private void saleProducts() { try { SQLCON.openConn(); SQLCON.cmd = new MySqlCommand("Insert Into tblsaledetail (invoiceNo,itemCode,itemName,unitePrice,quantity,price)" + " Values (@invoiceNo,@item,@itemName,@unitePrice,@quantity,@price)", SQLCON.cnn); var p = SQLCON.cmd; p.Parameters.AddWithValue("@invoiceNo", txtInvoiceNo.Text); p.Parameters.AddWithValue("@item", txtProducCode.Text); p.Parameters.AddWithValue("@itemName", txtItemName.Text); p.Parameters.AddWithValue(@"unitePrice", Convert.ToDouble(txtItemPrice.Text)); p.Parameters.AddWithValue("@quantity", txtQuantity.Text); p.Parameters.AddWithValue("@price", Convert.ToDouble(txtItemPrice.Text) * Convert.ToDouble(txtQuantity.Text)); p.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { SQLCON.cnn.Close(); loadSaleitem(); } SQLCON.cnn.Close(); }
private void txtProducCode_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { // add invoice try { DataTable dt = new DataTable(); SQLCON.openConn(); //SQLCON.cnn.Open(); SQLCON.cmd = new MySqlCommand("Select * from tblproduct where itemCode = @item", SQLCON.cnn); SQLCON.cmd.Parameters.AddWithValue("@item", txtProducCode.Text); SQLCON.da = new MySqlDataAdapter(SQLCON.cmd); SQLCON.da.Fill(dt); if (dt.Rows.Count > 0) { txtItemName.Text = Convert.ToString(dt.Rows[0]["itemName"]); txtItemCategory.Text = Convert.ToString(dt.Rows[0]["itemCategory"]); txtItemPrice.Text = Convert.ToString(dt.Rows[0]["itemPriceOut"]); txtQuantity.Focus(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } SQLCON.cnn.Close(); } }
private void btnDelete_Click(object sender, EventArgs e) { try { SQLCON.openConn(); DialogResult result = MessageBox.Show("Do you want to Delete Product?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.Yes) { SQLCON.sql = "Delete From tblproduct Where itemCode = @id"; SQLCON.cmd = new MySqlCommand(SQLCON.sql, SQLCON.cnn); SQLCON.cmd.Parameters.AddWithValue("@id", SQLCON.id); int i = SQLCON.cmd.ExecuteNonQuery(); if (i > 0) { MessageBox.Show("Product Delete Success!"); showProduct(); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } SQLCON.cnn.Close(); }
private void button2_Click(object sender, EventArgs e) { try { SQLCON.openConn(); int d; for (d = 0; d <= 900; d++) { SQLCON.cmd = new MySqlCommand("Insert Into tblproduct (itemCode) Values(@d)", SQLCON.cnn); SQLCON.cmd.Parameters.AddWithValue("@d", d); SQLCON.cmd.ExecuteNonQuery(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void metroButton1_Click(object sender, EventArgs e) { try { SQLCON.openConn(); //SQLCON.cnn.Open(); MySqlCommand cmd = new MySqlCommand("Select * from tbluser Where userName=@user And pwd=@pwd", SQLCON.cnn); cmd.Parameters.AddWithValue("@user", txtUser.Text); cmd.Parameters.AddWithValue("@pwd", txtPwd.Text); MySqlDataAdapter da = new MySqlDataAdapter(cmd); DataTable dtlogin = new DataTable(); da.Fill(dtlogin); SQLCON.cnn.Close(); if (dtlogin.Rows.Count > 0) { //this.Hide(); dash frmMain = new dash(); // login ln = new login(); this.Hide(); frmMain.Show(); //ln.Close(); } else { MessageBox.Show("Invalid"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { SQLCON.cnn.Close(); } }
private void saveInvoice_Print() { try { SQLCON.openConn(); if (txtRecieveDollar.Text != "" && txtRecieveDollar.Text == "") { MessageBox.Show("Can't Sale Products when not Recieve money yet !", "Recieve Money Requied"); return; } //when cash reciev is Dollar if (txtRecieveDollar.Text != "" && txtRecieveReil.Text == "") { SQLCON.cmd = new MySqlCommand("Insert Into tbl_invoice(invoiceNo,saleBy,saleDate,totalDollar,totalRiel,cash_D_R_all,cashRecieveDollar,cashReturnDollar,cashReturnRiel)" + " Values (@invoiceNo,'Sopheak',sysdate(),ROUND(@totalDollar,2),ROUND(@totalRiel,2),@cash_D_R_all,@cashRecieveDollar,@cashReturnDollar,@cashReturnRiel)", SQLCON.cnn); SQLCON.cmd.Parameters.AddWithValue("@invoiceNo", txtInvoiceNo.Text); SQLCON.cmd.Parameters.AddWithValue("@totalDollar", txtGrandTotalDollar.Text); SQLCON.cmd.Parameters.AddWithValue("@totalRiel", txtGrandTotalRiel.Text); SQLCON.cmd.Parameters.AddWithValue("@cash_D_R_all", 0); SQLCON.cmd.Parameters.AddWithValue("@cashRecieveDollar", txtRecieveDollar.Text); SQLCON.cmd.Parameters.AddWithValue("@cashReturnDollar", txtCashReturnDollar.Text); SQLCON.cmd.Parameters.AddWithValue("@cashReturnRiel", txtCashReturnRiel.Text); //SQLCON.cmd.Parameters.AddWithValue("@cash", txt.Text); } else if (txtRecieveReil.Text != "" && txtRecieveDollar.Text == "") { // When cash reciev is Riel SQLCON.cmd = new MySqlCommand("Insert Into tbl_invoice (invoiceNo,saleBy,saleDate,totalDollar,totalRiel,cash_D_R_all,cashRecieveRiel,cashReturnRiel)" + " Values (@invoiceNo,'Sopheak', sysdate(),@totalRiel,@cashRecieveRiel,@cash_D_R_all)", SQLCON.cnn); SQLCON.cmd.Parameters.AddWithValue("@totalDollar", txtGrandTotalDollar.Text); SQLCON.cmd.Parameters.AddWithValue("@totalRiel", txtGrandTotalRiel.Text); SQLCON.cmd.Parameters.AddWithValue("@cashRecieveRiel", txtRecieveReil.Text); SQLCON.cmd.Parameters.AddWithValue("@cash_D_R_all", 1); } //SQLCON.cmd = new MySqlCommand("Insert Into tbl_invoice (invoiceNo,saleBy,saleDate,totalDollar,totalRiel,cash_D_R_all,cashRecieveDollar,cashRecieveRiel,cashReturnDollar,isPay)" + // " Values (@invoiceNo,'Sopheak', sysdate(),@totalDollar,@cashRecieveDollar,@cash_D_R_all)", SQLCON.cnn); //SQLCON.cmd.Parameters.AddWithValue("@invoiceNo", txtInvoiceNo.Text); //SQLCON.cmd.ExecuteNonQuery(); int p = SQLCON.cmd.ExecuteNonQuery(); if (p > 0) { SQLCON.cmd = new MySqlCommand("Select * from v_invoice where invoiceNo=@invoiceNoPrintINvoice", SQLCON.cnn); SQLCON.cmd.Parameters.AddWithValue("@invoiceNoPrintINvoice", txtInvoiceNo.Text); SQLCON.da = new MySqlDataAdapter(SQLCON.cmd); //DataTable dt = new DataTable(); SQLCON.dsa.Clear(); SQLCON.da.Fill(SQLCON.dsa, "rptInvoice"); // rpt is the name of ttx File SQLCON.reportName = "cryInvoice"; // report name frmReportCrystal frmprint = new frmReportCrystal(); frmprint.ShowDialog(); btnNewSale.PerformClick(); foreach (Control t in pProductCash.Controls) { if (t is TextBox) { t.Text = ""; } } } // SQLCON.cnn.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } }