private void DoubleClick(object sender, MouseButtonEventArgs e) { Buytoday go = new Buytoday(); object item = dataGrid.SelectedItem; sendCode = (dataGrid.SelectedCells[0].Column.GetCellContent(item) as TextBlock).Text; sendName = (dataGrid.SelectedCells[1].Column.GetCellContent(item) as TextBlock).Text; sendPricebuy = (dataGrid.SelectedCells[2].Column.GetCellContent(item) as TextBlock).Text; sendPricesell = (dataGrid.SelectedCells[3].Column.GetCellContent(item) as TextBlock).Text; sendUnit = (dataGrid.SelectedCells[4].Column.GetCellContent(item) as TextBlock).Text; this.Close(); }
private void DoubleClick(object sender, MouseButtonEventArgs e) { object item = dataGrid.SelectedItem; Buytoday go = new Buytoday(); sendID = (dataGrid.SelectedCells[0].Column.GetCellContent(item) as TextBlock).Text; sendName = (dataGrid.SelectedCells[1].Column.GetCellContent(item) as TextBlock).Text; sendLname = (dataGrid.SelectedCells[2].Column.GetCellContent(item) as TextBlock).Text; sendAddress = (dataGrid.SelectedCells[3].Column.GetCellContent(item) as TextBlock).Text; sendCard = (dataGrid.SelectedCells[4].Column.GetCellContent(item) as TextBlock).Text; sendPlate = (dataGrid.SelectedCells[5].Column.GetCellContent(item) as TextBlock).Text; sendTel = (dataGrid.SelectedCells[6].Column.GetCellContent(item) as TextBlock).Text; this.Close(); }
private void Buytoday_Click(object sender, RoutedEventArgs e) { Buytoday go = new Buytoday(); go.Show(); }
private void Insert2DB() { try { using (con) { using (MySqlCommand cmd = new MySqlCommand()) { cmd.Connection = con; for (int i = 0; i < dataGrid.Items.Count; i++) { count += 1; object item = dataGrid.Items[i]; string showidProduct = (dataGrid.SelectedCells[0].Column.GetCellContent(item) as TextBlock).Text; string shownameProduct = (dataGrid.SelectedCells[1].Column.GetCellContent(item) as TextBlock).Text; string showtotalProduct = (dataGrid.SelectedCells[2].Column.GetCellContent(item) as TextBlock).Text; string showdeleteProduct = (dataGrid.SelectedCells[3].Column.GetCellContent(item) as TextBlock).Text; string showallTotal = (dataGrid.SelectedCells[4].Column.GetCellContent(item) as TextBlock).Text; string showPrice = (dataGrid.SelectedCells[5].Column.GetCellContent(item) as TextBlock).Text; string showType = (dataGrid.SelectedCells[6].Column.GetCellContent(item) as TextBlock).Text; string showPriceall = (dataGrid.SelectedCells[7].Column.GetCellContent(item) as TextBlock).Text; string showNote = (dataGrid.SelectedCells[8].Column.GetCellContent(item) as TextBlock).Text; con.Open(); string sqlproID = "SELECT proID FROM product WHERE proCode='" + showidProduct + "'"; MySqlCommand cmdproID = new MySqlCommand(sqlproID, con); MySqlDataReader readproID = cmdproID.ExecuteReader(); while (readproID.Read()) { getproID = readproID["proID"].ToString(); } con.Close(); con.Open(); string getValue = "SELECT stockTotal FROM stock WHERE proID='" + getproID + "'"; MySqlCommand getCommand = new MySqlCommand(getValue, con); MySqlDataReader getReader = getCommand.ExecuteReader(); getTotal = Double.Parse(showallTotal); while (getReader.Read()) { getTotal += Convert.ToDouble(getReader["stockTotal"]); } con.Close(); con.Open(); MySqlCommand cmdgettype = new MySqlCommand("SELECT typepID FROM typeproduct WHERE typepName='" + showType + "'", con); MySqlDataReader readtype = cmdgettype.ExecuteReader(); while (readtype.Read()) { gettypeID = readtype.GetString(readtype.GetOrdinal("typepID")); } con.Close(); if (count >= 1) { con.Open(); cmd.CommandText = @"INSERT INTO buytoday(docID,buyDate,cusID,cusName,cusLastname,cusPlate,buyCode,buyName,buyTotal,buyDtotal,buyTotalall,buyPrice,typepID,buyAllprice,buyInfo) VALUES (@Bill,@DATE,@idCus,@nameCus,@lnameCus,@plateCus,@buyCode,@buyName,@buyTotal,@buyDtotal,@buyTotalall,@buyPrice,@buyType,@buyAllprice,@buyInfo); UPDATE stock SET stockTotal='" + getTotal + "' WHERE proID='" + getproID + "'"; cmd.Parameters.AddWithValue("@Bill", ShowBill.Text); cmd.Parameters.AddWithValue("@DATE", Convert.ToDateTime(txtDate.Text).ToString("yyyy/MM/dd")); cmd.Parameters.AddWithValue("@nameCus", txtName.Text); cmd.Parameters.AddWithValue("@lnameCus", txtLname.Text); cmd.Parameters.AddWithValue("@plateCus", txtPlate.Text); cmd.Parameters.AddWithValue("@buyCode", showidProduct); cmd.Parameters.AddWithValue("@buyName", shownameProduct); cmd.Parameters.AddWithValue("@buyTotal", showtotalProduct); cmd.Parameters.AddWithValue("@buyDtotal", showdeleteProduct); cmd.Parameters.AddWithValue("@buyTotalall", showallTotal); cmd.Parameters.AddWithValue("@buyPrice", showPrice); cmd.Parameters.AddWithValue("@buyType", gettypeID); cmd.Parameters.AddWithValue("@buyAllprice", showPriceall); cmd.Parameters.AddWithValue("@buyInfo", showNote); if (calcusID == 1) { cmd.Parameters.AddWithValue("@idCus", txtID.Text); } else if (calcusID == 2) { cmd.Parameters.AddWithValue("@idCus", varcusID); } cmd.ExecuteNonQuery(); cmd.Parameters.Clear(); con.Close(); } else { con.Open(); cmd.CommandText = @"INSERT INTO buytoday(docID,buyDate,cusID,cusName,cusLastname,cusPlate,buyCode,buyName,buyTotal,buyDtotal,buyTotalall,buyPrice,typepID,buyAllprice,buyInfo) VALUES (@Bill,@DATE,@idCus,@nameCus,@lnameCus,@plateCus,@buyCode,@buyName,@buyTotal,@buyDtotal,@buyTotalall,@buyPrice,@buyType,@buyAllprice,@buyInfo); INSERT INTO receiptbuy(receiptDate,receiptCode,cusID,cusName,cusLastname,cusPlate,receiptInfo,receiptPriceall) VALUES(@DATE,@Bill,@idCus,@nameCus,@lnameCus,@plateCus,@buyInfo,@recPriceall); UPDATE stock SET stockTotal='" + getTotal + "' WHERE proID='" + getproID + "';"; cmd.Parameters.AddWithValue("@Bill", ShowBill.Text); cmd.Parameters.AddWithValue("@DATE", Convert.ToDateTime(txtDate.Text).ToString("yyyy/MM/dd")); cmd.Parameters.AddWithValue("@nameCus", txtName.Text); cmd.Parameters.AddWithValue("@lnameCus", txtLname.Text); cmd.Parameters.AddWithValue("@plateCus", txtPlate.Text); cmd.Parameters.AddWithValue("@buyCode", showidProduct); cmd.Parameters.AddWithValue("@buyName", shownameProduct); cmd.Parameters.AddWithValue("@buyTotal", showtotalProduct); cmd.Parameters.AddWithValue("@buyDtotal", showdeleteProduct); cmd.Parameters.AddWithValue("@buyTotalall", showallTotal); cmd.Parameters.AddWithValue("@buyPrice", showPrice); cmd.Parameters.AddWithValue("@buyType", gettypeID); cmd.Parameters.AddWithValue("@buyAllprice", showPriceall); cmd.Parameters.AddWithValue("@recPriceall", TotalLast.Text); cmd.Parameters.AddWithValue("@buyInfo", showNote); if (calcusID == 1) { cmd.Parameters.AddWithValue("@idCus", txtID.Text); }else if (calcusID == 2) { cmd.Parameters.AddWithValue("@idCus", varcusID); } cmd.ExecuteNonQuery(); cmd.Parameters.Clear(); con.Close(); } }// ปิด LOOP } // ปิด Using } } catch (Exception ex) { System.Windows.MessageBox.Show(ex.Message); } System.Windows.MessageBox.Show("บันทึกเรียบร้อยแล้ว"); Buytoday go = new Buytoday(); this.Close(); go.Show(); }