using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using BiskLog_Point_Of_Sale.Delivery; using BiskLog_Point_Of_Sale.Multiple_Login; using BiskLog_Point_Of_Sale.Properties; namespace Point_Of_Sale_Managment { public partial class AddProductDelivery : Form { SqlConnection cn; SqlCommand command; DatabaseConn conn = new DatabaseConn(); SqlDataReader dr; string currency; public static string id, product_name, price, quantity, unitname, unitcode, distinctive; NewDelivery formSale; public AddProductDelivery(NewDelivery formsales) { InitializeComponent(); cn = new SqlConnection(conn.MyConnection()); formSale = formsales; currency = Settings.Default.currrencyCode + " "; } private void DataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex != -1) { id = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString(); product_name = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString(); price = (dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString()).Substring(Settings.Default.currrencyCode.Length); quantity = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString(); unitname = dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString(); unitcode = dataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString(); distinctive = dataGridView1.Rows[e.RowIndex].Cells[6].Value.ToString(); if (int.Parse(quantity) <= 0) { string title = "Out of stock"; string message = "Sorry, " + product_name + " is out of stock!!"; NoAction noAction = new NoAction(title,message); noAction.BringToFront(); noAction.ShowDialog(); } else { quantityDelivery quant = new quantityDelivery(this, int.Parse(quantity)); quant.BringToFront(); quant.ShowDialog(); } } } public void AddtoCart(int quantity, decimal pPrice) { formSale.loadProductManual(product_name, quantity, pPrice, id,unitname,unitcode,distinctive); dataGridView1.Rows.Clear(); proID.Text = ""; proNAME.Text = ""; } public void products(string key) { dataGridView1.Rows.Clear(); cn.Open(); command = new SqlCommand("Select tblProduct.pcode,tblProduct.product_name,tblInventory.quantity,tblProduct.price,u.unitname as unitname,tblProduct.baseUnit as unitCode " + "from tblProduct Inner Join tblInventory On tblInventory.pcode = tblProduct.pcode Inner Join UnitOfMeasure u On u.unitCode = tblProduct.baseUnit " + "where tblProduct.branchID = @branch and tblProduct.status = 'ACTIVE' and tblProduct.pcode like '%" + key + "%' or " + "tblProduct.branchID = @branch and tblProduct.status = 'ACTIVE' and tblProduct.product_name like '%" + key + "%' " + "SELECT PAU.pcode,tp.product_name,uni.unitname as unitname,[price/unit] as price,(ti.quantity / [quantity/unit]) as quantity,PAU.unitCode ,distinctiveCode " + "FROM ProductAltUnit PAU Inner Join UnitOfMeasure uni On uni.unitCode = PAU.unitCode Inner Join tblProduct tp On tp.pcode = PAU.pcode " + "Inner Join tblInventory ti On ti.pcode = PAU.pcode where tp.branchID = @branch and tp.status = 'ACTIVE' and PAU.pcode like '%" + key + "%' or " + "tp.branchID = @branch and tp.status = 'ACTIVE' and tp.product_name like '%" + key + "%'", cn); command.Parameters.AddWithValue("@branch", Settings.Default.BranchID); command.ExecuteNonQuery(); dr = command.ExecuteReader(); while (dr.Read()) { dataGridView1.Rows.Add(dr[0].ToString(), dr["product_name"].ToString(), currency + dr["price"].ToString(), dr["quantity"].ToString(), dr["unitname"].ToString(), dr["unitCode"].ToString(), dr[0].ToString()); } dr.NextResult(); while (dr.Read()) { dataGridView1.Rows.Add(dr[0].ToString(), dr["product_name"].ToString(), currency + dr["price"].ToString(), dr["quantity"].ToString(), dr["unitname"].ToString(), dr["unitCode"].ToString(), dr["distinctiveCode"].ToString()); } dr.Close(); cn.Close(); } private void Label2_Click(object sender, EventArgs e) { this.Close(); } private void Label2_MouseEnter(object sender, EventArgs e) { label2.BackColor = Color.Crimson; } private void Label2_MouseLeave(object sender, EventArgs e) { label2.BackColor = Color.FromArgb(20, 158, 37); } private void AddProducttoCart_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Escape) { this.Close(); } } private void ProID_TextChanged(object sender, EventArgs e) { if (String.IsNullOrEmpty(proID.Text)) { dataGridView1.Rows.Clear(); } else { products(proID.Text); } } private void ProNAME_TextChanged(object sender, EventArgs e) { if (String.IsNullOrEmpty(proNAME.Text)) { dataGridView1.Rows.Clear(); } else { products(proNAME.Text); } } } }