Ejemplo n.º 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if ((txtFinalQty.Text != "") && (txtSampleSize.Text != "") && (txtImpurities.Text != ""))
            {
                try
                {
                    if (objQCReport_DL.IsPRPDBatchAccept(objPRPDBatch.PRPDBatchID, (int)QCReport.ReportStatus.Accept))
                    {
                        if (txtComments.Text == "")
                        {
                            objPRPDBatch.PRPDBatchComments = "N/A";
                        }
                        else
                        {
                            objPRPDBatch.PRPDBatchComments = txtComments.Text;
                        }

                        if (objPRPDBatch.Type == PRPDBatch.PRPDType.PrimaryOutsource)
                        {
                            objPRPDBatch.OutSourceQty = Convert.ToDecimal(txtOutsourceQty.Text);
                        }
                        else
                        {
                            objPRPDBatch.OutSourceQty = 0;
                        }
                        objPRPDBatch.PRPDBatchEndDate         = dtpDateHandOver.Value;
                        objPRPDBatch.PRPDBatchFinalQty        = Convert.ToDecimal(txtFinalQty.Text);
                        objPRPDBatch.PRPDBatchEndBy           = CurrentUser.UserEmp;
                        objPRPDBatch.PRPDBatchTotalImpurities = Convert.ToDecimal(txtImpurities.Text);
                        objPRPDBatch.PRPDSampleSize           = txtSampleSize.Text;
                        objPRPDBatch.Status = PRPDBatch.PRPDBatchStatus.Finished;

                        MRMaterial    objMRMaterial    = new MRMaterial();
                        MRMaterial_DL objMRMaterial_DL = new MRMaterial_DL(ConnectionStringClass.GetConnection());

                        objMRMaterial = objMRMaterial_DL.Get(objPRPDBatch.MRIN, objPRPDBatch.PRPDBatchMaterial.MaterialCode);

                        if ((objPRPDBatch.PRPDBatchFinalQty > 0) && (objMRMaterial.IssuedQty >= objPRPDBatch.PRPDBatchFinalQty))
                        {
                            if (objPRPDBatch.Type == PRPDBatch.PRPDType.PrimaryOutsource)
                            {
                                if (objPRPDBatch.OutSourceQty > 0)
                                {
                                    Decimal sampleQty = Convert.ToDecimal(objPRPDBatch.PRPDSampleSize);

                                    objPRPDBatch_DL.Update_Finish(objPRPDBatch);

                                    //Update Batch Cost

                                    objPRPDBatch_DL.Update_BatchCost(objPRPDBatch.PRPDBatchID, CurrentUser.EmployeeID, (int)objPRPDBatch.Type);

                                    Load_Batches(objDepartment);

                                    MessageBox.Show(this, "Successfully Saved and the Batch File is sent for Costing Approval", "Save Records", MessageBoxButtons.OK, MessageBoxIcon.Information);

                                    if (cmbPRPDBatchID.Items.Count <= 0)
                                    {
                                        MessageBox.Show(this, "Approved Batch file list Empty", "No Approved Batch Files", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                        this.Close();
                                    }
                                    else
                                    {
                                        cmbPRPDBatchID_SelectedIndexChanged(sender, e);
                                        grpFinalizeDetails.Enabled = false;
                                    }
                                }
                                else
                                {
                                    MessageBox.Show(this, "Outsource Qty Need to be greater than Zero", "Invalid Qty", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                }
                            }
                            else
                            {
                                Decimal sampleQty = Convert.ToDecimal(objPRPDBatch.PRPDSampleSize);

                                objPRPDBatch_DL.Update_Finish(objPRPDBatch);

                                //Update Batch Cost

                                objPRPDBatch_DL.Update_BatchCost(objPRPDBatch.PRPDBatchID, CurrentUser.EmployeeID, (int)objPRPDBatch.Type);

                                Load_Batches(objDepartment);

                                MessageBox.Show(this, "Successfully Saved and the Batch File is sent for Costing Approval", "Save Records", MessageBoxButtons.OK, MessageBoxIcon.Information);

                                if (cmbPRPDBatchID.Items.Count <= 0)
                                {
                                    MessageBox.Show(this, "Approved Batch file list Empty", "No Approved Batch Files", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                    this.Close();
                                }
                                else
                                {
                                    cmbPRPDBatchID_SelectedIndexChanged(sender, e);
                                    grpFinalizeDetails.Enabled = false;
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show(this, "Invalid Final Quantity", "Invalid Value", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                    else
                    {
                        MessageBox.Show(this, "PRPD Batch Quality test incomplete", "Quality Test", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, "Error occured while finalizing", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            else
            {
                MessageBox.Show(this, "Please Fill All Fields", "Fill Records", MessageBoxButtons.OK);
            }
        }