Ejemplo n.º 1
0
        protected void txtQtyBox_TextChanged(object sender, EventArgs e)                //This for calculate Qty value,Crate and Ltr for sale Line
        {
            try
            {
                GridViewRow gvrow       = (GridViewRow)(((TextBox)sender)).NamingContainer;
                TextBox     txtBox      = (TextBox)gvrow.FindControl("txtBox");
                TextBox     txtPCS      = (TextBox)gvrow.FindControl("txtPCS");
                TextBox     txtQty      = (TextBox)gvrow.FindControl("txtqty");    //total Qty conv
                TextBox     txtBoxPcs   = (TextBox)gvrow.FindControl("txtBoxPcs"); //total Qty conv
                HiddenField productPack = (HiddenField)gvrow.FindControl("HiddenField2");
                if (txtBox.Text == "")
                {
                    txtBox.Text = "0";
                }
                if (txtPCS.Text == "")
                {
                    txtPCS.Text = "0";
                }


                if (Convert.ToDecimal(txtPCS.Text) > Convert.ToDecimal(productPack.Value))
                {
                    int pcs       = Convert.ToInt32(Convert.ToDecimal(txtPCS.Text));
                    int pac       = Convert.ToInt32(Convert.ToDecimal(productPack.Value));
                    int addbox    = pcs / pac;
                    int remainder = pcs % pac;
                    if (remainder == 0)
                    {
                        txtPCS.Text = "0";
                    }
                    else
                    {
                        txtPCS.Text = Convert.ToString(remainder);
                    }
                    txtBox.Text = Convert.ToString(Convert.ToInt32(Convert.ToDouble(txtBox.Text)) + addbox);
                }

                if (txtBox.Text != "" && txtPCS.Text != "")
                {
                    string str = (Convert.ToInt32(txtBox.Text) + (Convert.ToDecimal(txtPCS.Text) / Convert.ToDecimal(productPack.Value))).ToString("N6");
                    txtQty.Text = str;
                }

                DataTable dt = new DataTable();
                dt = baseObj.GetData("SELECT BOXPRINT FROM [dbo].[udf_GetPCSDetails](" + App_Code.Global.ConvertToDecimal(txtQty.Text).ToString() + "," + Convert.ToDecimal(productPack.Value) + ")");
                if (dt.Rows.Count > 0)
                {
                    txtBoxPcs.Text = dt.Rows[0][0].ToString();
                }

                string[] calValue = baseObj.CalculatePrice1(gvrow.Cells[1].Text, string.Empty, decimal.Parse(txtQty.Text), "Box");
                if (calValue.Length > 0)
                {
                    gvrow.Cells[3].Text = calValue[0];                   //Crate
                    gvrow.Cells[8].Text = calValue[1];                   //ltr
                }
                if (Convert.ToDecimal(txtQty.Text) > Convert.ToDecimal(gvrow.Cells[9].Text))
                {
                    gvrow.BackColor = System.Drawing.Color.Red;
                    this.Page.ClientScript.RegisterStartupScript(GetType(), "Alert", " alert('Please check stock Qty for ITEM:" + gvrow.Cells[1].Text + " !');", true);
                    txtQty.Text         = "0";
                    gvrow.Cells[3].Text = "0";
                    gvrow.Cells[8].Text = "0";
                }
                else
                {
                    gvrow.BackColor = System.Drawing.Color.White;
                }

                ltr          = 0;
                Crates       = 0;
                BoxQty       = 0;
                TotalQtyConv = 0;
                PcsQty       = 0;

                foreach (GridViewRow grv in GridView2.Rows)
                {
                    string str = grv.Cells[3].Text;
                    Crates += Convert.ToDecimal(grv.Cells[3].Text);
                    TextBox txtQtyConv = (TextBox)grv.Cells[6].FindControl("txtqty");
                    TotalQtyConv += Convert.ToDecimal(txtQtyConv.Text);
                    TextBox txtBoxQty = (TextBox)grv.Cells[4].FindControl("txtBox");
                    BoxQty += Convert.ToDecimal(txtBoxQty.Text);
                    TextBox txtPcsQty = (TextBox)grv.Cells[5].FindControl("txtPCS");
                    PcsQty += Convert.ToDecimal(txtPcsQty.Text);
                    ltr    += Convert.ToDecimal(grv.Cells[8].Text);
                }

                GridView2.FooterRow.Cells[2].HorizontalAlign = HorizontalAlign.Right;
                GridView2.FooterRow.Cells[2].ForeColor       = System.Drawing.Color.MidnightBlue;
                GridView2.FooterRow.Cells[2].Text            = "TOTAL : ";
                GridView2.FooterRow.Cells[2].Font.Bold       = true;

                GridView2.FooterRow.Cells[3].HorizontalAlign = HorizontalAlign.Right;
                GridView2.FooterRow.Cells[3].ForeColor       = System.Drawing.Color.MidnightBlue;
                GridView2.FooterRow.Cells[3].Text            = Crates.ToString();
                GridView2.FooterRow.Cells[3].Font.Bold       = true;

                GridView2.FooterRow.Cells[4].Text            = BoxQty.ToString();
                GridView2.FooterRow.Cells[4].HorizontalAlign = HorizontalAlign.Right;
                GridView2.FooterRow.Cells[4].ForeColor       = System.Drawing.Color.MidnightBlue;
                GridView2.FooterRow.Cells[4].Font.Bold       = true;

                GridView2.FooterRow.Cells[5].Text            = PcsQty.ToString();
                GridView2.FooterRow.Cells[5].HorizontalAlign = HorizontalAlign.Right;
                GridView2.FooterRow.Cells[5].ForeColor       = System.Drawing.Color.MidnightBlue;
                GridView2.FooterRow.Cells[5].Font.Bold       = true;

                GridView2.FooterRow.Cells[6].Text            = TotalQtyConv.ToString();
                GridView2.FooterRow.Cells[6].HorizontalAlign = HorizontalAlign.Right;
                GridView2.FooterRow.Cells[6].ForeColor       = System.Drawing.Color.MidnightBlue;
                GridView2.FooterRow.Cells[6].Font.Bold       = true;

                GridView2.FooterRow.Cells[8].HorizontalAlign = HorizontalAlign.Right;
                GridView2.FooterRow.Cells[8].ForeColor       = System.Drawing.Color.MidnightBlue;
                GridView2.FooterRow.Cells[8].Text            = ltr.ToString();
                GridView2.FooterRow.Cells[8].Font.Bold       = true;
            }
            catch (Exception ex)
            {
                ErrorSignal.FromCurrentContext().Raise(ex);
                this.Page.ClientScript.RegisterStartupScript(GetType(), "Alert", " alert('Input String was not in Correct format !');", true);
            }
            //UppnalegridDetails.Update();
        }