public void BindGrid() { try { JournalVoucherMBL objJournalVoucherMBL = new JournalVoucherMBL(); JournalVoucherMBO objJournalVoucherMBO = new JournalVoucherMBO(); ApplicationResult objResultSelectAll = new ApplicationResult(); objResultSelectAll = objJournalVoucherMBL.JournalVoucherM_SelectAll(Convert.ToInt32(Session[ApplicationSession.TRUSTID]), Convert.ToInt32(Session[ApplicationSession.SCHOOLID]), Convert.ToInt32(Session[ApplicationSession.FINANCIALYEAR]), "Contra", Session[ApplicationSession.ACCOUNTFROMDATE].ToString(), Session[ApplicationSession.ACCOUNTTODATE].ToString()); if (objResultSelectAll != null) { DataTable dtSelectAll = new DataTable(); dtSelectAll = objResultSelectAll.resultDT; gvJournalContraEntry.DataSource = dtSelectAll; gvJournalContraEntry.DataBind(); } } catch (Exception ex) { logger.Error("Error", ex); ClientScript.RegisterStartupScript(typeof(Page), "MessagePopUp", "<script>alert('Oops! There is some technical issue. Please Contact to your administrator.');</script>"); } }
protected void gvJournalEntry_RowCommand(object sender, GridViewCommandEventArgs e) { try { JournalVoucherMBL objJournalVoucherMBL = new JournalVoucherMBL(); JournalVoucherMBO objJournalVoucherMBO = new JournalVoucherMBO(); ViewState["VoucherCode"] = e.CommandArgument.ToString(); if (e.CommandName.ToString() == "Edit1") { GvContraEntry.SelectedIndex = -1; ApplicationResult objResultSelect = new ApplicationResult(); objResultSelect = objJournalVoucherMBL.JournalVoucherM_Select(ViewState["VoucherCode"].ToString(), Convert.ToInt32(Session[ApplicationSession.TRUSTID]), Convert.ToInt32(Session[ApplicationSession.SCHOOLID])); if (objResultSelect != null) { DataTable dtSelect = new DataTable(); dtSelect = objResultSelect.resultDT; if (dtSelect.Rows.Count > 0) { ViewState["VoucherRow"] = dtSelect.Rows.Count; DataTable dt = new DataTable(); dt.Columns.Add("Number"); for (int i = 1; i <= Convert.ToInt32(ViewState["VoucherRow"]); i++) { dt.Rows.Add(i.ToString()); } GvContraEntry.DataSource = dt; GvContraEntry.DataBind(); BindAccountGroup(); for (int i = 0; i < dtSelect.Rows.Count; i++) { ((DropDownList)GvContraEntry.Rows[i].Cells[0].FindControl("ddlAccountName")).SelectedValue = dtSelect.Rows[i]["LedgerID"].ToString(); if (dtSelect.Rows[i]["TransactionType"].ToString() == "Debit") { ((TextBox)GvContraEntry.Rows[i].Cells[2].FindControl("txtDebitAmount")).Text = dtSelect.Rows[i]["Amount"].ToString(); } else { ((TextBox)GvContraEntry.Rows[i].Cells[3].FindControl("txtCreditAmount")).Text = dtSelect.Rows[i]["Amount"].ToString(); } GvContraEntry.Rows[i].Cells[4].Text = dtSelect.Rows[i][0].ToString(); txtNarration.Text = dtSelect.Rows[i]["Description"].ToString(); if (Convert.ToInt32(dtSelect.Rows[i]["ChequeNumber"]) != 0) { txtChequeNo.Text = dtSelect.Rows[i]["ChequeNumber"].ToString(); } txtVoucherCode.Text = ViewState["VoucherCode"].ToString(); txtDate.Text = dtSelect.Rows[i]["VoucherDate"].ToString(); } PanelVisibility(2); setControlScript(); enableDisableText(); getDebitCreditSum(); ViewState["Mode"] = "Edit"; } } } else if (e.CommandName.ToString() == "Delete1") { ApplicationResult objResultDelete = new ApplicationResult(); objResultDelete = objJournalVoucherMBL.JournalVoucherM_Delete(e.CommandArgument.ToString(), "Contra"); if (objResultDelete.status == ApplicationResult.CommonStatusType.SUCCESS) { BindGrid(); ClientScript.RegisterStartupScript(typeof(Page), "MessagePopUp", "<script>alert('Record Deleted Successfully.');</script>"); } } } catch (Exception ex) { logger.Error("Error", ex); ClientScript.RegisterStartupScript(typeof(Page), "MessagePopUp", "<script>alert('Oops! There is some technical issue. Please Contact to your administrator.');</script>"); } }
protected void btnSave_Click(object sender, EventArgs e) { try { string strVouchersDate = txtDate.Text; string strFromDate = Session[ApplicationSession.ACCOUNTFROMDATE].ToString(); string strToDate = Session[ApplicationSession.ACCOUNTTODATE].ToString(); string strYear; DateTime FromDate = Convert.ToDateTime(strFromDate); DateTime ToDate = Convert.ToDateTime(strToDate); DateTime VoucherDate = Convert.ToDateTime(strVouchersDate); strYear = Session[ApplicationSession.FINANCIALYEAR].ToString(); if (VoucherDate >= FromDate && VoucherDate <= ToDate) { //intOrgID = Convert.ToInt32(Session["Org_ID"].ToString()); getDebitCreditSum(); string strDebitSum, strCreditSum; strDebitSum = ((System.Web.UI.HtmlControls.HtmlInputText)(GvContraEntry.FooterRow.Cells[2].FindControl("txtDebitSum"))).Value; strCreditSum = ((System.Web.UI.HtmlControls.HtmlInputText)(GvContraEntry.FooterRow.Cells[3].FindControl("txtCreditSum"))).Value; // CHECK WHETHER ANY AMOUNT IS WITHOUT ACCOUNT SELECTION int intvalidate = 0; for (int i = 0; i < GvContraEntry.Rows.Count; i++) { string ddlVal = ((DropDownList)(GvContraEntry.Rows[i].Cells[0].FindControl("ddlAccountName"))).SelectedItem.Value; string strDebitAmt = ((TextBox)(GvContraEntry.Rows[i].Cells[2].FindControl("txtDebitAmount"))).Text; string strCreditAmt = ((TextBox)(GvContraEntry.Rows[i].Cells[3].FindControl("txtCreditAmount"))).Text; if (strDebitAmt != "" || strCreditAmt != "") { if (ddlVal == "-1") { ClientScript.RegisterStartupScript(typeof(Page), "MessagePopUp", "<script>alert('Select Account or enter amount before save Contra entry.');</script>"); return; } } else { intvalidate = intvalidate + 1; } if (GvContraEntry.Rows.Count == intvalidate) { ClientScript.RegisterStartupScript(typeof(Page), "MessagePopUp", "<script>alert('Select Account or enter amount before save Contra entry.');</script>"); return; } } if (strDebitSum == strCreditSum) // CHECKS WHETHER THE AMOUNTS MATCHES OR NOT { JournalVoucherMBL objJournalVoucherMBL = new JournalVoucherMBL(); JournalVoucherMBO objJournalVoucherMBO = new JournalVoucherMBO(); //JournalVoucherTBL objJournalVoucherTBL = new JournalVoucherTBL(); //JournalVoucherTBO objJournalVoucherTBO = new JournalVoucherTBO(); DatabaseTransaction.OpenConnectionTransation(); if (ViewState["Mode"].ToString() == "Save") { ApplicationResult objResultInsert = new ApplicationResult(); objJournalVoucherMBO.TrustMID = Convert.ToInt32(Session[ApplicationSession.TRUSTID]); objJournalVoucherMBO.SchoolMID = Convert.ToInt32(Session[ApplicationSession.SCHOOLID]); objJournalVoucherMBO.VoucherDate = txtDate.Text; if (txtChequeNo.Text != "") { objJournalVoucherMBO.ChequeNumber = Convert.ToInt32(txtChequeNo.Text); } objJournalVoucherMBO.OperationType = "Contra"; objJournalVoucherMBO.Description = txtNarration.Text; objJournalVoucherMBO.CreatedBy = Convert.ToInt32(Session[ApplicationSession.USERID]); objJournalVoucherMBO.CreatedDate = DateTime.UtcNow.AddHours(5.5).ToString("dd/MM/yyyy"); objJournalVoucherMBO.IsDeleted = 0; objJournalVoucherMBO.LastModifideDate = DateTime.UtcNow.AddHours(5.5).ToString("dd/MM/yyyy"); objJournalVoucherMBO.LastModifideUserID = Convert.ToInt32(Session[ApplicationSession.USERID]); objJournalVoucherMBO.Year = Convert.ToInt32(strYear); for (int i = 0; i < GvContraEntry.Rows.Count; i++) { string strAccountID = ((DropDownList)(GvContraEntry.Rows[i].Cells[0].FindControl("ddlAccountName"))).SelectedItem.Value; string strDebit = ((TextBox)(GvContraEntry.Rows[i].Cells[2].FindControl("txtDebitAmount"))).Text; string strCredit = ((TextBox)(GvContraEntry.Rows[i].Cells[3].FindControl("txtCreditAmount"))).Text; if ((strAccountID == "-1" && strDebit == "") || (strAccountID == "-1" && strCredit == "")) { continue; } if (strAccountID != "-1") { objJournalVoucherMBO.LedgerID = Convert.ToInt32(strAccountID); if (strDebit == "") { objJournalVoucherMBO.TransactionType = "Credit"; objJournalVoucherMBO.Amount = Convert.ToDouble(strCredit); } else { objJournalVoucherMBO.TransactionType = "Debit"; objJournalVoucherMBO.Amount = Convert.ToDouble(strDebit); } objResultInsert = objJournalVoucherMBL.JournalVoucherM_Insert(objJournalVoucherMBO); if (i == 0) { if (objResultInsert != null) { DataTable dt = new DataTable(); dt = objResultInsert.resultDT; if (dt.Rows.Count > 0) { if (dt.Rows[0][0].ToString() == "0") { DatabaseTransaction.RollbackTransation(); ClientScript.RegisterStartupScript(typeof(Page), "MessagePopUp", "<script>alert('Please Initialize Voucher Start No. For This Year.');</script>"); goto Exit; } else { ViewState["VoucherNo"] = Convert.ToInt32(dt.Rows[0][0]); ViewState["VoucherCode"] = dt.Rows[0][1].ToString(); objJournalVoucherMBO.VoucherNo = Convert.ToInt32(ViewState["VoucherNo"]); objJournalVoucherMBO.VoucherCode = ViewState["VoucherCode"].ToString(); } } } } else { objJournalVoucherMBO.VoucherNo = Convert.ToInt32(ViewState["VoucherNo"]); objJournalVoucherMBO.VoucherCode = ViewState["VoucherCode"].ToString(); } } } insertLedgerTransaction(ViewState["VoucherCode"].ToString()); ClientScript.RegisterStartupScript(typeof(Page), "MessagePopUp", "<script>alert('Contra Saved Successfully. Voucher No is " + ViewState["VoucherCode"].ToString() + "');</script>"); } else if (ViewState["Mode"].ToString() == "Edit") // UPDATE THE EXISTING JOURNAL { ApplicationResult objResulUpdate = new ApplicationResult(); objJournalVoucherMBO.TrustMID = Convert.ToInt32(Session[ApplicationSession.TRUSTID]); objJournalVoucherMBO.SchoolMID = Convert.ToInt32(Session[ApplicationSession.SCHOOLID]); objJournalVoucherMBO.VoucherDate = txtDate.Text; if (txtChequeNo.Text != "") { objJournalVoucherMBO.ChequeNumber = Convert.ToInt32(txtChequeNo.Text); } objJournalVoucherMBO.OperationType = "Contra"; objJournalVoucherMBO.Description = txtNarration.Text; objJournalVoucherMBO.CreatedBy = Convert.ToInt32(Session[ApplicationSession.USERID]); objJournalVoucherMBO.CreatedDate = DateTime.UtcNow.AddHours(5.5).ToString("dd/MM/yyyy"); objJournalVoucherMBO.IsDeleted = 0; objJournalVoucherMBO.LastModifideDate = DateTime.UtcNow.AddHours(5.5).ToString("dd/MM/yyyy"); objJournalVoucherMBO.LastModifideUserID = Convert.ToInt32(Session[ApplicationSession.USERID]); objJournalVoucherMBO.Year = Convert.ToInt32(strYear); objJournalVoucherMBO.VoucherNo = Convert.ToInt32(txtVoucherCode.Text.ToString().Substring(6, txtVoucherCode.Text.Length - 6)); objJournalVoucherMBO.VoucherCode = txtVoucherCode.Text; int intActRows = 0; for (int i = 0; i < GvContraEntry.Rows.Count; i++) { string strAccId = ((DropDownList)(GvContraEntry.Rows[i].Cells[0].FindControl("ddlAccountName"))).SelectedItem.Value; if (strAccId != "-1") { intActRows++; } else { break; } } if (intActRows == Convert.ToInt32(ViewState["VoucherRow"])) // CHECKS WHETHER THE JOURNAL RECORD IS LARGER OR SMALLER THEN EXIXTING RECORD { for (int i = 0; i < GvContraEntry.Rows.Count; i++) { GvContraEntry.Columns[4].Visible = true; if (GvContraEntry.Rows[i].Cells[4].Text.ToString() != "") { string strAccountID = ((DropDownList)(GvContraEntry.Rows[i].Cells[0].FindControl("ddlAccountName"))).SelectedItem.Value; string strDebit = ((TextBox)(GvContraEntry.Rows[i].Cells[2].FindControl("txtDebitAmount"))).Text; string strCredit = ((TextBox)(GvContraEntry.Rows[i].Cells[3].FindControl("txtCreditAmount"))).Text; if (strAccountID != "-1") { objJournalVoucherMBO.LedgerID = Convert.ToInt32(strAccountID); if (strDebit == "") { objJournalVoucherMBO.TransactionType = "Credit"; objJournalVoucherMBO.Amount = Convert.ToDouble(strCredit); } else { objJournalVoucherMBO.TransactionType = "Debit"; objJournalVoucherMBO.Amount = Convert.ToDouble(strDebit); } } objJournalVoucherMBO.JournalID = Convert.ToInt32(GvContraEntry.Rows[i].Cells[4].Text.ToString()); objResulUpdate = objJournalVoucherMBL.JournalVoucherM_Update(objJournalVoucherMBO, Session[ApplicationSession.ACCOUNTFROMDATE].ToString()); } GvContraEntry.Columns[4].Visible = false; } } else { ApplicationResult objResultInsert = new ApplicationResult(); ApplicationResult objResultDelete = new ApplicationResult(); objResultDelete = objJournalVoucherMBL.JournalVoucherM_Delete_Transaction(txtVoucherCode.Text, "Journal"); if (objResultDelete.status == ApplicationResult.CommonStatusType.SUCCESS) { } for (int i = 0; i < GvContraEntry.Rows.Count; i++) { string strAccountID = ((DropDownList)(GvContraEntry.Rows[i].Cells[0].FindControl("ddlAccountName"))).SelectedItem.Value; string strDebit = ((TextBox)(GvContraEntry.Rows[i].Cells[2].FindControl("txtDebitAmount"))).Text; string strCredit = ((TextBox)(GvContraEntry.Rows[i].Cells[3].FindControl("txtCreditAmount"))).Text; if (strAccountID != "-1") { objJournalVoucherMBO.LedgerID = Convert.ToInt32(strAccountID); if (strDebit == "") { objJournalVoucherMBO.TransactionType = "Credit"; objJournalVoucherMBO.Amount = Convert.ToDouble(strCredit); } else { objJournalVoucherMBO.TransactionType = "Debit"; objJournalVoucherMBO.Amount = Convert.ToDouble(strDebit); } objResultInsert = objJournalVoucherMBL.JournalVoucherM_Insert(objJournalVoucherMBO); } else { break; } } insertLedgerTransaction(txtVoucherCode.Text); } ClientScript.RegisterStartupScript(typeof(Page), "MessagePopUp", "<script>alert('Contra Updated Successfully...');</script>"); } DatabaseTransaction.CommitTransation(); clear(); PanelVisibility(1); BindGrid(); } else // WHEN THE AMOUNTS DOESNOT MATCH { ClientScript.RegisterStartupScript(typeof(Page), "MessagePopUp", "<script>alert('Total amounts of Debit and Credit donot match...');</script>"); return; } } else { ClientScript.RegisterStartupScript(typeof(Page), "MessagePopUp", "<script>alert('Select Date according to your Accounting Period.');</script>"); return; } GvContraEntry.Visible = true; Exit :; } catch (Exception ex) { DatabaseTransaction.RollbackTransation(); logger.Error("Error", ex); ClientScript.RegisterStartupScript(typeof(Page), "MessagePopUp", "<script>alert('Oops! There is some technical issue. Please Contact to your administrator.');</script>"); } finally { DatabaseTransaction.connection.Close(); } }
/// <summary> /// To Update details of JournalVoucherM in tbl_JournalVoucher_M table /// Created By : Viral, 10/13/2014 /// Modified By : /// </summary> /// <param name="objJournalVoucherMBO"></param> /// <returns></returns> public ApplicationResult JournalVoucherM_Update(JournalVoucherMBO objJournalVoucherMBO, string strFromDate) { try { pSqlParameter = new SqlParameter[16]; pSqlParameter[0] = new SqlParameter("@JournalID", SqlDbType.Int); pSqlParameter[0].Direction = ParameterDirection.Input; pSqlParameter[0].Value = objJournalVoucherMBO.JournalID; pSqlParameter[1] = new SqlParameter("@TrustMID", SqlDbType.Int); pSqlParameter[1].Direction = ParameterDirection.Input; pSqlParameter[1].Value = objJournalVoucherMBO.TrustMID; pSqlParameter[2] = new SqlParameter("@SchoolMID", SqlDbType.Int); pSqlParameter[2].Direction = ParameterDirection.Input; pSqlParameter[2].Value = objJournalVoucherMBO.SchoolMID; pSqlParameter[3] = new SqlParameter("@LedgerID", SqlDbType.Int); pSqlParameter[3].Direction = ParameterDirection.Input; pSqlParameter[3].Value = objJournalVoucherMBO.LedgerID; pSqlParameter[4] = new SqlParameter("@VoucherNo", SqlDbType.Int); pSqlParameter[4].Direction = ParameterDirection.Input; pSqlParameter[4].Value = objJournalVoucherMBO.VoucherNo; pSqlParameter[5] = new SqlParameter("@VoucherCode", SqlDbType.NVarChar); pSqlParameter[5].Direction = ParameterDirection.Input; pSqlParameter[5].Value = objJournalVoucherMBO.VoucherCode; pSqlParameter[6] = new SqlParameter("@VoucherDate", SqlDbType.NVarChar); pSqlParameter[6].Direction = ParameterDirection.Input; pSqlParameter[6].Value = objJournalVoucherMBO.VoucherDate; pSqlParameter[7] = new SqlParameter("@Amount", SqlDbType.Float); pSqlParameter[7].Direction = ParameterDirection.Input; pSqlParameter[7].Value = objJournalVoucherMBO.Amount; pSqlParameter[8] = new SqlParameter("@TransactionType", SqlDbType.NVarChar); pSqlParameter[8].Direction = ParameterDirection.Input; pSqlParameter[8].Value = objJournalVoucherMBO.TransactionType; pSqlParameter[9] = new SqlParameter("@OperationType", SqlDbType.NVarChar); pSqlParameter[9].Direction = ParameterDirection.Input; pSqlParameter[9].Value = objJournalVoucherMBO.OperationType; pSqlParameter[10] = new SqlParameter("@ChequeNumber", SqlDbType.Int); pSqlParameter[10].Direction = ParameterDirection.Input; pSqlParameter[10].Value = objJournalVoucherMBO.ChequeNumber; pSqlParameter[11] = new SqlParameter("@Description", SqlDbType.NVarChar); pSqlParameter[11].Direction = ParameterDirection.Input; pSqlParameter[11].Value = objJournalVoucherMBO.Description; //pSqlParameter[12] = new SqlParameter("@CreatedDate", SqlDbType.NVarChar); //pSqlParameter[12].Direction = ParameterDirection.Input; //pSqlParameter[12].Value = objJournalVoucherMBO.CreatedDate; //pSqlParameter[13] = new SqlParameter("@CreatedBy", SqlDbType.Int); //pSqlParameter[13].Direction = ParameterDirection.Input; //pSqlParameter[13].Value = objJournalVoucherMBO.CreatedBy; //pSqlParameter[14] = new SqlParameter("@IsDeleted", SqlDbType.Int); //pSqlParameter[14].Direction = ParameterDirection.Input; //pSqlParameter[14].Value = objJournalVoucherMBO.IsDeleted; pSqlParameter[12] = new SqlParameter("@LastModifideUserID", SqlDbType.Int); pSqlParameter[12].Direction = ParameterDirection.Input; pSqlParameter[12].Value = objJournalVoucherMBO.LastModifideUserID; pSqlParameter[13] = new SqlParameter("@LastModifideDate", SqlDbType.NVarChar); pSqlParameter[13].Direction = ParameterDirection.Input; pSqlParameter[13].Value = objJournalVoucherMBO.LastModifideDate; pSqlParameter[14] = new SqlParameter("@Year", SqlDbType.Int); pSqlParameter[14].Direction = ParameterDirection.Input; pSqlParameter[14].Value = objJournalVoucherMBO.Year; pSqlParameter[15] = new SqlParameter("@FromDate", SqlDbType.VarChar); pSqlParameter[15].Direction = ParameterDirection.Input; pSqlParameter[15].Value = strFromDate; sSql = "usp_tbl_JournalVoucher_M_Update"; DataTable dtResult = new DataTable(); dtResult = DatabaseTransaction.ExecuteDataTable(CommandType.StoredProcedure, sSql, pSqlParameter); ApplicationResult objResults = new ApplicationResult(dtResult); objResults.status = ApplicationResult.CommonStatusType.SUCCESS; return(objResults); } catch (Exception ex) { throw ex; } finally { objJournalVoucherMBO = null; } }