-1-
-2-
using POSDemo.DB;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace POSDemo.Screens.salesBill
{
public partial class fsalesbill2 : Form
{
POSTutEntities db = new POSTutEntities();
public fsalesbill2()
{
InitializeComponent();
comboBox1.DataSource = db.Customers.Where(x => x.IsActive == true).ToList();
comboBox1.DisplayMember = "Name";
comboBox1.ValueMember = "id";
//comboBox2.DataSource = db.Products.ToList();
//List<Product> pp= db.Products.ToList();
//comboBox2.DataSource = new BindingSource(pp, null);
// comboBox2.DisplayMember = "Name";
// comboBox2.ValueMember = "Id";
// comboBox2.Text = "";
}
private void label2_Click(object sender, EventArgs e)
{
}
private void fsalesbill_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'pOSTutDataSet1.Product' table. You can move, or remove it, as needed.
this.productTableAdapter.Fill(this.pOSTutDataSet1.Product);
comboBox1.SelectedIndex = -1;
comboBox2.SelectedIndex = -1;
}
int i = 0;
Product pro;
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
i = int.Parse(comboBox2.SelectedValue.ToString());
pro = db.Products.SingleOrDefault(x => x.Id == i);
txtBarcode.Text = pro.Code.ToString();
txtPrice.Text = pro.Price.ToString();
txtQty.Text = pro.Qty.ToString();
}
catch
{
}
}
private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void button1_Click(object sender, EventArgs e)
{
//if (comboBox2.SelectedIndex <= -1) return;
//i = int.Parse(comboBox2.SelectedValue.ToString());
//pro = db.Products.SingleOrDefault(x => x.Id == i);
try
{
int subTotal;
int tt=0;
for (int i = 0; i < dataGridView1.RowCount; i++)
{
if (dataGridView1.Rows[i].Cells["Id"].Value.ToString()==pro.Id.ToString())
{
dataGridView1.Rows[i].Cells["Qty"].Value =int.Parse(dataGridView1.Rows[i].Cells["Qty"].Value.ToString() )+ int.Parse(textqty.Text);
tt = int.Parse(dataGridView1.Rows[i].Cells["total"].Value.ToString());
dataGridView1.Rows[i].Cells["total"].Value = int.Parse(dataGridView1.Rows[i].Cells["Qty"].Value.ToString()) * pro.Price;
subTotal = int.Parse(dataGridView1.Rows[i].Cells["total"].Value.ToString());
goto Total;
}
}
string id = pro.Id.ToString();
string item = comboBox2.Text;
int qty = Convert.ToInt32(textqty.Text);
int price = Convert.ToInt32(txtPrice.Text);
subTotal = qty * price;
Image image1 = pro.Image == null? new Bitmap(40, 40) :new Bitmap(pro.Image);
object[] row = { id,item, txtPrice.Text, textqty.Text, subTotal.ToString(),image1 };
dataGridView1.Rows.Add(row);
Total:
txttotal.Text = (Convert.ToInt32(txttotal.Text) + subTotal - tt).ToString();
txtNettotal.Text = (int.Parse(txttotal.Text) - int.Parse(textDis.Text))+"";
comboBox2.Focus();
// dataGridView1.Rows.Add(pro.Id, pro.Name, pro.Price, textqty.Text, int.Parse(textqty.Text) * pro.Price, pro.Image);
}
catch { }
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void comboBox2_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Enter)
{
textqty.Focus();
textqty.SelectAll();
}
}
private void textqty_TextChanged(object sender, EventArgs e)
{
}
private void textqty_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Enter)
{
button1.PerformClick();
comboBox2.Focus();
}
}
private void textDis_TextChanged(object sender, EventArgs e)
{
txtNettotal.Text = (int.Parse(txttotal.Text) - int.Parse(textDis.Text)) + "";
}
private void Save_Click(object sender, EventArgs e)
{
}
}
}
-3-
-4-