public static Boolean SALE(clsSale s) { try { StringBuilder sb = new StringBuilder(); sb.Remove(0, sb.ToString().Length); sb.Append(" DELETE "); sb.Append(" FROM DETAIL_SALE "); sb.Append(" WHERE Sale_ID = '" + s.Sale_ID + "'"); sb.Append(" AND Product_ID = '" + s.Product_ID + "'"); clsGlobal.SQLQUERY.MS_ExecuteNonQuery(sb.ToString()); return true; } catch (Exception ex) { return false; throw ex; } }
private void btnAdd_Click(object sender, EventArgs e) { DataTable dt = clsSELECT.sale(this.lbID.Text.Trim(), this.txtPID.Text.Trim()).Tables[0]; if (dt.Rows.Count < 0) { string ProductID = dt.Rows[0]["Product_ID"].ToString(); } if (txtPID.Text.Trim() == "") { MessageBox.Show("กรุณาระบุรหัสสินค้า!", "การดำเนินการ", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } else if (txtTotal.Text.Trim() == "") { MessageBox.Show("กรุณาระบุจำนวนสินค้า!", "การดำเนินการ", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } else if (Convert.ToDecimal(txtTotal.Text) > Convert.ToDecimal(txtStock.Text)) { MessageBox.Show("จำนวนสินค้าในสต๊อกมีไม่เพียงพอ!", "การดำเนินการ", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } else { try { var Sale = new clsSale(); Sale.Sale_ID = this.lbID.Text.Trim(); Sale.Product_ID = this.txtPID.Text.Trim(); Sale.Total = this.txtTotal.Text.Trim(); if (dt.Rows.Count == 0) { if (clsINSERT.SALE(Sale) == true) { StringBuilder sbUPSTOCK = new StringBuilder(); sbUPSTOCK.Append("update dbo.PRODUCT set Total = "); sbUPSTOCK.Append("Total - '" + txtTotal.Text.Trim() + "'"); sbUPSTOCK.Append(" where Product_ID = '" + txtPID.Text.Trim() + "'"); clsGlobal.SQLQUERY.MS_ExecuteNonQuery(sbUPSTOCK.ToString()); } else { MessageBox.Show("ข้อมูลไม่ถูกต้อง", "Message", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { StringBuilder sbUP = new StringBuilder(); sbUP.Append("update DETAIL_SALE set Total = "); sbUP.Append("Total + " + txtTotal.Text.Trim()); sbUP.Append(" where Sale_ID = '" + lbID.Text.Trim() + "'"); sbUP.Append(" and Product_ID = '" + txtPID.Text.Trim() + "'"); clsGlobal.SQLQUERY.MS_ExecuteNonQuery(sbUP.ToString()); //อัพเดดสต๊อก StringBuilder sbUPSTOCK = new StringBuilder(); sbUPSTOCK.Append("update dbo.PRODUCT set Total = "); sbUPSTOCK.Append("Total - '" + txtTotal.Text.Trim() + "'"); sbUPSTOCK.Append(" where Product_ID = '" + txtPID.Text.Trim() + "'"); clsGlobal.SQLQUERY.MS_ExecuteNonQuery(sbUPSTOCK.ToString()); } } catch (Exception) { MessageBox.Show("เกิดข้อผิดพลาด!", "การดำเนินการ", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } try //คิดเงินรวม { double total = 0; foreach (DataGridViewRow row in dgvView.Rows) { total += Convert.ToDouble(row.Cells["Pricesale"].Value.ToString()) * Convert.ToDouble(row.Cells["Total"].Value.ToString()); } txtSum.Text = total.ToString("##,###.00"); } catch { } btnSearch_Click( sender, e); }
public static Boolean SALE(clsSale S) { try { StringBuilder sb = new StringBuilder(); sb.Remove(0, sb.ToString().Length); sb.Append(" INSERT INTO DETAIL_SALE "); sb.Append(" ( Sale_ID "); sb.Append(" ,Product_ID"); sb.Append(" ,Total ) "); sb.Append(" VALUES "); sb.Append(" ('" + S.Sale_ID + "' "); sb.Append(" ,'" + S.Product_ID + "' "); sb.Append(" ,'" + S.Total + "') "); clsGlobal.SQLQUERY.MS_ExecuteNonQuery(sb.ToString()); return true; } catch (Exception ex) { return false; throw ex; } }
private void button4_Click(object sender, EventArgs e) { var Sale = new clsSale (); Sale.Sale_ID = dgvView.Rows[dgvView.CurrentRow.Index].Cells["Sale_ID"].Value.ToString().Trim(); Sale.Product_ID = dgvView.Rows[dgvView.CurrentRow.Index].Cells["Product_ID"].Value.ToString().Trim(); Sale.Pricesale = dgvView.Rows[dgvView.CurrentRow.Index].Cells["Pricesale"].Value.ToString().Trim(); Sale.Total = dgvView.Rows[dgvView.CurrentRow.Index].Cells["Total"].Value.ToString().Trim(); if (MessageBox.Show("ต้องการลบข้อมูลใช่หรือไม่", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { if (clsDELETE.SALE(Sale) == true) { StringBuilder sbUPSTOCK = new StringBuilder(); sbUPSTOCK.Append("update dbo.PRODUCT set Total = "); sbUPSTOCK.Append("Total + '" + Sale.Total+"'"); sbUPSTOCK.Append(" where Product_ID = '" + Sale.Product_ID + "'"); clsGlobal.SQLQUERY.MS_ExecuteNonQuery(sbUPSTOCK.ToString()); MessageBox.Show("ลบข้อมูลสำเร็จ", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("ลบข้อมูลไม่สำเร็จ", "Message", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); } } btnSearch_Click( sender, e); }