private bool CheckBalanceAccType() { bool flage = false; int BS = 0; int PL = 0; DataRow[] rArr; ValBS = 0; ValPT = 0; double total = 0; double Valuesource = 0; double value = 0; DataRow r; string prdbalance = ""; string s = string.Format(GeneralFunctions.Format_Date, DateTime.Now); prdbalance = FindPeriod(s); for (int i = 0; i < dtSourceAccounts.Rows.Count; i++) { r = dtSourceAccounts.Rows[i]; if (r.Equals(dtSourceAccounts.Rows[dtSourceAccounts.Rows.Count - 1]) && r["AllocationSourceAccount"].ToString() == "" && r["AllocationSourceAccountName"].ToString() == "") { break; } if (r.RowState == DataRowState.Added || r.RowState == DataRowState.Modified) { rArr = this.dbAccountingProjectDS.GLAccounts.Select("AccountNumber ='" + dtSourceAccounts.Rows[i]["AllocationSourceAccount"].ToString() + "'"); Valuesource = CurrentBalanceAccount(prdbalance, dtSourceAccounts.Rows[i]["AllocationSourceAccount"].ToString(), DateTime.Now.Date); value = (Valuesource / 100) * (double)dtSourceAccounts.Rows[i]["AllocationSourceAccountPercentage"]; value = GeneralFunctions.ChangeDecimal(value, decmal); string sdf = string.Format("{*,**}", value); if (rArr[0]["AccountTypeName"].ToString() == "Assets" || rArr[0]["AccountTypeName"].ToString() == "Liability" || rArr[0]["AccountTypeName"].ToString() == "Equity") { BS++; ValBS = ValBS - value; } else if (rArr[0]["AccountTypeName"].ToString() == "Revenue" || rArr[0]["AccountTypeName"].ToString() == "Expenses") { PL++; ValPT = ValPT - value; } total = total + value; } } for (int i = 0; i < dtDestinationAccounts.Rows.Count; i++) { value = 0; r = dtDestinationAccounts.Rows[i]; if (r.Equals(dtDestinationAccounts.Rows[dtDestinationAccounts.Rows.Count - 1]) && r["DestinationGLAccountNumber"].ToString() == "" && r["DestinationAccountDescription"].ToString() == "") { break; } if (r.RowState == DataRowState.Added || r.RowState == DataRowState.Modified) { rArr = this.dbAccountingProjectDS.GLAccounts.Select("AccountNumber ='" + dtDestinationAccounts.Rows[i]["DestinationGLAccountNumber"].ToString() + "'"); value = (total / 100) * double.Parse(dtDestinationAccounts.Rows[i]["DestinationAccountPercentage"].ToString()); value = GeneralFunctions.ChangeDecimal(value, decmal); if (rArr[0]["AccountTypeName"].ToString() == "Assets" || rArr[0]["AccountTypeName"].ToString() == "Liability" || rArr[0]["AccountTypeName"].ToString() == "Equity") { BS++; ValBS = ValBS + value; } else if (rArr[0]["AccountTypeName"].ToString() == "Revenue" || rArr[0]["AccountTypeName"].ToString() == "Expenses") { PL++; ValPT = ValPT + value; } } } if (BS > 0 && PL > 0) { flage = true; } else { flage = false; ValPT = 0; ValBS = 0; } return(flage); }
private void btnrun_Click(object sender, EventArgs e) { try { string msg = GeneralFunctions.CheckLockTables("GLTotals", "", "", "Edit"); if (msg != "") { MessageBox.Show("Can't Run Because GLTotals Edit By " + msg, "Stop", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } GeneralFunctions.LockTables("GLTotals", "Allocation Run", "", "Edit"); if (checkvaluePercentage() == false && chkpost.Checked == true) { MessageBox.Show("Can't Run Allocation In Status Posted Because Percentage Source Value = 0 ", "General Ledger"); return; } double value = 0; string prdbalance = ""; string s = string.Format(GeneralFunctions.Format_Date, DateTime.Now); prdbalance = FindPeriod(s); currentJVNumber = GeneralFunctions.CreateJVNumberFormat(GeneralFunctions.lblJV, GeneralFunctions.JVNumberFormat, true); if (GeneralFunctions.RetrievePeriod(string.Format(GeneralFunctions.Format_Date, DateTime.Now), out currentPeriodID, out periodName, out currentEndDate)) { } else { MessageBox.Show("The period has been defined", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (dgvallocation.CurrentRow.Cells["Repeat"].Value.ToString() == "0") { DataRow[] drc = dbAccountingProjectDS.Batch.Select("AllocationCode = '" + dgvallocation.CurrentRow.Cells["Code"].Value.ToString() + "' AND BatchPRD = '" + periodName + "'"); if (drc.Length != 0) { MessageBox.Show("Can't Run This Allocation In This Period Again", "General Ledger"); return; } } SqlConnection sqlconBatch = new SqlConnection(GeneralFunctions.ConnectionString); sqlconBatch.Open(); SqlCommand getBatch = new SqlCommand("Select Max(BatchNo)+1 From Batch", sqlconBatch); if (getBatch.ExecuteScalar() != DBNull.Value) { NewNumber = Convert.ToInt32(getBatch.ExecuteScalar()); } else { NewNumber = 1; } sqlconBatch.Close(); msg = "new"; while (msg != "") { msg = GeneralFunctions.CheckLockTables("Batch", "", NewNumber.ToString(), "New"); if (msg != "") { NewNumber = NewNumber + 1; } } GeneralFunctions.LockTables("Batch", "Allocation Run", NewNumber.ToString(), "New"); sqlconBatch.Open(); SqlCommand cmdBatchSelect = new SqlCommand("Select BatchNo From Batch Where BatchNo=" + NewNumber + "", sqlconBatch); SqlDataReader drBatch = cmdBatchSelect.ExecuteReader(); if (!drBatch.HasRows && !GeneralFunctions.FindRow("BatchNo=" + NewNumber + "", dbAccountingProjectDS.Batch)) { DataRow rBatch = this.dbAccountingProjectDS.Batch.NewRow(); rBatch["BatchNo"] = NewNumber; rBatch["JVNumber"] = currentJVNumber; rBatch["BatchDate"] = DateTime.Now.Date; //string.Format(GeneralFunctions.Format_Date, DTP_JVDate.Value.Date); rBatch["BatchPRD"] = periodName; rBatch["BatchDSC"] = dgvallocation.CurrentRow.Cells["Description"].Value.ToString(); rBatch["BatchSRC"] = "GL"; rBatch["BatchJNL"] = dgvallocation.CurrentRow.Cells["Journal"].Value.ToString(); if (chkpost.Checked == true) { rBatch["BatchStat"] = "P"; } else if (chkpost.Checked == false) { rBatch["BatchStat"] = "U"; } rBatch["PostDate"] = DateTime.Now.Date; rBatch["UserID"] = AaDeclrationClass.xUserCode.ToString(); rBatch["REVBatch"] = 0; rBatch["REVBatchNo"] = 0; rBatch["REVBatchPRD"] = ""; rBatch["AllocationCode"] = dgvallocation.CurrentRow.Cells[0].Value.ToString(); rBatch["PropertyCode"] = ""; rBatch["Tran_Cashier"] = false; dbAccountingProjectDS.Batch.Rows.Add(rBatch); drBatch.Close(); sqlconBatch.Close(); SqlConnection sqlTransactions = new SqlConnection(GeneralFunctions.ConnectionString); sqlTransactions.Open(); double totalsource = 0; int sort = 1; if (chkpost.Checked == true) { if (CheckBalanceAccType() != false) { AddAccountsForBS_PL(NewNumber, prdbalance); } } for (int i = 0; i < dtSourceAccounts.Rows.Count; i++) { r = dtSourceAccounts.Rows[i]; if (r.Equals(dtSourceAccounts.Rows[dtSourceAccounts.Rows.Count - 1]) && r["AllocationSourceAccount"].ToString() == "" && r["AllocationSourceAccountName"].ToString() == "") { break; } if (r.RowState == DataRowState.Added || r.RowState == DataRowState.Modified) { Valuesource = CurrentBalanceAccount(prdbalance, dtSourceAccounts.Rows[i]["AllocationSourceAccount"].ToString(), DateTime.Now.Date); value = (Valuesource / 100) * (double)dtSourceAccounts.Rows[i]["AllocationSourceAccountPercentage"]; value = GeneralFunctions.ChangeDecimal(value, decmal); value = -1 * value; r = this.dbAccountingProjectDS.GLTransactions.NewRow(); SqlCommand commadTransactions = new SqlCommand("Select MAX(TransNO)+1 From GLTransactions", sqlTransactions); if (commadTransactions.ExecuteScalar() != DBNull.Value) { r["TransNO"] = Convert.ToUInt32(commadTransactions.ExecuteScalar()); } else { r["TransNO"] = 1; } r["BatchNo"] = NewNumber; r["GLAccount"] = dtSourceAccounts.Rows[i]["AllocationSourceAccount"].ToString(); //txt_JVNumber.Text; r["TRANSREF"] = ""; r["TRANSDATE"] = DateTime.Now.Date; r["AmountLC"] = value; r["Amount"] = 0; r["TRANSUnit"] = 0; r["CurrencyType"] = ""; r["Rate"] = "0"; r["ProjectCode"] = ""; r["SortNO"] = sort; sort++; dbAccountingProjectDS.GLTransactions.Rows.Add(r); if (chkpost.Checked == true) { ModifyTotals(prdbalance, dtSourceAccounts.Rows[i]["AllocationSourceAccount"].ToString(), value, DateTime.Now.Date); } updatetable();//adaptertbGLTotals.Update(dbAccountingProjectDS.GLTotals); dbAccountingProjectDS.AcceptChanges(); value = -1 * value; totalsource = totalsource + value; Valuesource = 0; value = 0; } } for (int i = 0; i < dtDestinationAccounts.Rows.Count; i++) { r = dtDestinationAccounts.Rows[i]; if (r.Equals(dtDestinationAccounts.Rows[dtDestinationAccounts.Rows.Count - 1]) && r["DestinationGLAccountNumber"].ToString() == "" && r["DestinationAccountDescription"].ToString() == "") { break; } if (r.RowState == DataRowState.Added || r.RowState == DataRowState.Modified) { value = (totalsource / 100) * double.Parse(dtDestinationAccounts.Rows[i]["DestinationAccountPercentage"].ToString()); value = GeneralFunctions.ChangeDecimal(value, decmal); r = this.dbAccountingProjectDS.GLTransactions.NewRow(); SqlCommand commadTransactions = new SqlCommand("Select MAX(TransNO)+1 From GLTransactions", sqlTransactions); if (commadTransactions.ExecuteScalar() != DBNull.Value) { r["TransNO"] = Convert.ToUInt32(commadTransactions.ExecuteScalar()); } else { r["TransNO"] = 1; } r["BatchNo"] = NewNumber; r["GLAccount"] = dtDestinationAccounts.Rows[i]["DestinationGLAccountNumber"].ToString(); //txt_JVNumber.Text; r["TRANSREF"] = ""; r["TRANSDATE"] = DateTime.Now.Date; r["AmountLC"] = value; r["Amount"] = 0; r["TRANSUnit"] = 0; r["CurrencyType"] = ""; r["Rate"] = "0"; r["ProjectCode"] = ""; r["SortNO"] = sort; sort++; dbAccountingProjectDS.GLTransactions.Rows.Add(r); if (chkpost.Checked == true) { ModifyTotals(prdbalance, dtDestinationAccounts.Rows[i]["DestinationGLAccountNumber"].ToString(), value, DateTime.Now.Date); } updatetable();//adaptertbGLTotals.Update(dbAccountingProjectDS.GLTotals); dbAccountingProjectDS.AcceptChanges(); value = 0; } } totalsource = 0; updatetable(); sqlTransactions.Close(); MessageBox.Show("JV Transaction Record inserted successfully"); lbllastran.Text = "Last Run in " + string.Format(GeneralFunctions.Format_Date, DateTime.Now.Date); } } catch (Exception ex) { MessageBox.Show(ex.Message, "General Ledger"); } finally { GeneralFunctions.UnLockTable("", "Allocation Run", "", "New"); GeneralFunctions.UnLockTable("", "Allocation Run", "", "Edit"); } }