protected void QtyChanged(object sender, EventArgs e)
        {
            ImageButton    ib;
            GridViewRow    gvr;
            string         s;
            int            BOMQty, ShipQty;
            TextBox        tb;
            HyperLink      hl;
            string         sqlCommandSrc;
            string         strLine, strItem;
            SqlConnection  scDMSource = new SqlConnection(ConfigurationManager.ConnectionStrings["DMSourceConnectionString"].ConnectionString);
            SqlCommand     srcCommand;
            SqlTransaction sqlTransaction;
            SqlDataReader  sdr;
            decimal        labelSN;

            tb = (TextBox)sender;
            if (int.TryParse(tb.Text, out ShipQty))
            {
                gvr = (GridViewRow)((TextBox)sender).NamingContainer;
                hl  = (HyperLink)gvr.Cells[4].Controls[0];

                int.TryParse(gvr.Cells[2].Text, out BOMQty);

                // Make edit button available
                ib         = (ImageButton)gvr.FindControl("ibEdit");
                ib.Visible = true;
                tb.Enabled = false;

                // Get our item #
                strItem = hl.Text.Trim();
                strLine = gvr.Cells[0].Text.Trim();
                // Update Ship Qty, set status to staged
                scDMSource.Open();
                sqlTransaction = scDMSource.BeginTransaction();
                try
                {
                    if (ShipQty == 0)
                    {
                        // If we aren't shipping this line, set the status to Packed
                        sqlCommandSrc = string.Concat("Update SL_Detail set ShipQty=0, PackStatus='P' Where (Vendor=", VendorList, ") and PO='", lblPO.Text, "' and Line='", strLine, "'");
                    }
                    else
                    {
                        sqlCommandSrc = string.Concat("Update SL_Detail set ShipQty=(ComponentQty * ", ShipQty.ToString(), "), PackStatus='S' Where (Vendor=", VendorList, ") and PO='", lblPO.Text, "' and Line='", strLine, "'");
                    }
                    srcCommand             = new SqlCommand(sqlCommandSrc, scDMSource);
                    srcCommand.Transaction = sqlTransaction;
                    if (srcCommand.ExecuteNonQuery() < 1)
                    {
                        lblMessage.Text = "Critical Error Updating Records.";
                        return;
                    }
                    else
                    {
                        if (ShipQty == 0)
                        {
                            gvr.Cells[7].Text = "Packed";
                        }
                        else
                        {
                            gvr.Cells[7].Text = "Staged";
                        }
                        hl.NavigateUrl = String.Concat("./Components.aspx?PO=", txtSearch.Text, "&Line=", strLine);          // , "&Item=", strItem, "&Qty=", ShipQty.ToString());
                                                                                                                             // DataClass.StageLabels(lblPO.Text, strLine, strItem, BOMQty, ShipQty);
                    }

                    // Create records to remove labels on AS400 side
                    // Commented 6/18/2020, All SL_Operations take place upon printing
                    //sqlCommandSrc = string.Concat("Select LabelSN from SL_Labels Where (Vendor=", VendorList, ") and PO='", lblPO.Text, "' and PackingSeq in (Select Seq from SL_Packing where (Vendor=", VendorList, ") and PO='", lblPO.Text, "' and Line='", strLine, "')");
                    //srcCommand = new SqlCommand(sqlCommandSrc, scDMSource);
                    //srcCommand.Transaction = sqlTransaction;
                    //sdr = srcCommand.ExecuteReader();
                    //if (sdr.HasRows)
                    //{
                    //    while (sdr.Read())
                    //    {
                    //        labelSN = (decimal)sdr["LabelSN"];
                    //        sqlCommandSrc = string.Concat("Insert into SL_Operations (SerialNo, Vendor, PO, Line, Item, Component, Description, ShipQty, Operation, CartonNo, OfCartons, SkidSerialNo, Status) Values (", labelSN.ToString(), ", ", VendorList, ", '", lblPO.Text, "', '', '', '', '', 0, 'D', 0, 0, 0, 'N') ");
                    //        srcCommand = new SqlCommand(sqlCommandSrc, scDMSource);
                    //        srcCommand.Transaction = sqlTransaction;
                    //        srcCommand.ExecuteNonQuery();
                    //    }
                    //    sdr.Close();
                    //}

                    // Remove Label records for these cartons
                    sqlCommandSrc          = string.Concat("Delete from SL_Labels Where (Vendor=", VendorList, ") and PO='", lblPO.Text, "' and PackingSeq in (Select Seq from SL_Packing where (Vendor=", VendorList, ") and PO='", lblPO.Text, "' and Line='", strLine, "')");
                    srcCommand             = new SqlCommand(sqlCommandSrc, scDMSource);
                    srcCommand.Transaction = sqlTransaction;
                    srcCommand.ExecuteNonQuery();

                    // Remove packing records
                    sqlCommandSrc          = string.Concat("Delete from SL_Packing Where (Vendor=", VendorList, ") and PO='", lblPO.Text, "' and Line='", strLine, "'");
                    srcCommand             = new SqlCommand(sqlCommandSrc, scDMSource);
                    srcCommand.Transaction = sqlTransaction;
                    srcCommand.ExecuteNonQuery();
                    sqlTransaction.Commit();
                }
                catch (Exception ex)
                {
                    sqlTransaction.Rollback();
                    scDMSource.Close();
                    lblMessage.Text = "Critical Error Updating Ship Qty";
                }

                // Close SQL Connection
                scDMSource.Close();
                lblMessage.Text = "Ship Quantity Updated.";
            }
            else
            {
                lblMessage.Text = "Invalid Ship Qty";
            }
        }
