protected void btnSave_Click(object sender, EventArgs e)
        {
            if (ViewState["Indicator"] != null)
            {
                indicatorofOutputPosted = true;
            }
            if (!Regex.IsMatch(txtPostingDate.Text, "(((0|1)[0-9]|2[0-9]|3[0-1])\\/(0[1-9]|1[0-2])\\/((19|20)\\d\\d))$") || !Regex.IsMatch(txtDocumentDate.Text, "(((0|1)[0-9]|2[0-9]|3[0-1])\\/(0[1-9]|1[0-2])\\/((19|20)\\d\\d))$"))
            {
                var message1 = new JavaScriptSerializer().Serialize("Not Valid dates!!!");
                var script1  = string.Format("alert({0});", message1);
                ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "", script1, true);
            }
            else
            {
                foreach (GridViewRow g1 in gvOutput.Rows)
                {
                    string Qty = (g1.FindControl("txtOut") as TextBox).Text;
                    if (Qty != null && Qty != "")
                    {
                        OpSum = OpSum + Convert.ToDecimal(Qty);
                    }
                    lblOutputSum.Text = ":" + Convert.ToString(OpSum);
                }
                foreach (GridViewRow g1 in gvCons.Rows)
                {
                    string Qty = (g1.FindControl("txtCons") as TextBox).Text;
                    if (Qty != null && Qty != "")
                    {
                        ConsSum = ConsSum + Convert.ToDecimal(Qty);
                    }
                    lblConsumptionTotal.Text = ":" + Convert.ToString(ConsSum);
                }

                if (OpSum == ConsSum)
                {
                    NetworkCredential NetCredentials = new NetworkCredential();
                    NetCredentials.UserName = SessionManager.GetNAVUserName(HttpContext.Current);
                    NetCredentials.Password = SessionManager.GetNAVUserPassword(HttpContext.Current);

                    try
                    {
                        if (indicatorofOutputPosted == false)
                        {
                            foreach (GridViewRow g1 in gvOutput.Rows)
                            {
                                string  code     = (g1.FindControl("lblDimCode1") as Label).Text;
                                string  Qty      = (g1.FindControl("txtOut") as TextBox).Text;
                                Decimal quantity = 0;
                                if (Qty != null && Qty != "")
                                {
                                    if (Qty != null)
                                    {
                                        quantity = Convert.ToDecimal(Qty);
                                    }
                                    Web_Order_Mail objser = new Web_Order_Mail();
                                    objser.UseDefaultCredentials = true;
                                    objser.Credentials           = NetCredentials;
                                    // 0 = output
                                    objser.CreateItemJournal(0, lblNo.Text, quantity, code, lblItemNo.Text, Convert.ToDateTime(txtPostingDate.Text), Convert.ToDateTime(txtDocumentDate.Text), Convert.ToString(Session["NavUserName"]), string.Empty);
                                    objser = null;
                                }
                            }
                            // posted the entry for output
                            Web_Order_Mail objserv = new Web_Order_Mail();
                            objserv.UseDefaultCredentials = true;
                            objserv.Credentials           = NetCredentials;
                            indicatorofOutputPosted       = objserv.PostItemJournal(0);
                            objserv = null;
                        }
                        try
                        {
                            foreach (GridViewRow g1 in gvCons.Rows)
                            {
                                string code = (g1.FindControl("lblDimCode2") as Label).Text;
                                string Qty  = (g1.FindControl("txtCons") as TextBox).Text;
                                if (Qty != null && Qty != "")
                                {
                                    Decimal        quantity = Convert.ToDecimal(Qty);
                                    Web_Order_Mail objser   = new Web_Order_Mail();
                                    objser.UseDefaultCredentials = true;
                                    objser.Credentials           = NetCredentials;
                                    // 1 = Consumption
                                    objser.CreateItemJournal(1, lblNo.Text, quantity, code, lblItemNo.Text, Convert.ToDateTime(txtPostingDate.Text), Convert.ToDateTime(txtDocumentDate.Text), Convert.ToString(Session["NavUserName"]), string.Empty);
                                    objser = null;
                                }
                            }
                            // Consumption post
                            Web_Order_Mail objservc = new Web_Order_Mail();
                            objservc.UseDefaultCredentials = true;
                            objservc.Credentials           = NetCredentials;
                            bool i = objservc.PostItemJournal(1);
                            objservc = null;
                        }
                        catch (Exception ex)
                        {
                            ViewState["Indicator"] = true;
                            var message1 = new JavaScriptSerializer().Serialize(ex.Message.ToString());
                            var script1  = string.Format("alert({0});", message1);
                            ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "", script1, true);
                        }

                        var messagefordi1 = new JavaScriptSerializer().Serialize("Production Order :" + lblNo.Text + " : Output and Consumption entries are posted successfully.!!!");
                        var scriptForview = string.Format("alert({0});window.location='ShowRlsProductOdr.aspx';", messagefordi1);
                        ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "", scriptForview, true);
                    }
                    catch (Exception ex)
                    {
                        //ViewState["Indicator"] = true;
                        var message1 = new JavaScriptSerializer().Serialize(ex.Message.ToString());
                        var script1  = string.Format("alert({0});", message1);
                        ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "", script1, true);
                    }
                }
                else
                {
                    var message1 = new JavaScriptSerializer().Serialize("Sum of Output and Consumption must be same!!!");
                    var script1  = string.Format("alert({0});", message1);
                    ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "", script1, true);
                }
            }
        }