Ejemplo n.º 1
0
        private void btn_SaveMaterial_Click(object sender, EventArgs e)
        {
            try
            {
                string txtMatCode = tbMatCode.Text.Trim();
                string txtMatName = tbMatName.Text.Trim();
                string txtStaff   = tbStaff.Text.Trim();
                string txtMatID   = "0";
                if (string.IsNullOrEmpty(txtMatCode) || string.IsNullOrEmpty(txtMatName) || string.IsNullOrEmpty(txtStaff))
                {
                    MessageBox.Show("กรุณาป้อนข้อมูลให้ครบถ้วน!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    tbMatName.Focus();
                    return;
                }
                if (MatGroup.check_Has_MatCode(txtMatCode) && _MatAddEdit == 0)//check for insert
                {
                    MessageBox.Show("รหัส Mat นี้ซ้ำกับในระบบ! กรุณาตรวจสอบด้วย", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    tbMatCode.Focus();
                    tbStaff.Text = string.Empty;
                    return;
                }

                if (MatGroup.check_Has_MatName(txtMatName))
                {
                    MessageBox.Show("ชื่อนี้มีการป้อนไปแล้ว! กรุณาตรวจสอบด้วย", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    tbMatName.Focus();
                    tbStaff.Text = string.Empty;
                    return;
                }
                if (!frm1.CheckStaff(txtStaff))
                {
                    MessageBox.Show("ไม่พบรหัสพนักงาน!", "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    tbStaff.Text = string.Empty;
                    tbStaff.Focus();
                    return;
                }
                if (_MatAddEdit == 0)//insert
                {
                    MatGroup.Material_Save("INSERT", txtMatCode, txtMatName, txtStaff, txtMatID);
                }
                else//update
                {
                    txtMatID = lbl_ID.Text.Trim();
                    MatGroup.Material_Save("UPDATE", txtMatCode, txtMatName, txtStaff, txtMatID);
                }
                MessageBox.Show("บันทึกข้อมูลเรียบร้อย!", "Successful!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Clear_MaterialForm();
                btn_FindMaterial_Click(null, null);
                btnMas_Find_Click(null, null);//reload form master list
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 2
0
 private void btnMat_Del_Click(object sender, EventArgs e)
 {
     try
     {
         if (_MatAddEdit == 1)
         {
             string txtMatID = lbl_ID.Text.Trim();
             string txtStaff = tbStaff.Text.Trim();
             if (!frm1.CheckStaff(txtStaff))
             {
                 MessageBox.Show("ไม่พบรหัสพนักงาน!", "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 tbStaff.Text = string.Empty;
                 tbStaff.Focus();
                 return;
             }
             if (MatGroup.Check_Material_Ref(txtMatID))//check มีการผูกรหัส material ไปใช้ยัง
             {
                 MessageBox.Show("ไม่สามารถลบได้! \nเนื่องจากใช้ใน Master group แล้ว", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 tbStaff.Text = string.Empty;
                 tbStaff.Focus();
                 return;
             }
             if (MessageBox.Show("ต้องการลบใช่หรือไม่?", "Confirm!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
             {
                 MatGroup.Material_Save("DELETE", "", "", txtStaff, txtMatID);
                 MessageBox.Show("ลบข้อมูลเรียบร้อย!", "Successful!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 Clear_MaterialForm();
                 btn_FindMaterial_Click(null, null);
             }
         }
         else
         {
             MessageBox.Show("กรุณากด Double Click รายการด้านล่าง เพื่อทำการลบ!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }