private void btnInsert_Click(object sender, EventArgs e)
 {
     bool valueIsValid = true;
     if (CLSValidityCheck.IsInt(txtInstalmentBalance))
     {
         if (int.Parse(txtInstalmentBalance.Text) <= 0) valueIsValid = false;
     }
     else valueIsValid = false;
     if (valueIsValid)
     {
         double newInstalment = double.Parse(txtInstalmentBalance.Text);
         if (newInstalment <= remainBalance)
         {
             bool termExistsInTable = false;
             DataRow drCurrentTerm = null;
             foreach (DataRow dr in dtInstalment.Rows)
             {
                 if (dr["Pay_Term_No"].ToString() == numTermNo.Value.ToString())
                 {
                     termExistsInTable = true;
                     drCurrentTerm = dr;
                 }
             }
             if (termExistsInTable)
             {
                 if (MessageBox.Show("مبلغ " + drCurrentTerm["Balance"].ToString() + " برای این دوره ثبت گردیده است. مبلغ جدید به مبلغ قبلی اضافه شود؟", "", MessageBoxButtons.YesNo) == DialogResult.Yes)
                 {
                     drCurrentTerm["Balance"] = double.Parse(drCurrentTerm["Balance"].ToString()) + newInstalment;
                     CalcFormBalances();
                 }
             }
             else
             {
                 DataRow drNew = dtInstalment.Rows.Add();
                 drNew["Bill_Term_No"] = termNo;
                 drNew["Pay_Term_No"] = (int)numTermNo.Value;
                 drNew["Cntr_No"] = int.Parse(cntrNo);
                 drNew["Balance"] = newInstalment;
                 drNew["cmdDelete"] = "حذف";
                 instalmentSum += newInstalment;
                 lblInstalmentSum.Text = instalmentSum.ToString();
                 remainBalance = billBalance - instalmentSum;
                 lblRemainBalance.Text = remainBalance.ToString();
                 txtInstalmentBalance.Text = remainBalance.ToString();
                 numTermNo.Value++;
             }
         }
         else
         {
             MessageBox.Show("مقدار وارد شده از مبلغ باقیمانده قبض بیشتر است.");
         }
     }
     else MessageBox.Show("مقدار وارد شده معتبر نیست.");
     txtInstalmentBalance.Focus();
     txtInstalmentBalance.SelectAll();
 }
Esempio n. 2
0
 private bool InsertUpdateAction()
 {
     if (CLSValidityCheck.IsInt(txtPayBalance) && CLSValidityCheck.IsDate(mskPayDate))
     {
         string query = "";
         if (modeIsUpdate)
         {
             query += "update tbl_payment set ";
             query += "Pay_Balance =" + txtPayBalance.Text.Trim() + ",";
             query += "Pay_Date = '" + (mskPayDate.Text.Trim()) + "'";
             query += " where Cust_No = " + cmbCust.Text + " and Pay_Date = '" + original_Pay_Date + "' and Pay_Balance = " + original_Pay_Balance;
         }
         else
         {
             string Cntr_No = "";
             try
             {
                 Cntr_No = dataAccess.GetAccessDataSetByQuery("select Cntr_No from tbl_Cust where cust_No = " +
                                                              cmbCust.Text).Tables[0].Rows[0]["Cntr_No"].ToString();
             }
             catch
             {
                 MessageBox.Show("مشتری با این شماره وجود ندارد", "", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign);
                 return(false);
             }
             query += "insert into tbl_payment (cust_No,cntr_No,Pay_Date,Pay_Balance)";
             query += " values (" + cmbCust.Text.Trim() +
                      "," + Cntr_No +
                      ",'" + mskPayDate.Text.Trim() +
                      "'," + txtPayBalance.Text +
                      ")";
         }
         dataAccess.ExecuteAccess(query);
         if (!modeIsUpdate)
         {
             if (cmbCust.SelectedIndex < dtCust.Rows.Count - 1)
             {
                 cmbCust.SelectedIndex++;
             }
             if (mskPayDate.Enabled)
             {
                 mskPayDate.Select();
                 mskPayDate.SelectAll();
             }
             else
             {
                 txtPayBalance.Select();
                 txtPayBalance.SelectAll();
             }
         }
         else
         {
             DialogResult = DialogResult.OK;
             //Close();
         }
     }
     else
     {
         MessageBox.Show("لطفاً مقادیر وارد شده را تصحیح نمایید");
         return(false);
     }
     return(true);
 }
Esempio n. 3
0
 private void txtPayBalance_Leave(object sender, EventArgs e)
 {
     CLSValidityCheck.IsInt(txtPayBalance);
 }