private void btnNext6_Click(object sender, EventArgs e) { string lvUnit = GsysSQL.fncFindItemUnit(txtID.Text); lbDate.Text = txtDate.DateTime.ToString("dd/MM/yyyy"); lbItem.Text = GsysSQL.fncFindItemName(txtID.Text); lbAmount.Text = txtAmount.Text + " " + lvUnit; lbUserResive.Text = GsysSQL.fncFindFullEmpName(txtUserResive.Text); if (pvMode != "IN") { lbUserPay.Text = GsysSQL.fncFindFullEmpName(txtUserPay.Text); } else { lbUserPay.Text = " - "; } if (txtID.Text == "00021" || txtID.Text == "00022" || txtID.Text == "00023") { tabControl1.SelectedIndex = 7; } else { tabControl1.SelectedIndex = 6; } }
private void btnSave_Click(object sender, EventArgs e) { if (pvMode == "IN") { #region รับเข้า //เช็คข้อมูล if (txtDate.EditValue == "") { MessageBox.Show("กรุณาระบุ วันที่", "แจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Information); txtDate.Focus(); return; } else if (txtID.Text == "") { MessageBox.Show("กรุณาระบุ รหัส", "แจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Information); txtID.Focus(); return; } else if (Gstr.fncToInt(txtAmount.Text) <= 0) { MessageBox.Show("กรุณาระบุ จำนวน", "แจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Information); txtAmount.Focus(); return; } else if (txtUserResive.Text == "") { MessageBox.Show("กรุณาระบุ ผู้รับ", "แจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Information); txtUserResive.Focus(); return; } string lvType = "R"; string lvDate = Gstr.fncChangeTDate(txtDate.EditValue.ToString()); string lvItemID = Gstr.fncGetDataCode(txtID.Text, ";"); string lvAmount = txtAmount.Text; string lvBal = GsysSQL.fncFindBal(lvItemID); string lvUserResive = txtUserResive.Text; string lvUserPay = ""; string lvRemark = txtRemark.Text; string lvSQL = ""; string lvResault = ""; int lvTotalBal = Gstr.fncToInt(lvBal) + Gstr.fncToInt(lvAmount); if (lvTotalBal < 0) { lvTotalBal = 0; } //Update ยอด lvSQL = "Update SysITEM_Stock set Item_Amount = '" + lvTotalBal + "' Where Item_ID = '" + lvItemID + "' "; lvResault = GsysSQL.fncExecuteQueryData(lvSQL); //Insert เคลื่อนไหว lvSQL = "Insert into Inv_Moving (M_Type, M_Date, M_ItemID, M_AmountR, M_AmountP, M_AmountBal, M_UserResive, M_UserPay, M_Remark) "; lvSQL += "values('" + lvType + "', '" + lvDate + "', '" + lvItemID + "', '" + lvAmount + "', '', '" + lvTotalBal + "', '" + lvUserResive + "', '" + lvUserPay + "', '" + lvRemark + "')"; lvResault = GsysSQL.fncExecuteQueryData(lvSQL); if (lvResault == "Success") { GVar.gvSave = true; MessageBox.Show("บันทึกข้อมูลเรียบร้อย", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } #endregion } else if (pvMode == "Borrow") { #region ยืมของ //เช็คข้อมูล if (txtDate.EditValue == "") { MessageBox.Show("กรุณาระบุ วันที่", "แจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Information); txtDate.Focus(); return; } else if (txtID.Text == "") { MessageBox.Show("กรุณาระบุ รหัส", "แจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Information); txtID.Focus(); return; } else if (Gstr.fncToInt(txtAmount.Text) <= 0) { MessageBox.Show("กรุณาระบุ จำนวน", "แจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Information); txtAmount.Focus(); return; } else if (txtUserResive.Text == "") { MessageBox.Show("กรุณาระบุ ผู้ขอเบิก", "แจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Information); txtUserResive.Focus(); return; } else if (txtUserPay.Text == "") { MessageBox.Show("กรุณาระบุ ผู้จ่าย", "แจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Information); txtUserResive.Focus(); return; } string lvType = "B"; string lvDate = Gstr.fncChangeTDate(txtDate.EditValue.ToString()); string lvItemID = Gstr.fncGetDataCode(txtID.Text, ";"); string lvAmount = txtAmount.Text; string lvBal = GsysSQL.fncFindBal(lvItemID); string lvUserResive = Gstr.fncGetDataCode(txtUserResive.Text, ";"); string lvUserPay = Gstr.fncGetDataCode(txtUserPay.Text, ";"); string lvRemark = txtRemark.Text; string lvSQL = ""; string lvResault = ""; int lvTotalBal = Gstr.fncToInt(lvBal) - Gstr.fncToInt(lvAmount); int lvMinStock = Gstr.fncToInt(GsysSQL.fncFindMinStock(lvItemID)); string lvOption = ""; if (ChkMouse.Checked) { lvOption += "Mouse "; } if (ChkMousePad.Checked) { lvOption += "MousePad "; } if (ChkAdapter.Checked) { lvOption += "Adapter "; } if (ChkPointer.Checked) { lvOption += "Pointer "; } if (ChkFlashDrive.Checked) { lvOption += "FlashDrive "; } lvOption = lvOption.Replace(' ', ','); ////ห้ามจ่ายติดลบ //if (lvTotalBal < 0) //{ // MessageBox.Show("จำนวนคงเหลือไม่เพียงพอ", "แจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Information); // txtAmount.Focus(); // return; //} //if (lvTotalBal < 0) lvTotalBal = 0; ////Update ยอด //lvSQL = "Update SysITEM_Stock set Item_Amount = '" + lvTotalBal + "' Where Item_ID = '" + lvItemID + "' "; //lvResault = GsysSQL.fncExecuteQueryData(lvSQL); //Insert เคลื่อนไหว lvSQL = "Insert into Inv_Moving (M_Type, M_Date, M_ItemID, M_AmountR, M_AmountP, M_AmountBal, M_UserResive, M_UserPay, M_Remark, M_Option) "; lvSQL += "values('" + lvType + "', '" + lvDate + "', '" + lvItemID + "', '', '" + lvAmount + "', '" + lvTotalBal + "', '" + lvUserResive + "', '" + lvUserPay + "', '" + lvRemark + "', '" + lvOption + "')"; lvResault = GsysSQL.fncExecuteQueryData(lvSQL); if (lvResault == "Success") { GVar.gvSave = true; string lvUserName = GsysSQL.fncFindFullEmpName(lvUserResive); string lvItemName = GsysSQL.fncFindItemName(lvItemID); string lvItemUnit = GsysSQL.fncFindItemUnit(lvItemID); if (lvItemName == "อื่นๆ") { lvItemName = lvRemark; } string lvMessage = "แจ้งเตือน " + lvUserName + " ได้ยืม " + lvItemName + " จำนวน " + lvAmount + " " + lvItemUnit + " " + lvRemark; lineNotify(lvMessage); MessageBox.Show("บันทึกข้อมูลเรียบร้อย", "แจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } #endregion } else { #region เบิกจ่าย //เช็คข้อมูล if (txtDate.EditValue == "") { MessageBox.Show("กรุณาระบุ วันที่", "แจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Information); txtDate.Focus(); return; } else if (txtID.Text == "") { MessageBox.Show("กรุณาระบุ รหัส", "แจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Information); txtID.Focus(); return; } else if (Gstr.fncToInt(txtAmount.Text) <= 0) { MessageBox.Show("กรุณาระบุ จำนวน", "แจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Information); txtAmount.Focus(); return; } else if (txtUserResive.Text == "") { MessageBox.Show("กรุณาระบุ ผู้ขอเบิก", "แจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Information); txtUserResive.Focus(); return; } else if (txtUserPay.Text == "") { MessageBox.Show("กรุณาระบุ ผู้จ่าย", "แจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Information); txtUserResive.Focus(); return; } string lvType = "P"; string lvDate = Gstr.fncChangeTDate(txtDate.EditValue.ToString()); string lvItemID = Gstr.fncGetDataCode(txtID.Text, ";"); string lvAmount = txtAmount.Text; string lvBal = GsysSQL.fncFindBal(lvItemID); string lvUserResive = Gstr.fncGetDataCode(txtUserResive.Text, ";"); string lvUserPay = Gstr.fncGetDataCode(txtUserPay.Text, ";"); string lvRemark = txtRemark.Text; string lvSQL = ""; string lvResault = ""; int lvTotalBal = Gstr.fncToInt(lvBal) - Gstr.fncToInt(lvAmount); int lvMinStock = Gstr.fncToInt(GsysSQL.fncFindMinStock(lvItemID)); //ห้ามจ่ายติดลบ if (lvTotalBal < 0) { MessageBox.Show("จำนวนคงเหลือไม่เพียงพอ", "แจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Information); txtAmount.Focus(); return; } if (lvTotalBal < 0) { lvTotalBal = 0; } //Update ยอด lvSQL = "Update SysITEM_Stock set Item_Amount = '" + lvTotalBal + "' Where Item_ID = '" + lvItemID + "' "; lvResault = GsysSQL.fncExecuteQueryData(lvSQL); //Insert เคลื่อนไหว lvSQL = "Insert into Inv_Moving (M_Type, M_Date, M_ItemID, M_AmountR, M_AmountP, M_AmountBal, M_UserResive, M_UserPay, M_Remark) "; lvSQL += "values('" + lvType + "', '" + lvDate + "', '" + lvItemID + "', '', '" + lvAmount + "', '" + lvTotalBal + "', '" + lvUserResive + "', '" + lvUserPay + "', '" + lvRemark + "')"; lvResault = GsysSQL.fncExecuteQueryData(lvSQL); if (lvResault == "Success") { if (lvTotalBal <= lvMinStock && lvMinStock != 0) { string lvMessage = "แจ้งเตือน " + txtName.Text + " ใกล้หมดแล้ว ยอดคงเหลือปัจุบัน คือ " + lvTotalBal; lineNotify(lvMessage); } else { string lvEmpName = GsysSQL.fncFindFullEmpName(lvUserResive); string lvItemName = GsysSQL.fncFindItemName(lvItemID); string lvItemUnit = GsysSQL.fncFindItemUnit(lvItemID); string lvMessage = "แจ้งเตือน " + lvEmpName + " ได้เบิก " + lvItemName + " จำนวน " + lvAmount + " " + lvItemUnit; lineNotify(lvMessage); } MessageBox.Show("บันทึกข้อมูลเรียบร้อย", "แจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } #endregion } }