Esempio n. 1
0
 private void dgv_CellValueChanged(object sender, DataGridViewCellEventArgs e)
 {
     if (e.ColumnIndex != -1 && e.RowIndex != -1)
     {
         if (dgv.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null)
         {
             if (e.ColumnIndex == 1)
             {
                 if (dgv.Rows[currentRowIndex].Cells["AccountTypeName"].Value.ToString() == "")
                 {
                     string accountNumber;
                     GeneralFunctions.AccountNumberValidate(dgv.Rows[currentRowIndex].Cells["AccountNumber"].Value.ToString(), out accountNumber);
                     DataRow[] rArr = dbAccountingProjectDS.GLAccounts.Select("AccountNumber = '" + accountNumber + "'");
                     if (rArr.Length != 0)
                     {
                         dgv.Rows[currentRowIndex].Cells["AccountTypeName"].Value = rArr[0]["AccountTypeName"].ToString();
                     }
                     else
                     {
                         MessageBox.Show("The given account number doesnt exist\n Please Enter another account or Choose an existing account");
                     }
                 }
                 if (dgv.Rows[currentRowIndex].Cells["AccountTypeName"].Value.ToString().ToLower() != "header" &&
                     dgv.Rows[currentRowIndex].Cells["AccountTypeName"].Value.ToString().ToLower() != "statistical" &&
                     dgv.Rows[currentRowIndex].Cells["AccountTypeName"].Value.ToString().ToLower() != "")
                 {
                     dgv.Rows[currentRowIndex].Cells["Debit"].Value  = value;
                     dgv.Rows[currentRowIndex].Cells["Credit"].Value = value;
                     dgv.Rows[currentRowIndex].Cells["Units"].Value  = 0;
                 }
                 if (currentRowIndex == dtTemplateAccounts.Rows.Count - 1)
                 {
                     DataRow r = dtTemplateAccounts.NewRow();
                     dtTemplateAccounts.Rows.Add(r);
                 }
             }
             if (e.ColumnIndex == 5)
             {
                 CalculateBalance();
                 if (checkBox_Currency.Checked && cb_Currency.Text != "")
                 {
                     double amount = double.Parse(dgv.Rows[currentRowIndex].Cells["Debit"].Value.ToString());
                     dgv.Rows[currentRowIndex].Cells["DebitCC"].Value = GeneralFunctions.CalculateForiegnCurrencyValue(amount, double.Parse(txt_CurrencyRate.Text));
                 }
                 else if (checkBox_Currency.Checked && cb_Currency.Text == "")
                 {
                     dgv.Rows[currentRowIndex].Cells["Debit"].Value = "";
                     MessageBox.Show("Please Specify the foreign currency", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
             }
             if (e.ColumnIndex == 6)
             {
                 CalculateBalance();
                 if (checkBox_Currency.Checked && cb_Currency.Text != "")
                 {
                     double amount = double.Parse(dgv.Rows[currentRowIndex].Cells["Credit"].Value.ToString());
                     dgv.Rows[currentRowIndex].Cells["CreditCC"].Value = GeneralFunctions.CalculateForiegnCurrencyValue(amount, double.Parse(txt_CurrencyRate.Text));
                 }
                 else if (checkBox_Currency.Checked && cb_Currency.Text == "")
                 {
                     dgv.Rows[currentRowIndex].Cells["Credit"].Value = "";
                     MessageBox.Show("Please Specify the foreign currency", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
             }
             if (e.ColumnIndex == 7)
             {
                 CalculateUnitsCount();
             }
         }
     }
 }