protected void btnSave_Click(object sender, EventArgs e) { try { 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); } } foreach (GridViewRow g1 in gvCons.Rows) { string Qty = (g1.FindControl("txtCons") as TextBox).Text; if (Qty != null && Qty != "") { ConsSum = ConsSum + Convert.ToDecimal(Qty); } } if (OpSum == ConsSum) { NetworkCredential NetCredentials = new NetworkCredential(); NetCredentials.UserName = SessionManager.GetNAVUserName(HttpContext.Current); NetCredentials.Password = SessionManager.GetNAVUserPassword(HttpContext.Current); Web_Order_Mail objservno = new Web_Order_Mail(); objservno.UseDefaultCredentials = true; objservno.Credentials = NetCredentials; string docno = objservno.ItemJournalDocumentNoSeries(); objservno = null; 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; // 2 = Positive objser.CreateItemJournal(2, docno, quantity, code, drpItem.SelectedItem.Value, 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(2); objserv = null; } 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(3, docno, quantity, code, drpItem.SelectedItem.Value, 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(3); objservc = null; var message1 = new JavaScriptSerializer().Serialize("Positive and Negative entries are posted successfully.!!!"); var script1 = string.Format("alert({0});window.location='frmElectricitySummary.aspx';", 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); } } } 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); } }