Пример #2
0
        protected void btnSave(object sender, EventArgs e)
        {
            GridViewRow gvr;
            TextBox     tb;
            // Label lbl;
            int    BOMQty, ShipQty;
            string Item;
            string Component;
            string Description;

            gvr = gvPacking.FooterRow;

            SqlConnection  scDMSource = new SqlConnection(ConfigurationManager.ConnectionStrings["DMSourceConnectionString"].ConnectionString);
            SqlCommand     srcCommand;
            SqlTransaction sqlTransaction;
            string         sqlCommandSrc;

            scDMSource.Open();
            sqlTransaction = scDMSource.BeginTransaction();

            try
            {
                Item = lblItemNo.Text;
                tb   = (TextBox)gvr.FindControl("txtBOMQty");
                try
                {
                    BOMQty = int.Parse(tb.Text);
                }
                catch (Exception ex)
                {
                    lblMessage.Text = "Invalid BOM Qty";
                    return;
                }
                tb = (TextBox)gvr.FindControl("txtShipQty");
                try
                {
                    ShipQty = int.Parse(tb.Text);
                }
                catch (Exception ex)
                {
                    lblMessage.Text = "Invalid Ship Qty";
                    return;
                }

                tb          = (TextBox)gvr.FindControl("txtComponent");
                Component   = tb.Text.Trim();
                tb          = (TextBox)gvr.FindControl("txtDescription");
                Description = tb.Text.Trim();

                // Insert Write-In into SL_Detail
                sqlCommandSrc          = string.Concat("Insert into SL_Detail (Vendor, PO, Line, LineType, Item, Component, Description, BomQty, ShipQty, CalcLabels, ShipLabels, PackStatus) Values (", VendorList, ",'", lblPO.Text, "', '", lblLineNo.Text, "', 'W', '", Item, "', '", Component, "', '", Description, "', ", BOMQty.ToString(), ", ", ShipQty.ToString(), ", 0, 0, 'S')");
                srcCommand             = new SqlCommand(sqlCommandSrc, scDMSource);
                srcCommand.Transaction = sqlTransaction;
                srcCommand.ExecuteNonQuery();

                // Update this Item as Staged in the detail
                sqlCommandSrc          = string.Concat("Update SL_Detail set PrintStatus='', ShipLabels=0, PackStatus='S', 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 = sqlTransaction;
                srcCommand.ExecuteNonQuery();

                sqlTransaction.Commit();
                scDMSource.Close();
                ClearFooter();
            }
            catch (Exception ex)
            {
                sqlTransaction.Rollback();
                scDMSource.Close();
                lblMessage.Text = string.Concat("Fatal Error Adding Row:", ex.Message);
                return;
            }

            gvPacking.ShowFooter = false;
            lbWriteIn.Visible    = true;
            gvPacking.DataBind();
        }