コード例 #1
0
        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);
        }
コード例 #2
0
        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();
        }
コード例 #3
0
        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;\">&nbsp;<br/><center>&nbsp;</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();
        }
コード例 #4
0
        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();
            }
        }