예제 #1
0
        protected void btnSaveSampleResult_Click(object sender, EventArgs e)
        {
            Messages.ClearMessage();

            //int no = 0;
            //if (((int)SamplingBussiness.SamplingStatus.DriverNotFound) != int.Parse(rbSampleStatus.SelectedValue) &&
            //    txtArrivalNoOfBags.Text.Trim() != string.Empty &&
            //    int.TryParse(txtArrivalNoOfBags.Text, out no) &&
            //    no < int.Parse(txtNumberOfBags.Text))
            //{
            //    Messages.SetMessage("Bag count greater than the bag count " + no + " registered on Voucher!", WarehouseApplication.Messages.MessageType.Error);
            //    return;
            //}
            if (ViewState["SelectedSMID"] == null)
            {
                Messages.SetMessage("The sample ticket dosen't exits. Please try reloading again!", WarehouseApplication.Messages.MessageType.Error);
                return;
            }
            //SamplingModel sm = (SamplingModel)ViewState["SelectedSMID"];
            SamplingModel sm = SamplingModel.GetSampleById(new Guid(ViewState["SelectedSMID"].ToString()));

            if (sm == null)
            {
                Messages.SetMessage("The sample ticket dosen't exits. Please try reloading again!", WarehouseApplication.Messages.MessageType.Error);
                return;
            }
            sm.ResultReceivedDateTime = DateTime.Parse(txtResultReceivedDate.Text + " " + txtResultReceivedTime.Text);
            sm.SamplingStatusID       = int.Parse(rbSampleStatus.SelectedValue);
            if (((int)SamplingBussiness.SamplingStatus.DriverNotFound) != int.Parse(rbSampleStatus.SelectedValue))
            {
                if (!chkIsPlompOk.Checked && txtSamplerComments.Text.Trim().Length <= 0)
                {
                    Messages.SetMessage("Please enter the remark since the plomp ok is not checked!", WarehouseApplication.Messages.MessageType.Error);
                    return;
                }
                int noOfbag = 0;
                if (!int.TryParse(txtNumberOfBags.Text, out noOfbag))
                {
                    Messages.SetMessage("Please enter a valid number of bags!", WarehouseApplication.Messages.MessageType.Error);
                    return;
                }
                sm.NumberOfBags = noOfbag;
                if (drpBagType.SelectedIndex <= 0)
                {
                    Messages.SetMessage("Please select Bag Type!", WarehouseApplication.Messages.MessageType.Error);
                    return;
                }
                sm.BagTypeID       = new Guid(drpBagType.SelectedValue);
                sm.SamplerComments = txtSamplerComments.Text;
                sm.PlompStatusID   = (int)(chkIsPlompOk.Checked ? PlompStatus.PlompOK : PlompStatus.PlompNotOk);
                // sm.SupervisorApprovalRemark = ""; txtSuppervisorApprovalRemark.Text;
                //sm.SupervisorApprovalDateTime = DateTime.Parse(txtSupperVisorApprovalDate.Text);
                sm.HasLiveInsect       = chkHasLiveInsect.Checked;
                sm.HasMoldOrFungus     = chkHasMoldOrFungus.Checked;
                sm.HasChemicalOrPetrol = chkHasChemicalOrPetrol.Checked;
                reqRemark.Enabled      = !chkIsPlompOk.Checked;
            }
            sm.LastModifiedBy        = BLL.UserBLL.CurrentUser.UserId;
            sm.LastModifiedTimestamp = DateTime.Now;

            try
            {
                sm.Save();


                int    no  = 0;
                string msg = "";
                if (((int)SamplingBussiness.SamplingStatus.DriverNotFound) != int.Parse(rbSampleStatus.SelectedValue) &&
                    txtArrivalNoOfBags.Text.Trim() != string.Empty &&
                    int.TryParse(txtArrivalNoOfBags.Text, out no) &&
                    no < int.Parse(txtNumberOfBags.Text))
                {
                    msg = "Bag count greater than the bag count " + no + " registered on Voucher!";
                }
                //PopulateCombo(sm.CommodityID,sm.VoucherCommodityTypeID);
                //Clear(true);

                if (msg == string.Empty)
                {
                    Messages.SetMessage("Record saved successfully! ", WarehouseApplication.Messages.MessageType.Success);
                }
                else
                {
                    Messages.SetMessage("Record saved successfully! " + msg, WarehouseApplication.Messages.MessageType.Warning);
                }
                btnSaveSampleResult.Visible = false;
            }
            catch (Exception ex)
            {
                Messages.SetMessage(ex.Message, WarehouseApplication.Messages.MessageType.Error);
            }
        }