protected void btnAdd_Click(object sender, EventArgs e) { List <GRNServiceBLL> listGRNService = null; if (ViewState["listGRNService"] != null) { listGRNService = (List <GRNServiceBLL>)ViewState["listGRNService"]; } Nullable <Guid> id = null; GRNBLL objGRN = new GRNBLL(); objGRN.CommodityGradeId = new Guid(this.hfCommodityGradeId.Value.ToString()); objGRN.CommodityRecivingId = new Guid(this.hfReceivigRequestId.Value.ToString()); objGRN.WarehouseId = new Guid(this.hfWarehouseId.Value.ToString()); objGRN.BagTypeId = new Guid(this.hfBagTypeId.Value.ToString()); try { objGRN.VoucherId = new Guid(this.hfVoucherId.Value.ToString()); } catch { //TODO : check if Coffee / commodity with Voucher - then retun. } objGRN.UnLoadingId = new Guid(this.hfUnloadingId.Value.ToString()); objGRN.ScalingId = new Guid(); objGRN.GradingId = new Guid(this.hfGradingId.Value.ToString()); objGRN.SamplingTicketId = new Guid(this.hfSamplingId.Value.ToString()); objGRN.GRNTypeId = new Guid(this.cboGRNType.SelectedValue.ToString()); objGRN.DateDeposited = Convert.ToDateTime(this.lblDateDeposited.Text); objGRN.Status = (int)GRNStatus.New; objGRN.TotalNumberOfBags = Convert.ToInt32(this.lblBags.Text); objGRN.GradingCode = this.cboGradingCode.SelectedItem.ToString(); objGRN.GRNCreatedDate = DateTime.Parse(this.txtDateRecived.Text); try { objGRN.ClientId = new Guid(this.hfClientId.Value.ToString()); } catch { this.lblmsg.Text = "Invalid Client Id please check and try again."; return; } try { objGRN.GrossWeight = float.Parse(this.lblGrossWeight.Text); objGRN.NetWeight = float.Parse(this.lblNetWeight.Text); } catch { this.lblmsg.Text = " Weight Can not be calculated please check and try again."; return; } try { objGRN.OriginalQuantity = float.Parse(this.lblOriginalQuantity.Text); objGRN.CurrentQuantity = float.Parse(this.lblCurrentQuantity.Text); } catch { this.lblmsg.Text = "Quantity Can not be calculated please check and try again."; return; } if (string.IsNullOrEmpty(this.hfTrackingNo.Value.ToString()) == true) { this.lblmsg.Text = "Can not load Tracking No."; return; } else { objGRN.TrackingNo = this.hfTrackingNo.Value; } if (bool.Parse(ViewState["hasVoucher"].ToString()) == true) { if (string.IsNullOrEmpty(this.hfVoucherId.Value.ToString()) == true) { this.lblmsg.Text = "Can not load Voucher information."; return; } else { try { objGRN.VoucherId = new Guid(this.hfVoucherId.Value); } catch { this.lblmsg.Text = "Can not load Voucher information."; return; } } } else { objGRN.VoucherId = Guid.Empty; } if (string.IsNullOrEmpty(this.hfScalingId.Value.ToString()) == true) { this.lblmsg.Text = "Can not load Scaling information."; return; } else { try { objGRN.ScalingId = new Guid(this.hfScalingId.Value); } catch { this.lblmsg.Text = "Can not load Voucher information."; return; } } try { id = objGRN.Add(listGRNService); Session["GRNIDPrint"] = id.ToString(); } catch (IndeterminateGRNCountException) { this.lblmsg.Text = "Please check if GRN is Created and try again."; return; } catch (MultipleGRNForSingleGradingCodeException) { this.lblmsg.Text = "A GRN has already been created for this Grading Code."; return; } catch (Exception ex) { //this.lblmsg.Text = "An error has occured please try again.If the error persists contact the administrator."; //return; throw ex; } if (id != null) { Session["GRNID"] = id.ToString(); this.lblmsg.Text = "New GRN added Successfully."; //Response.Redirect("PageSwicther.aspx?TranNo=" + objGRN.TrackingNo); ScriptManager.RegisterStartupScript(this, this.GetType(), "ShowReport", "<script type=\"text/javascript\">" + string.Format("javascript:window.open(\"rptGRN.aspx?id={0}\", \"_blank\",\"height=400px,width=600px,top=0,left=0,resizable=yes,scrollbars=yes\");", Guid.NewGuid()) + "</script>", false); } else { this.lblmsg.Text = "Unable to add new GRN please try Again"; return; } //if (id != null) //{ //} }