Ejemplo n.º 1
0
    protected void btnUpdateReqQty_Click(object sender, EventArgs e)
    {
        #region If user changed the item # then recalculate price

        if (hidNetUnitPrice.Value == "")
        {
            char[]    QtyArray = txtReqQty.Text.Trim().ToCharArray();
            string    UOMText  = "";
            string    Qtytext  = "";
            DataTable dt       = new DataTable();
            foreach (char c in QtyArray)
            {
                if (c.Equals('-'))
                {
                    Qtytext += c;
                }
                if (char.IsDigit(c))
                {
                    Qtytext += c;
                }
                if (c.Equals('.'))
                {
                    Qtytext += c;
                }
                if (char.IsLetter(c))
                {
                    UOMText += c;
                }
            }
            // get the data.
            DataSet dsAvail = SqlHelper.ExecuteDataset(Global.PFCERPConnectionString, "[pSOEGetBrAvail]",
                                                       new SqlParameter("@SearchItemNo", txtPFCItemNo.Text),
                                                       new SqlParameter("@QtyRequested", Qtytext),
                                                       new SqlParameter("@QtyUOM", UOMText),
                                                       new SqlParameter("@PrimaryBranch", ddlShipLoc.SelectedValue.Trim()));
            if (dsAvail.Tables.Count >= 1)
            {
                if (dsAvail.Tables.Count == 1)
                {
                    if (dsAvail.Tables[0].Rows.Count > 0)
                    {
                        ShowMessage("Invalid UOM " + UOMText, false);
                        scmSplitItem.SetFocus(txtReqQty);
                        return;
                    }
                }
                else
                {
                    dsAvail.Tables[1].DefaultView.RowFilter = "Location='" + ddlShipLoc.SelectedValue.Trim() + "'";
                    dt = dsAvail.Tables[1].DefaultView.ToTable();
                    lblAvailQty.Text = (dt != null && dt.Rows.Count > 0) ? dt.Rows[0]["QOH"].ToString() : "0";
                    txtReqQty.Text   = dsAvail.Tables[2].Rows[0]["QtyToSell"].ToString();
                }
            }

            // Display Pricing Information
            DataSet dsPricedetail = orderEntry.GetProductPriceDetail(Session["OrderHeaderID"].ToString(),
                                                                     txtPFCItemNo.Text.Trim(),
                                                                     Session["CustomerNumber"].ToString(),
                                                                     ddlShipLoc.SelectedValue,
                                                                     Session["OrderTableName"].ToString(),
                                                                     Session["DetailTableName"].ToString(),
                                                                     txtReqQty.Text,
                                                                     txtSellPrice.Text,
                                                                     lblPriceInd.Text,
                                                                     Session["CustPriceCode"].ToString());
            if (dsPricedetail != null && dsPricedetail.Tables.Count >= 1)
            {
                if (dsPricedetail.Tables.Count == 1)
                {
                    // We only go one table back, something is wrong
                    DataTable dtPrice = dsPricedetail.Tables[0];
                    if (dtPrice.Rows.Count > 0)
                    {
                        ShowMessage("Pricing problem", false);
                        scmSplitItem.SetFocus(txtPFCItemNo);
                    }
                }
                else
                {
                    if (dsPricedetail != null && dsPricedetail.Tables[1].Rows.Count > 0)
                    {
                        hidOECost.Value         = dsPricedetail.Tables[1].Rows[0]["OECost"].ToString();
                        hidAltUMQty.Value       = dsPricedetail.Tables[1].Rows[0]["AltUOMQty"].ToString();
                        txtSellPrice.Text       = Math.Round(Convert.ToDecimal(dsPricedetail.Tables[1].Rows[0]["AltSellPrice"]), 2).ToString();
                        hidNetUnitPrice.Value   = Math.Round(Convert.ToDecimal(dsPricedetail.Tables[1].Rows[0]["Price"]), 2).ToString();
                        lblPriceInd.Text        = dsPricedetail.Tables[1].Rows[0]["PriceOrigin"].ToString();
                        hidAvgCost.Value        = dsPricedetail.Tables[1].Rows[0]["AvgCost"].ToString();
                        hidPrevPriceValue.Value = txtSellPrice.Text;
                    }
                }
            }
        }

        #endregion

        if (txtReqQty.Text != "" && hidNetUnitPrice.Value != "")
        {
            int     _reqQty       = Convert.ToInt32(Math.Round(Convert.ToDecimal(txtReqQty.Text), 0));
            int     _sellStkQty   = Convert.ToInt32(hidSellStkQty.Value);
            decimal _netUnitPrice = Convert.ToDecimal(hidNetUnitPrice.Value);
            decimal _extAmt       = _netUnitPrice * _reqQty;
            decimal _extWght      = Convert.ToDecimal(hidNetWght.Value) * _reqQty;

            hidAltUMQty.Value = (_sellStkQty * _reqQty).ToString();
            lblExtAmount.Text = Math.Round(_extAmt, 2).ToString();
            lblExtWght.Text   = Math.Round(_extWght, 2).ToString();
            txtReqQty.Text    = _reqQty.ToString();
        }

        scmSplitItem.SetFocus(txtSellPrice);
        pnlEntry.Update();
    }