protected bool ReadHeader(string strPO) { string sqlCmdDMSource, sqlCmdDMTarget; SqlDataReader srcDataReader, tgtDataReader; SqlConnection scDMTarget = new SqlConnection(ConfigurationManager.ConnectionStrings["DMTargetConnectionString"].ConnectionString); SqlConnection scDMSource = new SqlConnection(ConfigurationManager.ConnectionStrings["DMSourceConnectionString"].ConnectionString); SqlCommand srcCommand, tgtCommand; DataView dv; string sVendor; // Reset line counts PackedLines = 0; TotalLines = 0; // Create Reference Record if it doesn't exist try { scDMTarget.Open(); // Loop through detail records, create new working status records sqlCmdDMTarget = string.Concat("Select * from POORDHP where PHPONO='", strPO, "'"); tgtCommand = new SqlCommand(sqlCmdDMTarget, scDMTarget); tgtDataReader = tgtCommand.ExecuteReader(); if (tgtDataReader.HasRows) { tgtDataReader.Read(); sVendor = tgtDataReader["PHVEN1"].ToString(); tgtDataReader.Close(); } else { lblMessage.Text = string.Concat("PO ", strPO, " Not Found"); tgtDataReader.Close(); scDMSource.Close(); scDMTarget.Close(); return(false); } scDMTarget.Close(); scDMSource.Open(); sqlCmdDMSource = string.Concat("SELECT * from SL_Status where (Vendor=", VendorList, ") and PO='", strPO, "'"); srcCommand = new SqlCommand(sqlCmdDMSource, scDMSource); srcDataReader = srcCommand.ExecuteReader(); if (!srcDataReader.HasRows) { sqlCmdDMSource = string.Concat("Insert into SL_Status (PO, Vendor, Reference, Status) Values('", strPO, "', ", VendorList, ", '', 'A')"); srcCommand = new SqlCommand(sqlCmdDMSource, scDMSource); srcCommand.ExecuteNonQuery(); } srcDataReader.Close(); scDMSource.Close(); } catch (Exception ex) { lblMessage.Text = "Critical error creating PO Reference."; return(false); } // Read Header Fields sdsPO.SelectCommand = string.Concat("Select POORDHP.*, Ref.Reference from POORDHP inner join [DMSource].[dbo].[SL_Status] as Ref on (POORDHP.PHPONO=Ref.PO) where PHPONO='", strPO, "'"); dv = (DataView)sdsPO.Select(DataSourceSelectArguments.Empty); if (dv.Count > 0) { lblShipName.Text = dv.Table.Rows[0].Field <string>("PHSNAM"); lblShipAddr1.Text = dv.Table.Rows[0].Field <string>("PHSAD1"); lblShipAddr2.Text = dv.Table.Rows[0].Field <string>("PHSAD2"); lblShipCity.Text = dv.Table.Rows[0].Field <string>("PHSCTY"); lblShipState.Text = dv.Table.Rows[0].Field <string>("PHSSTA"); lblShipZip.Text = dv.Table.Rows[0].Field <string>("PHSZIP"); lblPO.Text = dv.Table.Rows[0].Field <string>("PHPONO"); lblPODate.Text = string.Format(dv.Table.Rows[0].Field <DateTime>("PHDATE").ToString(), "MM/dd/yyyy"); lblCompletionDate.Text = string.Format(dv.Table.Rows[0].Field <DateTime>("PHEDAT").ToString(), "MM/dd/yyyy"); txtVendRef.Text = dv.Table.Rows[0].Field <string>("Reference"); lblVendor.Text = DataClass.GetVendor(dv.Table.Rows[0].Field <decimal>("PHVEN1")); return(true); } else { lblMessage.Text = "PO Not Found"; return(false); } }
protected bool ProcessSkid(GridViewRow gvr) { ImageButton ib; string s; int SkidNo, BulkNo, CartonNo, Seq; int CurrentSkid = 0, CurrentSkidSN = 0; int CurrentBulk = 0, CurrentBulkSN = 0; decimal CartonSN, SkidSN, BulkSN; TextBox tb; HyperLink hl; Label lbl; string sqlCmdDMSource; SqlConnection scDMSource = new SqlConnection(ConfigurationManager.ConnectionStrings["DMSourceConnectionString"].ConnectionString); SqlCommand scmdDMSource; SqlTransaction srcTransaction; SqlDataReader sdrDMSource; bool bSkidExists = false; bool bBulkExists = false; tb = (TextBox)gvr.FindControl("tbSkid"); lbl = (Label)gvr.FindControl("lblStatus"); // Get the current Skid for this row if (int.TryParse(tb.ToolTip, out CurrentSkid)) { } else { CurrentSkid = 0; lblMessage.Text = "Error Reading Skid #"; return(true); } if (int.TryParse(tb.Text, out SkidNo)) { } else { SkidNo = 0; // return false; } tb = (TextBox)gvr.FindControl("tbBulk"); // Get the current Skid for this row if (int.TryParse(tb.ToolTip, out CurrentBulk)) { } else { CurrentBulk = 0; lbl.Text = "Error reading Bulk Carton #"; return(true); } if (int.TryParse(tb.Text, out BulkNo)) { } else { BulkNo = 0; // return false; } // Are we re-assigning the skid # / Bulk # here? if ((CurrentSkid != SkidNo) || (CurrentBulk != BulkNo)) { if (SkidNo > 0) { CurrentSkidSN = DataClass.CheckSkidLabel(lblPO.Text, SkidNo); if (CurrentSkidSN > 0) { bSkidExists = true; } } else { // If Skid is 0, we aren't going to create it. bSkidExists = true; } if (BulkNo > 0) { CurrentBulkSN = DataClass.CheckBulkLabel(lblPO.Text, BulkNo); if (CurrentBulkSN > 0) { bBulkExists = true; } } else { // If Bulk is 0, we aren't going to create it. bBulkExists = true; } // Read out carton # if (int.TryParse(gvr.Cells[2].Text, out CartonNo)) { } else { lbl.Text = "Error reading Carton #"; return(true); } CartonSN = DataClass.GetCartonSN(lblPO.Text, CartonNo); scDMSource.Open(); srcTransaction = scDMSource.BeginTransaction(); try { sqlCmdDMSource = string.Concat("Update SL_Packing set Skid=", SkidNo.ToString(), ", BulkCarton=", BulkNo.ToString(), " Where (Vendor=", VendorList, ") and PO='", lblPO.Text, "' and Carton=", CartonNo); scmdDMSource = new SqlCommand(sqlCmdDMSource, scDMSource); scmdDMSource.Transaction = srcTransaction; if (scmdDMSource.ExecuteNonQuery() < 1) { tb.Text = ""; lbl.Text = "Critical Error Updating Packing Records."; srcTransaction.Rollback(); scDMSource.Close(); return(true); } else { // Then update skid # on this CartonNo sqlCmdDMSource = string.Concat("Update SL_Labels set Skid=", SkidNo.ToString(), ", BulkCarton=", BulkNo.ToString(), " where (Vendor=", VendorList, ") and PO='", lblPO.Text, "' and Carton=", CartonNo.ToString()); scmdDMSource = new SqlCommand(sqlCmdDMSource, scDMSource); scmdDMSource.Transaction = srcTransaction; if (scmdDMSource.ExecuteNonQuery() < 1) { tb.Text = ""; lbl.Text = string.Concat("Critical Error : Skid/Bulk on Carton # ", CartonNo.ToString()); srcTransaction.Rollback(); scDMSource.Close(); return(true); } if (!bBulkExists) { BulkSN = DataClass.GetNextBulk(lblPO.Text, BulkNo); // Now insert Label record into SL_Labels table sqlCmdDMSource = string.Concat("Insert Into SL_Labels (SkidSN, BulkSN, PackingSeq, Vendor, PO, Description, Seq, Skid, BulkCarton, Carton, Status, PrintStatus) values (0, ", BulkSN.ToString(), ", 0, ", VendorList, ", '", lblPO.Text, "', 'Bulk Label ", BulkNo.ToString(), "', 0, ", SkidNo.ToString(), ", ", BulkNo.ToString(), ",0,'A','')"); scmdDMSource = new SqlCommand(sqlCmdDMSource, scDMSource); scmdDMSource.Transaction = srcTransaction; if (scmdDMSource.ExecuteNonQuery() < 1) { tb.Text = ""; lbl.Text = "Critical Error Creating Bulk Label Record."; srcTransaction.Rollback(); scDMSource.Close(); return(true); } } else { // We are removing from a skid, check if anything is left on the skid and remove the label if necessary. sqlCmdDMSource = string.Concat("Select * from SL_Labels where (Vendor=", VendorList, ") and PO='", lblPO.Text, "' and BulkCarton=", CurrentBulk.ToString(), " and Carton<>0"); scmdDMSource = new SqlCommand(sqlCmdDMSource, scDMSource); scmdDMSource.Transaction = srcTransaction; sdrDMSource = scmdDMSource.ExecuteReader(); if (!sdrDMSource.HasRows) { sdrDMSource.Close(); // There is nothing else on this BulkCarton, time to remove it's label sqlCmdDMSource = string.Concat("Delete from SL_Labels where (Vendor=", VendorList, ") and PO='", lblPO.Text, "' and BulkCarton=", CurrentBulk.ToString(), " and Carton=0"); scmdDMSource = new SqlCommand(sqlCmdDMSource, scDMSource); scmdDMSource.Transaction = srcTransaction; scmdDMSource.ExecuteNonQuery(); // Now delete the skid sqlCmdDMSource = string.Concat("Delete from SL_Bulk where (Vendor=", VendorList, ") and PO='", lblPO.Text, "' and BulkCarton=", CurrentBulk.ToString()); scmdDMSource = new SqlCommand(sqlCmdDMSource, scDMSource); scmdDMSource.Transaction = srcTransaction; scmdDMSource.ExecuteNonQuery(); } else { sdrDMSource.Close(); } } // Updated Packing information with the Skid, create the label record if (!bSkidExists) { //// OK, Skid doesn't exist, get Seq from the Carton we are updating //sqlCmdDMSource = string.Concat("Select Seq from SL_Labels where (Vendor=", VendorList, ") and PO='", lblPO.Text, "' and Carton=", CartonNo.ToString()); //scmdDMSource = new SqlCommand(sqlCmdDMSource, scDMSource); //scmdDMSource.Transaction = srcTransaction; //sdrDMSource = scmdDMSource.ExecuteReader(); //if (sdrDMSource.HasRows) //{ // sdrDMSource.Read(); // Seq = (int)sdrDMSource["Seq"]; // sdrDMSource.Close(); //} //else //{ // Seq = 1; //} //// Then update sequence of all cartons >= selected CartonNo //sqlCmdDMSource = string.Concat("Update SL_Labels set Seq=Seq+1 where (Vendor=", VendorList, ") and PO='", lblPO.Text, "' and Seq>=", Seq.ToString()); //scmdDMSource = new SqlCommand(sqlCmdDMSource, scDMSource); //scmdDMSource.Transaction = srcTransaction; //if (scmdDMSource.ExecuteNonQuery() < 1) //{ // tb.Text = ""; // lbl.Text = "Critical Error Updating Carton Label Records: Sequence Insert."; // srcTransaction.Rollback(); // scDMSource.Close(); // return true; //} //else //{ SkidSN = DataClass.GetNextSkid(lblPO.Text, SkidNo); // Now insert Label record into SL_Labels table sqlCmdDMSource = string.Concat("Insert Into SL_Labels (SkidSN, BulkSN, PackingSeq, Vendor, PO, Description, Seq, Skid, BulkCarton, Carton, Status, PrintStatus) values (", SkidSN.ToString(), ", 0, 0, ", VendorList, ", '", lblPO.Text, "', 'Skid Label ", SkidNo.ToString(), "', 0, ", SkidNo.ToString(), ", ", BulkNo.ToString(), ",0,'A','')"); scmdDMSource = new SqlCommand(sqlCmdDMSource, scDMSource); scmdDMSource.Transaction = srcTransaction; if (scmdDMSource.ExecuteNonQuery() < 1) { tb.Text = ""; lbl.Text = "Critical Error Creating Skid Label Record."; srcTransaction.Rollback(); scDMSource.Close(); return(true); } // Update Skid # on Label // Commented 6/18/2020, will insert upon printing //sqlCmdDMSource = string.Concat("Insert into SL_Operations (SerialNo, Vendor, PO, Line, Item, Component, Description, ShipQty, Operation, CartonNo, OfCartons, SkidSerialNo, Status) Values (", CartonSN.ToString(), ", ", VendorList, ", '", lblPO.Text, "', '', '', '', '', 0, 'U', 0, 0, ", SkidSN.ToString(), ", 'N') "); //scmdDMSource = new SqlCommand(sqlCmdDMSource, scDMSource); //scmdDMSource.Transaction = srcTransaction; //scmdDMSource.ExecuteNonQuery(); // } } else { // We aren't creating a skid, assign the existing found Skid # int UpdateSkidSN = 0; if (SkidNo != 0) { UpdateSkidSN = CurrentSkidSN; // If we aren't creating the Skid, find it's serial # and then update the label // Now insert Label record into SL_Labels table // Update Skid # on Label } else { // We are removing from a skid, check if anything is left on the skid and remove the label if necessary. sqlCmdDMSource = string.Concat("Select * from SL_Labels where (Vendor=", VendorList, ") and PO='", lblPO.Text, "' and Skid=", CurrentSkid.ToString(), " and Carton<>0"); scmdDMSource = new SqlCommand(sqlCmdDMSource, scDMSource); scmdDMSource.Transaction = srcTransaction; sdrDMSource = scmdDMSource.ExecuteReader(); if (!sdrDMSource.HasRows) { sdrDMSource.Close(); // Nothing left on the skid, lets remove and resequence // First get the sequence of this skid # //sqlCmdDMSource = string.Concat("Select * from SL_Labels where (Vendor=", VendorList, ") and PO='", lblPO.Text, "' and Skid=", CurrentSkid.ToString(), " and Carton=0"); //scmdDMSource = new SqlCommand(sqlCmdDMSource, scDMSource); //scmdDMSource.Transaction = srcTransaction; //sdrDMSource = scmdDMSource.ExecuteReader(); //if (sdrDMSource.HasRows) //{ // sdrDMSource.Read(); // Seq = (int)sdrDMSource["Seq"]; // // Then update sequence of all cartons >= selected CartonNo // sqlCmdDMSource = string.Concat("Update SL_Labels set Seq=Seq-1 where (Vendor=", VendorList, ") and PO='", lblPO.Text, "' and Seq>", Seq.ToString()); // scmdDMSource = new SqlCommand(sqlCmdDMSource, scDMSource); // scmdDMSource.Transaction = srcTransaction; // if (scmdDMSource.ExecuteNonQuery() < 1) // { // tb.Text = ""; // lbl.Text = "Critical Error Updating Carton Label Records: Sequence Removal."; // srcTransaction.Rollback(); // scDMSource.Close(); // return true; // } //} //sdrDMSource.Close(); // There is nothing else on this skid, time to remove it's label sqlCmdDMSource = string.Concat("Delete from SL_Labels where (Vendor=", VendorList, ") and PO='", lblPO.Text, "' and Skid=", CurrentSkid.ToString(), " and Carton=0"); scmdDMSource = new SqlCommand(sqlCmdDMSource, scDMSource); scmdDMSource.Transaction = srcTransaction; scmdDMSource.ExecuteNonQuery(); // Now delete the skid sqlCmdDMSource = string.Concat("Delete from SL_Skids where (Vendor=", VendorList, ") and PO='", lblPO.Text, "' and Skid=", CurrentSkid.ToString()); scmdDMSource = new SqlCommand(sqlCmdDMSource, scDMSource); scmdDMSource.Transaction = srcTransaction; scmdDMSource.ExecuteNonQuery(); } else { sdrDMSource.Close(); } } // Commented 6/18/2020, SL_Operations will be updated upon printing //sqlCmdDMSource = string.Concat("Insert into SL_Operations (SerialNo, Vendor, PO, Line, Item, Component, Description, ShipQty, Operation, CartonNo, OfCartons, SkidSerialNo, Status) Values (", CartonSN.ToString(), ", ", VendorList, ", '", lblPO.Text, "', '', '', '', '', 0, 'U', 0, 0, ", UpdateSkidSN.ToString(), ", 'N') "); //scmdDMSource = new SqlCommand(sqlCmdDMSource, scDMSource); //scmdDMSource.Transaction = srcTransaction; //scmdDMSource.ExecuteNonQuery(); } } // Close SQL Connection srcTransaction.Commit(); scDMSource.Close(); if ((SkidNo == 0) && (BulkNo == 0)) { lbl.Text = string.Concat("Carton ", CartonNo.ToString(), " removed from Bulk/Skid."); } else { lbl.Text = string.Concat("Carton ", CartonNo.ToString(), " added to Bulk # ", BulkNo.ToString(), " Skid # ", SkidNo.ToString()); } } catch (Exception ex) { lbl.Text = "Critical Unhandled Exception."; srcTransaction.Rollback(); scDMSource.Close(); } tb.ToolTip = SkidNo.ToString(); } else { lbl.Text = ""; } return(false); }
protected void Page_Load(object sender, EventArgs e) { string PO = ""; string Line = ""; string Item = ""; string Qty = "0"; VendorList = DataClass.GetVendorList(); // Check Query Strings if (Request.QueryString["PO"] != null) { PO = Request.QueryString["PO"]; } else { lblMessage.Text = "Missing PO #"; return; } if (Request.QueryString["Line"] != null) { Line = Request.QueryString["Line"]; } else { // lblMessage.Text = "Missing Line #"; // return; } if (!IsPostBack) { // Populate header fields lblPO.Text = PO; lblLineNo.Text = Line; // Are we packing a specific line? if (Line.Trim() == "") { sdsPacking.SelectCommand = string.Concat("SELECT SL_Detail.PO, SL_Detail.Line, SL_Detail.Item, SL_Detail.Description, SL_Detail.ShipQty, SL_Packing.Carton, SL_Packing.BulkCarton, SL_Packing.Skid FROM SL_Packing INNER JOIN SL_Detail ON SL_Packing.Vendor = SL_Detail.Vendor and SL_Packing.PO = SL_Detail.PO AND SL_Packing.Line = SL_Detail.Line WHERE (SL_Detail.LineType = 'I') and (SL_Detail.PO='", PO, "') GROUP BY SL_Detail.PO, SL_Detail.Line, SL_Detail.Item, SL_Detail.ShipQty, SL_Detail.Description, SL_Packing.Carton, SL_Packing.BulkCarton, SL_Packing.Skid order by SL_Packing.Carton"); } else { sdsPacking.SelectCommand = string.Concat("SELECT SL_Detail.PO, SL_Detail.Line, SL_Detail.Item, SL_Detail.Description, SL_Detail.ShipQty, SL_Packing.Carton, SL_Packing.BulkCarton, SL_Packing.Skid FROM SL_Packing INNER JOIN SL_Detail ON SL_Packing.Vendor = SL_Detail.Vendor and SL_Packing.PO = SL_Detail.PO AND SL_Packing.Line = SL_Detail.Line WHERE (SL_Detail.LineType = 'I') and (SL_Detail.PO='", PO, "') and (SL_Detail.Line='", Line, "') GROUP BY SL_Detail.PO, SL_Detail.Line, SL_Detail.Item, SL_Detail.ShipQty, SL_Detail.Description, SL_Packing.Carton, SL_Packing.BulkCarton, SL_Packing.Skid order by SL_Packing.Carton"); } // Check if this item has components // sdsPacking.SelectCommand = string.Concat("SELECT SL_Detail.PO, SL_Detail.Line, SL_Detail.Item, SL_Detail.Description, SL_Detail.ShipQty, SL_Packing.Carton, SL_Packing.BulkCarton, SL_Packing.Skid FROM SL_Packing INNER JOIN SL_Detail ON SL_Packing.Vendor = SL_Detail.Vendor and SL_Packing.PO = SL_Detail.PO AND SL_Packing.Line = SL_Detail.Line WHERE (SL_Detail.LineType = 'I') and (SL_Detail.PO='", PO, "') and (SL_Detail.Line='", Line, "') GROUP BY SL_Detail.PO, SL_Detail.Line, SL_Detail.Item, SL_Detail.ShipQty, SL_Detail.Description, SL_Packing.Carton, SL_Packing.BulkCarton, SL_Packing.Skid order by SL_Packing.Carton"); DataView dv = (DataView)sdsPacking.Select(DataSourceSelectArguments.Empty); if (dv.Count != 0) { } else { lblMessage.Text = "No packing information found."; } gvPacking.DataBind(); hlComponents.NavigateUrl = string.Concat("./Components.aspx?PO=", PO, "&Line=", Line); hlPOByItem.NavigateUrl = string.Concat("./Default.aspx?PO=", PO); } else { // Make sure select command is up to date // Are we packing a specific line? if (Line.Trim() == "") { sdsPacking.SelectCommand = string.Concat("SELECT SL_Detail.PO, SL_Detail.Line, SL_Detail.Item, SL_Detail.Description, SL_Detail.ShipQty, SL_Packing.Carton, SL_Packing.BulkCarton, SL_Packing.Skid FROM SL_Packing INNER JOIN SL_Detail ON SL_Packing.Vendor = SL_Detail.Vendor and SL_Packing.PO = SL_Detail.PO AND SL_Packing.Line = SL_Detail.Line WHERE (SL_Detail.LineType = 'I') and (SL_Detail.PO='", PO, "') GROUP BY SL_Detail.PO, SL_Detail.Line, SL_Detail.Item, SL_Detail.ShipQty, SL_Detail.Description, SL_Packing.Carton, SL_Packing.BulkCarton, SL_Packing.Skid order by SL_Packing.Carton"); } else { sdsPacking.SelectCommand = string.Concat("SELECT SL_Detail.PO, SL_Detail.Line, SL_Detail.Item, SL_Detail.Description, SL_Detail.ShipQty, SL_Packing.Carton, SL_Packing.BulkCarton, SL_Packing.Skid FROM SL_Packing INNER JOIN SL_Detail ON SL_Packing.Vendor = SL_Detail.Vendor and SL_Packing.PO = SL_Detail.PO AND SL_Packing.Line = SL_Detail.Line WHERE (SL_Detail.LineType = 'I') and (SL_Detail.PO='", PO, "') and (SL_Detail.Line='", Line, "') GROUP BY SL_Detail.PO, SL_Detail.Line, SL_Detail.Item, SL_Detail.ShipQty, SL_Detail.Description, SL_Packing.Carton, SL_Packing.BulkCarton, SL_Packing.Skid order by SL_Packing.Carton"); } // sdsPacking.SelectCommand = string.Concat("SELECT SL_Detail.PO, SL_Detail.Line, SL_Detail.Item, SL_Detail.Description, SL_Detail.ShipQty, SL_Packing.Carton, SL_Packing.BulkCarton, SL_Packing.Skid FROM SL_Packing INNER JOIN SL_Detail ON SL_Packing.Vendor = SL_Detail.Vendor and SL_Packing.PO = SL_Detail.PO AND SL_Packing.Line = SL_Detail.Line WHERE (SL_Detail.LineType = 'I') and (SL_Detail.PO='", lblPO.Text, "') and (SL_Detail.Line='", lblLineNo.Text, "') GROUP BY SL_Detail.PO, SL_Detail.Line, SL_Detail.Item, SL_Detail.ShipQty, SL_Detail.Description, SL_Packing.Carton, SL_Packing.BulkCarton, SL_Packing.Skid order by SL_Packing.Carton"); lblMessage.Text = ""; } }
protected void Page_Load(object sender, EventArgs e) { string PO = ""; string Line = ""; string Item = ""; int Qty = 0; VendorList = DataClass.GetVendorList(); // Check Query Strings if (Request.QueryString["PO"] != null) { PO = Request.QueryString["PO"]; } else { lblMessage.Text = "Missing PO #"; return; } if (Request.QueryString["Line"] != null) { Line = Request.QueryString["Line"]; } else { lblMessage.Text = "Missing Line #"; return; } if (!IsPostBack) { DataClass.GetLineInfo(PO, Line, ref Item, ref Qty); // Populate header fields lblPO.Text = PO; lblLineNo.Text = Line; lblItemNo.Text = Item; lblPOQty.Text = Qty.ToString(); ShowNextCarton(); // If we are looking at a component line, select the components for display if (DataClass.CheckComponents(Item)) { lblItemType.Text = "C"; // Added LineType 'W' 3/8/2020 for WriteIns gvPacking.Columns[2].Visible = false; gvPacking.Columns[3].Visible = true; lbWriteIn.Visible = true; } else { lblItemType.Text = "I"; gvPacking.Columns[2].Visible = true; gvPacking.Columns[3].Visible = false; lbWriteIn.Visible = false; } SetupSelect(); lblCalcCartons.Text = "0"; gvPacking.DataBind(); hlPOByItem.NavigateUrl = string.Concat("./Default.aspx?PO=", PO); hlPOBySkid.NavigateUrl = string.Concat("./LinePacking.aspx?PO=", PO, "&Line=", Line); } else { lblMessage.Text = ""; SetupSelect(); } }
protected void btnPack(object sender, EventArgs e) { LinkButton lb; Label lbl; TextBox tbFrom, tbTo, tbShipQty; GridViewRow gvr; int TotalRows = 0; int ShipQty = 0; int NewID = 0; int NewSN = 0; int Seq = 0; int CartonStart, CartonEnd, TotalCartons; string strDescription, strComponent, strBOMQty, strShipQty; string sqlCommandSrc; bool bComponent = true; SqlConnection scDMSource = new SqlConnection(ConfigurationManager.ConnectionStrings["DMSourceConnectionString"].ConnectionString); SqlCommand srcCommand; SqlTransaction srcTransaction; SqlDataReader srcDataReader; lb = (LinkButton)sender; gvr = (GridViewRow)((LinkButton)sender).NamingContainer; tbFrom = (TextBox)gvr.FindControl("FromCarton"); tbTo = (TextBox)gvr.FindControl("ToCarton"); tbShipQty = (TextBox)gvr.FindControl("ShipQty"); lbl = (Label)gvr.FindControl("lblBOMQty"); strBOMQty = lbl.Text; lbl = (Label)gvr.FindControl("lblComponent"); strComponent = lbl.Text.Trim(); lbl = (Label)gvr.FindControl("lblDescription"); strDescription = HttpUtility.HtmlDecode(lbl.Text); // If this is an Item, clear out the Component gathered from the Item/Component cell if (strComponent.Length == 0) { bComponent = false; } // Validate Ship Qty if (int.TryParse(tbShipQty.Text, out ShipQty)) { strShipQty = ShipQty.ToString(); } else { lblMessage.Text = "Invalid Ship Qty."; return; } if ((tbFrom.Text.Trim().Length == 0) && (tbTo.Text.Trim().Length == 0)) { int BaseCarton; int.TryParse(lblNextCarton.Text, out BaseCarton); tbFrom.Text = lblNextCarton.Text; tbTo.Text = (BaseCarton + ShipQty - 1).ToString(); } if (int.TryParse(tbFrom.Text, out CartonStart)) { if (int.TryParse(tbTo.Text, out CartonEnd)) { if (CartonEnd < CartonStart) { lblMessage.Text = "To carton must larger than From carton."; return; } } else { CartonEnd = CartonStart; } // Open the connection, lets start moving some data!!! scDMSource.Open(); // Validate these carton #s are not in use on another line in this PO for (int i = CartonStart; i <= CartonEnd; i++) { sqlCommandSrc = string.Concat("Select * from SL_Packing Where (Vendor=", VendorList, ") and PO='", lblPO.Text, "' and Carton=", i.ToString(), " and Line<>'", lblLineNo.Text, "'"); srcCommand = new SqlCommand(sqlCommandSrc, scDMSource); srcDataReader = srcCommand.ExecuteReader(); if (srcDataReader.HasRows) { lblMessage.Text = string.Concat("Error: Carton #", i.ToString(), " used on another line for this Purchase Order."); srcDataReader.Close(); scDMSource.Close(); return; } srcDataReader.Close(); } // Create packing records, to be used to create carton labels TotalCartons = CartonEnd - CartonStart + 1; srcTransaction = scDMSource.BeginTransaction(); try { Seq = DataClass.GetNextLabelSeq(lblPO.Text, lblLineNo.Text); for (int i = CartonStart; i <= CartonEnd; i++) { // Create information about cartons/skids for this Line # decimal dShipQty = (decimal)ShipQty / (decimal)TotalCartons; decimal dRemainder = (decimal)ShipQty % (decimal)TotalCartons; if ((dRemainder > 0) && (dRemainder > (i - CartonStart))) { dShipQty++; } sqlCommandSrc = string.Concat("Insert into SL_Packing (Vendor, PO, Line, BOMQty, ShipQty, Item, Component, Description, Carton, Skid) Values(", VendorList, ", '", lblPO.Text, "', '", lblLineNo.Text, "', ", strBOMQty, ", ", dShipQty.ToString(), ", '", lblItemNo.Text, "', '", strComponent, "', '", strDescription, "', ", i.ToString(), ", ", 0, ")"); srcCommand = new SqlCommand(sqlCommandSrc, scDMSource); srcCommand.Transaction = srcTransaction; TotalRows += srcCommand.ExecuteNonQuery(); // Get the CartonID rom last insert sqlCommandSrc = string.Concat("Select @@Identity as newId from SL_Packing"); srcCommand = new SqlCommand(sqlCommandSrc, scDMSource); srcCommand.Transaction = srcTransaction; NewID = Convert.ToInt32(srcCommand.ExecuteScalar()); // Create Label for last created carton string sDescription; decimal InsertSeq; if (bComponent) { sDescription = string.Concat("Carton Label: ", lblItemNo.Text); InsertSeq = 0; } else { sDescription = lblItemNo.Text; InsertSeq = NewID; } // Check to see if a Label already exists for this PO/Line/Carton # // Do not create duplicate labels sqlCommandSrc = string.Concat("Select * from SL_Labels where (Vendor=", VendorList, ") and PO='", lblPO.Text, "' and Line='", lblLineNo.Text, "' and Carton=", i.ToString()); srcCommand = new SqlCommand(sqlCommandSrc, scDMSource); srcCommand.Transaction = srcTransaction; srcDataReader = srcCommand.ExecuteReader(); // We need to create this carton label. // It will be with a 0 PackingSeq if (!srcDataReader.HasRows) { sqlCommandSrc = string.Concat("Insert Into SL_Labels (PackingSeq, Vendor, PO, Line, Description, Seq, Skid, Carton, Status, PrintStatus) Values (", InsertSeq.ToString(), ",", VendorList, ",'", lblPO.Text, "','", lblLineNo.Text, "','", sDescription, "',", Seq.ToString(), ",0,", i.ToString(), ",'A','')"); srcCommand = new SqlCommand(sqlCommandSrc, scDMSource); srcCommand.Transaction = srcTransaction; srcCommand.ExecuteNonQuery(); // Get the CartonID rom last insert sqlCommandSrc = string.Concat("Select @@Identity as newId from SL_Labels"); srcCommand = new SqlCommand(sqlCommandSrc, scDMSource); srcCommand.Transaction = srcTransaction; NewSN = Convert.ToInt32(srcCommand.ExecuteScalar()); // Add to our AS400 int ThisCarton = (i - CartonStart) + 1; //sqlCommandSrc = string.Concat("Insert into SL_Operations (SerialNo, Vendor, PO, Line, Item, Component, Description, ShipQty, Operation, CartonNo, OfCartons, SkidSerialNo, Status) Values (", NewSN.ToString(), ", ", VendorList, ", '", lblPO.Text, "', '", lblLineNo.Text, "', '", lblItemNo.Text, "', '", strComponent, "', '", strDescription, "', ", dShipQty.ToString(), ", 'A', ", ThisCarton.ToString(), ", ", TotalCartons.ToString(), ", 0, 'N') "); //srcCommand = new SqlCommand(sqlCommandSrc, scDMSource); //srcCommand.Transaction = srcTransaction; //srcCommand.ExecuteNonQuery(); } srcDataReader.Close(); Seq++; } // Update this row in the detail and mark as Packed sqlCommandSrc = string.Concat("Update SL_Detail set ShipQty=", strShipQty, ", ShipLabels=", TotalCartons.ToString(), ", PrintStatus='', PackStatus='P', PackTime='", DateTime.Now, "' where (Vendor=", VendorList, ") and PO='", lblPO.Text, "' and Line='", lblLineNo.Text, "' and Item='", lblItemNo.Text, "' and Component='", strComponent, "'"); srcCommand = new SqlCommand(sqlCommandSrc, scDMSource); srcCommand.Transaction = srcTransaction; srcCommand.ExecuteNonQuery(); // If this is a component and all pieces are packed, mark the "Item" as packed if (bComponent) { sqlCommandSrc = string.Concat("Select * from SL_Detail where (Vendor=", VendorList, ") and PO='", lblPO.Text, "' and Line='", lblLineNo.Text, "' and Item='", lblItemNo.Text, "' and LineType='C' and PackStatus='S'"); srcCommand = new SqlCommand(sqlCommandSrc, scDMSource); srcCommand.Transaction = srcTransaction; srcDataReader = srcCommand.ExecuteReader(); if (!srcDataReader.HasRows) { int TotalLabels = 0; srcDataReader.Close(); // Get total Component label count sqlCommandSrc = string.Concat("Select count(distinct Carton) as TotalLabels from SL_Packing where (Vendor=", VendorList, ") and PO='", lblPO.Text, "' and Line='", lblLineNo.Text, "'"); srcCommand = new SqlCommand(sqlCommandSrc, scDMSource); srcCommand.Transaction = srcTransaction; srcDataReader = srcCommand.ExecuteReader(); if (srcDataReader.HasRows) { srcDataReader.Read(); int.TryParse(srcDataReader["TotalLabels"].ToString(), out TotalLabels); srcDataReader.Close(); } else { lblMessage.Text = "Critical error counting labels"; srcDataReader.Close(); srcTransaction.Rollback(); scDMSource.Close(); return; } // Update this Item as Packed in the detail sqlCommandSrc = string.Concat("Update SL_Detail set ShipLabels=", TotalLabels.ToString(), ", PrintStatus='', PackStatus='P', PackTime='", DateTime.Now, "' where (Vendor=", VendorList, ") and PO='", lblPO.Text, "' and Line='", lblLineNo.Text, "' and Item='", lblItemNo.Text, "' and LineType='I'"); srcCommand = new SqlCommand(sqlCommandSrc, scDMSource); srcCommand.Transaction = srcTransaction; srcCommand.ExecuteNonQuery(); } else { // There are still rows srcDataReader.Close(); } } srcTransaction.Commit(); // gvr = (GridViewRow)((TextBox)sender).NamingContainer; //hl = (HyperLink)gvr.Cells[4].Controls[0]; // Close SQL Connection scDMSource.Close(); tbShipQty.Enabled = false; tbFrom.Enabled = false; tbTo.Enabled = false; lb.Visible = false; lb = (LinkButton)gvr.FindControl("btnUnpack"); lb.Visible = true; lblMessage.Text = string.Concat(TotalRows.ToString(), " Cartons Created."); ShowNextCarton(); } catch (Exception ex) { srcTransaction.Rollback(); scDMSource.Close(); lblMessage.Text = "Error packing cartons."; return; } } else { lblMessage.Text = "Invalid From Carton #"; } }
protected void btnPrintSelected_Click(object sender, EventArgs e) { string strCommand; LinkButton lb; CheckBox cb; GridViewRow gvr; string printContent = ""; string divContent = ""; bool rowClosed = false; bool PrintAll = false; int rowNumber = 0; int lblCount = 0; string VendorLine; string ShipAddr2, ShipAddr1, ShipName, ShipCity, ShipZip, ShipState; string Model; // const string quote = "\""; lb = (LinkButton)sender; if (string.Compare(lb.ID, "lbPrintAll") == 0) { PrintAll = true; } // Get header record information for the labels // Read Header Fields string sqlCommandSrc; SqlConnection sqlConnection2 = new SqlConnection(ConfigurationManager.ConnectionStrings["DMTargetConnectionString"].ConnectionString); SqlConnection sqlConnection1 = new SqlConnection(ConfigurationManager.ConnectionStrings["DMSourceConnectionString"].ConnectionString); SqlDataReader sdr; sqlConnection2.Open(); sqlConnection1.Open(); sqlCommandSrc = string.Concat("Select * from POORDHP where PHPONO = '", lblPO.Text, "'"); SqlCommand command = new SqlCommand(sqlCommandSrc, sqlConnection2); sdr = command.ExecuteReader(); if (sdr.HasRows) { sdr.Read(); ShipAddr2 = (string)sdr["PHSAD2"]; ShipAddr1 = (string)sdr["PHSAD1"]; ShipName = (string)sdr["PHSNAM"]; ShipCity = (string)sdr["PHSCTY"]; ShipState = (string)sdr["PHSSTA"]; ShipZip = (string)sdr["PHSZIP"]; VendorLine = string.Concat("Vendor: ", DataClass.GetVendor((decimal)sdr["PHVEN1"]), "<br/><hr/>"); } else { sdr.Close(); sqlConnection1.Close(); sqlConnection2.Close(); lblMessage.Text = "Critical Error: Order Header Information Not Found"; return; } sdr.Close(); sqlConnection2.Close(); // Setup print content header printContent = string.Concat("<head><link rel=\"stylesheet\" type=\"text/css\" href=\"Labels.css\"></head><body>"); for (int i = 0; i < gvPrinting.Rows.Count; i++) { gvr = gvPrinting.Rows[i]; cb = (CheckBox)gvr.FindControl("cbPrint"); // If we can't find a checkbox, next row if ((cb != null) && (cb.Visible == true)) { // Are we printing this label? if ((PrintAll == true) || (cb.Checked == true)) { // Generate actual label text into divContent // cb.Tooltip has the SN of the label we are printing strCommand = string.Concat("SELECT SL_Labels.LabelSN, SL_Labels.BulkSN, SL_Labels.SkidSN, SL_Labels.PackingSeq, SL_Labels.PO, SL_Labels.Description, SL_Labels.Seq, SL_Labels.Skid, SL_Labels.BulkCarton, SL_Labels.Carton, SL_Labels.Status, SL_Labels.PrintStatus, SL_Labels.Line, SL_Packing.Component, SL_Packing.Item, SL_Packing.ShipQty, SL_Packing.BOMQty FROM SL_Labels FULL OUTER JOIN SL_Packing ON SL_Labels.PackingSeq = SL_Packing.Seq WHERE ((SL_Labels.Vendor = ", VendorList, ") and SL_Labels.PO = '", lblPO.Text, "' and SL_Labels.LabelSN=", cb.ToolTip.ToString() + ")"); command = new SqlCommand(strCommand, sqlConnection1); sdr = command.ExecuteReader(); if (sdr.HasRows) { int CartonCount, MinCarton, CurrentCarton, BoxNo; int SkidNo; int BulkCarton; decimal CartonSN; decimal BulkSN; decimal SkidSN; string PrintCarton; string LineNo; sdr.Read(); SkidNo = (int)sdr["Skid"]; BulkCarton = (int)sdr["BulkCarton"]; CartonSN = (decimal)sdr["LabelSN"]; BulkSN = (decimal)sdr["BulkSN"]; SkidSN = (decimal)sdr["SkidSN"]; LineNo = sdr["Line"].ToString(); CurrentCarton = (int)sdr["Carton"]; // Check if this is a skid label, pre-pend 'S' if it is if ((SkidNo > 0) && (CurrentCarton == 0) && (BulkCarton == 0)) { PrintCarton = string.Concat("S", SkidSN.ToString("000000000")); } else if ((BulkCarton > 0) && (CurrentCarton == 0)) { PrintCarton = string.Concat("B", BulkSN.ToString("000000000")); } else { PrintCarton = CartonSN.ToString("000000000"); } //// Check if this is a skid label, pre-pend 'S' if it is //if ((SkidNo > 0) && (CurrentCarton == 0)) //{ // PrintCarton = string.Concat("S", SkidSN.ToString("000000000")); //} //else //{ // PrintCarton = CartonSN.ToString("000000000"); //} CartonCount = DataClass.GetCartonCount(lblPO.Text, LineNo); MinCarton = DataClass.GetFirstCarton(lblPO.Text, LineNo); BoxNo = CurrentCarton - MinCarton + 1; // If we are printint a Skid label, set the box # to 0 as well. if (CartonCount == 0) { BoxNo = 0; } // Start generating the label content divContent = VendorLine; // Check if our Item is null, will be a skid label in this instance. if ((SkidNo > 0) && (BulkCarton == 0) && (CurrentCarton == 0)) { divContent += "<p style='text-align: center; font-size: 3em; font-weight: bold'>SKID " + SkidNo.ToString() + "</p><br/><br/>"; } else if ((BulkCarton > 0) && (CurrentCarton == 0)) { divContent += "<p style='text-align: center; font-size: 3em; font-weight: bold'>BULK CTN " + BulkCarton.ToString() + "</p><br/><br/>"; } else { if (System.DBNull.Value.Equals(sdr["Item"])) { Model = (string)sdr["Description"]; divContent += string.Concat(Model, "<br/>"); } else { Model = (string)sdr["Item"]; divContent += string.Concat("Model: ", Model, "<br/>"); } divContent += "Finishes: <br/>"; divContent += string.Concat("Qty: ", sdr["ShipQty"], "<br/>"); divContent += string.Concat("Box: ", BoxNo.ToString(), " of ", CartonCount.ToString()); if ((BulkCarton != 0) && (BoxNo != 0)) { divContent += string.Concat(", Bulk #", BulkCarton.ToString()); } if ((SkidNo != 0) && (BoxNo != 0)) { divContent += string.Concat(" - On Skid: ", SkidNo.ToString()); } } divContent += string.Concat("<br/><hr/>"); divContent += "Ship To: <br/>"; divContent += string.Concat(ShipName, "<br/>"); divContent += string.Concat(ShipAddr1, "<br/>"); if (ShipAddr2.Trim().Length > 0) { divContent += string.Concat(ShipAddr2, "<br/>"); } divContent += string.Concat(ShipCity, ", ", ShipState, " ", ShipZip, "<br />"); divContent += "Load: <br/>"; divContent += string.Concat("PO NUMBER/LINE#: <B>", lblPO.Text, " / ", LineNo.ToString(), "<B/><br/>"); divContent += string.Concat("ORDER /LINE#: <br/><hr/>"); divContent += string.Concat("<div style=\"height: 1.5in;\"><center><img alt='Barcode Generator TEC-IT' src='https://barcode.tec-it.com/barcode.ashx?data=", PrintCarton, "&code=Code39&dpi=96&dataseparator=' /></center></div>"); divContent += string.Concat("<hr/>"); } else { sdr.Close(); sqlConnection1.Close(); lblMessage.Text = string.Concat("Critical Error Locating Label: ", cb.ToolTip); return; } sdr.Close(); // Are we printing in the left or right column? if ((lblCount % 2) == 0) { rowNumber++; if ((rowNumber % 2) == 0) { // Spacer printContent += string.Concat("<div style=\"width: 100%; display: table; min-height: .5in;\"><div style=\"display: table-row;\"><div style=\"display: table-cell;\"><hr /></div></div></div>"); printContent += string.Concat("<div style=\"width: 100%; display: table; \"><div style=\"display: table-row; page-break-after: always;\">"); //printContent += string.Concat("<div style=\"width: 100%; display: table; \"><div style=\"display: table-row; height: 7.5in; min-height: 7.5in;\">"); } else { printContent += string.Concat("<div style=\"width: 100%; display: table; \"><div style=\"display: table-row; height: 7.75in; min-height: 7.75in;\">"); // printContent += string.Concat("<div style=\"width: 100%; display: table; \"><div style=\"display: table-row; height: 7.5in; min-height: 7.5in;\">"); // rowClosed = false; } // Label Row Header rowClosed = false; } printContent += string.Concat("<div class=\"Label\" style=\"display: table-cell; min-width: 4in; \">", divContent, "</div>"); // Last, increase our printed label count for positioning the next label, and mark this one printed DataClass.MarkPrinted(cb.ToolTip); lblCount++; cb.Checked = false; // Also uncheck the print selection cb.Text = "Re-Print"; // Close off the row if ((lblCount % 2) == 0) { printContent += "</div></div>"; rowClosed = true; } } // End: if((PrintAll == true) || (cb.Checked == true)) } // End: if((cb != null) && (cb.Visible == true)) //lb = (LinkButton)gvr.FindControl("btnPrint"); //if (lb != null) //{ // DataClass.MarkPrinted(lb.ToolTip); //} } // End: for (int i = 0; i < gvPrinting.Rows.Count; i++) if (rowClosed == false) { printContent += string.Concat("<div class=\"Label\" style=\"display: table-cell; min-width: 4in;\"> <br/><center> </center><br/></div></div></div>"); } printContent += string.Concat("</body>"); sqlConnection1.Close(); // Let's print!!! //StreamWriter streamWriter = new StreamWriter("C:\\Temp\\Log.Txt", true); //streamWriter.WriteLine("Starting Print"); //streamWriter.Flush(); var Renderer = new IronPdf.HtmlToPdf(); Renderer.PrintOptions.SetCustomPaperSizeInInches(8.5, 13); Renderer.PrintOptions.MarginTop = 6; Renderer.PrintOptions.MarginBottom = 6; Renderer.PrintOptions.MarginLeft = 6; Renderer.PrintOptions.MarginRight = 6; Renderer.PrintOptions.DPI = 300; // Renderer.PrintOptions.RenderDelay = 50; Renderer.PrintOptions.CssMediaType = PdfPrintOptions.PdfCssMediaType.Print; string FileName = string.Concat("Labels", lblPO.Text.Trim(), "_", DateTime.Now.ToFileTimeUtc().ToString(), ".PDF"); string Path = string.Concat("C:\\Temp\\", FileName); // Renderer.RenderHtmlAsPdf(printContent).SaveAs(FileName); //streamWriter.WriteLine(String.Concat("Printing: ", Path)); //streamWriter.Flush(); PdfDocument PDF = Renderer.RenderHtmlAsPdf(printContent); //streamWriter.WriteLine(String.Concat("Rendered: ", Path)); //streamWriter.Flush(); PDF.SaveAs(Path); //streamWriter.WriteLine("Finished, closing"); //streamWriter.Flush(); //streamWriter.Close(); System.Web.HttpResponse response = System.Web.HttpContext.Current.Response; response.ClearContent(); response.Clear(); response.ContentType = "application/pdf"; response.AddHeader("Content-Disposition", "attachment; filename=" + FileName + ";"); response.TransmitFile(Path); response.Flush(); response.End(); }
protected void btnPrint(object sender, EventArgs e) { string sqlCommandSrc; SqlCommand command; SqlDataReader sdr, sdrDMTarget; LinkButton lb; lb = (LinkButton)sender; DataClass.MarkPrinted(lb.ToolTip); SqlConnection sqlConnection2 = new SqlConnection(ConfigurationManager.ConnectionStrings["DMTargetConnectionString"].ConnectionString); SqlConnection sqlConnection1 = new SqlConnection(ConfigurationManager.ConnectionStrings["DMSourceConnectionString"].ConnectionString); // Get the PO/Line # for this Carton sqlCommandSrc = string.Concat("Select * from SL_Labels where LabelSN=", lb.ToolTip.ToString()); sqlCommandSrc = string.Concat("SELECT SL_Labels.LabelSN, SL_Labels.SkidSN, SL_Labels.PackingSeq, SL_Labels.PO, SL_Labels.Description, SL_Labels.Seq, SL_Labels.Skid, SL_Labels.Carton, SL_Labels.Status, SL_Labels.PrintStatus, SL_Labels.Line, SL_Packing.Component, SL_Packing.Item, SL_Packing.ShipQty, SL_Packing.BOMQty FROM SL_Labels FULL OUTER JOIN SL_Packing ON SL_Labels.PackingSeq = SL_Packing.Seq WHERE((SL_Labels.Vendor = ", VendorList, ") and SL_Labels.PO = '", lblPO.Text, "') ORDER BY SL_Labels.LabelSN"); command = new SqlCommand(sqlCommandSrc, sqlConnection1); sdr = command.ExecuteReader(); if (sdr.HasRows) { while (sdr.Read()) { int SkidNo, CurrentCarton, CartonCount, MinCarton, BoxNo; decimal CartonSN, SkidSN; string LineNo, PrintCarton; SkidNo = (int)sdr["Skid"]; CartonSN = (decimal)sdr["LabelSN"]; SkidSN = (decimal)sdr["SkidSN"]; LineNo = sdr["Line"].ToString(); CurrentCarton = (int)sdr["Carton"]; // Seq = (int)drv["Seq"]; // Check if this is a skid label, pre-pend 'S' if it is if ((SkidNo > 0) && (CurrentCarton == 0)) { PrintCarton = string.Concat("S", SkidSN.ToString("000000000")); } else { PrintCarton = CartonSN.ToString("000000000"); } CartonCount = DataClass.GetCartonCount(lblPO.Text, LineNo); MinCarton = DataClass.GetFirstCarton(lblPO.Text, LineNo); BoxNo = CurrentCarton - MinCarton + 1; // If we are printint a Skid label, set the box # to 0 as well. if (CartonCount == 0) { BoxNo = 0; } sqlConnection2.Open(); sqlCommandSrc = string.Concat("Select * from POORDHP where PHPONO = '", lblPO.Text, "'"); command = new SqlCommand(sqlCommandSrc, sqlConnection2); sdrDMTarget = command.ExecuteReader(); if (sdrDMTarget.HasRows) { sdrDMTarget.Read(); string addr2 = (string)sdr["PHSAD2"]; // string Model; // hl.NavigateUrl = String.Concat("/Component.aspx?PO=", txtSearch.Text, "&Item=", hl.Text.Trim); } else { sqlConnection1.Close(); sqlConnection2.Close(); lblMessage.Text = "PO Not Found"; return; } } } sdr.Close(); sqlConnection1.Close(); sqlConnection2.Close(); }
protected void gvLabels_Databound(object sender, GridViewRowEventArgs e) { // LinkButton lb; DataRowView drv; Literal innerHtml, SN; TableCell cell; string LineNo; int CartonCount, MinCarton, CurrentCarton, BoxNo; // int Seq; int SkidNo; string divID; decimal CartonSN; decimal SkidSN; string PrintCarton; if (e.Row.RowType == DataControlRowType.DataRow) { drv = (DataRowView)e.Row.DataItem; // Display the company name in italics. innerHtml = (Literal)e.Row.FindControl("innerHtml"); SN = (Literal)e.Row.FindControl("SN"); SkidNo = (int)drv["Skid"]; CartonSN = (decimal)drv["LabelSN"]; SkidSN = (decimal)drv["SkidSN"]; LineNo = drv["Line"].ToString(); CurrentCarton = (int)drv["Carton"]; // Seq = (int)drv["Seq"]; cell = e.Row.Cells[0]; divID = string.Concat("divLabel_", e.Row.DataItemIndex.ToString()); // divID = string.Concat("divLabel_", CartonSN.ToString()); cell.Controls[0].ID = divID; SN.Text = CartonSN.ToString(); // Check if this is a skid label, pre-pend 'S' if it is if ((SkidNo > 0) && (CurrentCarton == 0)) { PrintCarton = string.Concat("S", SkidSN.ToString("000000000")); } else { PrintCarton = CartonSN.ToString("000000000"); } CartonCount = DataClass.GetCartonCount(lblPO.Text, LineNo); MinCarton = DataClass.GetFirstCarton(lblPO.Text, LineNo); BoxNo = CurrentCarton - MinCarton + 1; // If we are printint a Skid label, set the box # to 0 as well. if (CartonCount == 0) { BoxNo = 0; } // Read Header Fields string sqlCommandSrc; SqlConnection sqlConnection2 = new SqlConnection(ConfigurationManager.ConnectionStrings["DMTargetConnectionString"].ConnectionString); SqlDataReader sdr; sqlConnection2.Open(); sqlCommandSrc = string.Concat("Select * from POORDHP where PHPONO = '", lblPO.Text, "'"); SqlCommand command = new SqlCommand(sqlCommandSrc, sqlConnection2); sdr = command.ExecuteReader(); if (sdr.HasRows) { sdr.Read(); string addr2 = (string)sdr["PHSAD2"]; string Model; innerHtml.Text = string.Concat("Vendor: ", DataClass.GetVendor((decimal)sdr["PHVEN1"]), "<br/><hr/>"); // Check if our Item is null, will be a skid label in this instance. if (System.DBNull.Value.Equals(drv["Item"])) { Model = (string)drv["Description"]; innerHtml.Text += string.Concat(Model, "<br/>"); } else { Model = (string)drv["Item"]; innerHtml.Text += string.Concat("Model: ", Model, "<br/>"); } innerHtml.Text += "Finishes: <br/>"; innerHtml.Text += string.Concat("Qty: ", drv["ShipQty"], "<br/>"); innerHtml.Text += string.Concat("Box: ", BoxNo.ToString(), " of ", CartonCount.ToString()); if ((SkidNo != 0) && (BoxNo != 0)) { innerHtml.Text += string.Concat(" - On Skid: ", SkidNo.ToString()); } innerHtml.Text += string.Concat("<br/><hr/>"); innerHtml.Text += "Ship To: <br/>"; innerHtml.Text += string.Concat((string)sdr["PHSNAM"], "<br/>"); innerHtml.Text += string.Concat((string)sdr["PHSAD1"], "<br/>"); if (addr2.Trim().Length > 0) { innerHtml.Text += string.Concat(addr2, "<br/>"); } innerHtml.Text += string.Concat(sdr["PHSCTY"], ", ", sdr["PHSSTA"], " ", sdr["PHSZIP"], "<br />"); innerHtml.Text += "Load: <br/>"; innerHtml.Text += string.Concat("PO NUMBER/LINE#: <B>", lblPO.Text, " / ", LineNo.ToString(), "<B/><br/>"); innerHtml.Text += string.Concat("ORDER /LINE#: <br/><hr/>"); innerHtml.Text += string.Concat("<center><img alt='Barcode Generator TEC-IT' src='https://barcode.tec-it.com/barcode.ashx?data=", PrintCarton, "&code=Code39&dpi=96&dataseparator=' /></center> "); // hl.NavigateUrl = String.Concat("/Component.aspx?PO=", txtSearch.Text, "&Item=", hl.Text.Trim); } else { sqlConnection2.Close(); lblMessage.Text = "PO Not Found"; return; } sqlConnection2.Close(); } }