Exemplo n.º 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            PRPDBatch objPRPDBatch = new PRPDBatch();

            DialogResult dr = MessageBox.Show(this, "Are you sure you want to Create a PRPD Batch?\n\nThis will Create a new PRPD Batch and send to approval\nClick Yes to Create", "Confirmation ", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);

            if (dr == DialogResult.Yes)
            {
                if (cmbMaterial.SelectedValue == null)
                {
                    MessageBox.Show(this, "Please select a material", "Empty Fields", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (txtNewBatchQuantity.Text.Equals(""))
                {
                    MessageBox.Show(this, "Please enter a Quantity", "Empty Fields", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (Convert.ToDecimal(txtNewBatchQuantity.Text) <= 0)
                {
                    MessageBox.Show(this, "Please enter a valid Quantity", "Invalid Data", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    try
                    {
                        objPRPDBatch.PRPDBatchInstructedBy   = CurrentUser.UserEmp;
                        objPRPDBatch.PRPDBatchInstructedDate = DateTime.Today;
                        objPRPDBatch.PRPDBatchMaterial       = objMaterial_DL.Get(cmbMaterial.SelectedValue.ToString());
                        objPRPDBatch.PRPDBatchQty            = Convert.ToDecimal(txtNewBatchQuantity.Text);
                        objPRPDBatch.MRIN   = 0;
                        objPRPDBatch.Status = PRPDBatch.PRPDBatchStatus.Created;
                        if (rdbPP.Checked == true)
                        {
                            objPRPDBatch.Type = PRPDBatch.PRPDType.PrimaryPreperation;
                        }
                        else if (rdbPPOutsource.Checked == true)
                        {
                            objPRPDBatch.Type = PRPDBatch.PRPDType.PrimaryOutsource;
                        }
                        else
                        {
                            objPRPDBatch.Type = PRPDBatch.PRPDType.Rework;
                        }
                        objPRPDBatch.PRPDBatchComments = "N/A";

                        String PRPDID = objPRPDBatch_DL.AddPP(objPRPDBatch);


                        if (PRPDID != null)
                        {
                            objPRPDBatch.PRPDBatchID = PRPDID;
                            foreach (PRPDBatchActivityInstructions _obj in objPRPDBatchActivityInstructionsCollec)
                            {
                                _obj.PRPDBatch = objPRPDBatch;

                                objPRPDBatchActivityInstructions_DL.Add(_obj);
                            }

                            //long res = GenerateMR(objPRPDBatch);
                            //int x = 0;
                            //if (res > 0)
                            //{
                            //    objPRPDBatch.MRIN = res;
                            //    x = objPRPDBatch_DL.UpdateMR(objPRPDBatch.PRPDBatchID, res);

                            //}
                            //if (x > 0)
                            //{
                            MessageBox.Show(this, "Successfully Created a PRPD Batch \n\nPRPD Batch ID :- " + PRPDID, "Successfull Created", MessageBoxButtons.OK, MessageBoxIcon.Information);

                            frmPRPDBatchCreatePreperation objFrm = new frmPRPDBatchCreatePreperation(CurrentUser);
                            objFrm.MdiParent = this.MdiParent;

                            this.Close();
                            objFrm.Show();



                            //}
                            //else
                            //{
                            //    objPRPDBatch_DL.Delete(PRPDID);
                            //    MessageBox.Show(this, "Error occuerd while saving, PRPD batch does not save", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            //}
                        }
                        else
                        {
                            MessageBox.Show(this, "Error occuerd while saving, PRPD batch does not save", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(this, "Error occuerd while saving,Please check the enterd data", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }