protected void btnPrintPUN_Click(object sender, EventArgs e) { List <PickupNoticeModel> names = new List <PickupNoticeModel>(); string punIds = string.Empty; int WeightInKg = 0; foreach (GridViewRow gvr in this.gvSearchPickupNotice.Rows) { if (((CheckBox)gvr.FindControl("chkSelect")).Checked == true) { PickupNoticeModel g = new PickupNoticeModel(); if (!string.IsNullOrEmpty(punIds)) { punIds += ","; } punIds += gvSearchPickupNotice.DataKeys[gvr.RowIndex].Value.ToString(); g.ID = new Guid(gvSearchPickupNotice.DataKeys[gvr.RowIndex].Value.ToString()); names.Add(g); WeightInKg = WeightInKg + Convert.ToInt32(gvSearchPickupNotice.DataKeys[gvr.RowIndex].Values["WeightInKg"]); } } List <PickupNoticeModel> pikListcheck = PickupNoticeModel.PrintPUNChecking(punIds); if (pikListcheck.Count > 0) { Session["ReportType"] = "DoNuthing"; Messages.SetMessage("You may contact system administrator for assistance. From selected PUN list the following WHR# are already printed: " + pikListcheck.Select(s => s.WarehouseReceiptNo.ToString()).Aggregate((str, nex) => str + "," + nex), Messages.MessageType.Warning); } else { List <PickupNoticeModel> pikList = PickupNoticeModel.PreparePUNId(punIds); if (pikList.Count > 0) { Session["ReportType"] = "PUN"; Session["PUNID"] = pikList.Select(s => s.ID.ToString()).Aggregate((str, nex) => str + "," + nex); ScriptManager.RegisterStartupScript(this, this.GetType(), "ShowReport", "<script type=\"text/javascript\">" + string.Format("javascript:window.open(\"ReportViewer.aspx\", \"_blank\",\"height=1000px,width=1000px,top=0,left=0,resizable=yes,scrollbars=yes\");", Guid.NewGuid()) + "</script>", false); } else { Messages.SetMessage("The system can’t print this Pun please contact Administrator ", Messages.MessageType.Warning); } } btnGINProcess.Style["visibility"] = "Visible"; btnPrintPUN.Style["visibility"] = "Visible"; btnProcessPSA.Style["visibility"] = "Visible"; }
private void Process() { string punIds = string.Empty; int WeightInKg = 0; int MaxLimit = 0; int count = 0; foreach (GridViewRow gvr in this.gvSearchPickupNotice.Rows) { if (((CheckBox)gvr.FindControl("chkSelect")).Checked == true) { System.Web.UI.WebControls.Label lblUnApprovedGINCount = ((System.Web.UI.WebControls.Label)gvr.FindControl("lblUnApprovedGINCount")); int UnApprovedGINCount = 0; if (Session["ProcessType"].ToString() == "PSA" && int.TryParse(lblUnApprovedGINCount.Text, out UnApprovedGINCount) && UnApprovedGINCount > 0) { Messages.SetMessage("The selected PUN in row " + (gvr.RowIndex + 1).ToString() + " has unapproved " + UnApprovedGINCount + " GIN under it. Please approve that first!" , WarehouseApplication.Messages.MessageType.Warning); return; } if (!string.IsNullOrEmpty(punIds)) { punIds += ","; } punIds += gvSearchPickupNotice.DataKeys[gvr.RowIndex].Value.ToString(); Session["PUNID"] = punIds; count = count + 1; WeightInKg = WeightInKg + Convert.ToInt32(gvSearchPickupNotice.DataKeys[gvr.RowIndex].Values["WeightInKg"]); MaxLimit = Convert.ToInt32(gvSearchPickupNotice.DataKeys[gvr.RowIndex].Values["MaxLimit"]); } } //if (WeightInKg > MaxLimit) //{ // Messages.SetMessage("The selected PUN list exceeded the maximum capacity by : " + (Convert.ToInt32(CommodityMaximumRangeEnum.MaximumRange) - WeightInKg) + " You can only process maximum of " + Convert.ToInt32(CommodityMaximumRangeEnum.MaximumRange) + " for one truck/GIN.", Messages.MessageType.Warning); //} //else //{ GINModel ob = new GINModel(); List <PickupNoticeModel> pikListcheck = PickupNoticeModel.PrintPUNChecking(punIds); if (pikListcheck.Count != count) { Messages.SetMessage("From selected PUN list some of them are not printed.You can’t process GIN before PUN is printed. ", Messages.MessageType.Warning); } else { ob.ID = Guid.NewGuid(); ob.PrepareGIN(punIds); Guid gradeID; string shedName; gradeID = ob.PickupNoticesList[0].CommodityGradeID; shedName = ob.PickupNoticesList[0].ShedName; ob.PickupNoticesList[0].ShedName = shedName; int ProductionYear = ob.PickupNoticesList[0].ProductionYear; ob.PickupNoticesList[0].ProductionYear = ProductionYear; bool hasError = false; foreach (PickupNoticeModel pm in ob.PickupNoticesList) { if (pm.ProductionYear != ProductionYear || pm.CommodityGradeID != gradeID || pm.ShedName != shedName) { hasError = true; Messages.SetMessage("ERROR: Please check warehouse receipts are of the same grade, shed and production year!"); break; } } if (hasError) { return; } ob.PUNPrintDateTime = pikListcheck[0].PUNPrintDateTime; ob.PUNPrintedBy = pikListcheck[0].PUNPrintedBy; ob.GINNumber = ob.GetNewGINNumber()[0]; ob.AutoNumber = int.Parse(ob.GetNewGINNumber()[1]); // ob.TransactionId = WFTransaction.GetTransaction(new Guid(ConfigurationSettings.AppSettings["GINNew"])).ToString(); ob.WarehouseID = UserBLL.GetCurrentWarehouse(); ob.CommodityGradeID = gradeID; ob.ProductionYear = ProductionYear; Session["GINMODEL"] = ob; Session["EditMode"] = false; if (Session["ProcessType"].ToString() == "GIN") { Response.Redirect("GIN.aspx"); } else if (Session["ProcessType"].ToString() == "PSA") { Response.Redirect("GINPSA.aspx"); } //} } btnGINProcess.Style["visibility"] = "Visible"; btnPrintPUN.Style["visibility"] = "Visible"; btnProcessPSA.Style["visibility"] = "Visible"; }