Ejemplo n.º 1
0
 /// <summary>
 /// Save or edit function, Checking all invalid entrys to save or edit
 /// </summary>
 public void SaveOrEditFunction()
 {
     try
     {
         txtVoucherDate.Text = txtVoucherDate.Text.Trim();
         cmbAccountLedger.Text = cmbAccountLedger.Text.Trim();
         txtAmount.Text = txtAmount.Text.Trim();
         cmbBank.Text = cmbBank.Text.Trim();
         txtCheckDate.Text = txtCheckDate.Text.Trim();
         txtcheckNo.Text = txtcheckNo.Text.Trim();
         txtNarration.Text = txtNarration.Text.Trim();
         bool isOk = true;
         bool isAmountOk = false;
         try
         {
             if (Convert.ToDecimal(txtAmount.Text) > 0)
                 isAmountOk = true;
         }
         catch
         {
             txtAmount.Text = string.Empty;
         }
         if (isOk)
         {
             if (txtVoucherNo.Text == string.Empty)
             {
                 Messages.InformationMessage("Enter voucher no");
                 txtVoucherNo.Focus();
             }
             else if (txtVoucherDate.Text == string.Empty)
             {
                 Messages.InformationMessage("Select date");
                 txtVoucherDate.Focus();
             }
             else if (cmbAccountLedger.SelectedValue == null)
             {
                 Messages.InformationMessage("Select account ledger");
                 cmbAccountLedger.Focus();
             }
             else if (!isAmountOk)
             {
                 Messages.InformationMessage("Select amount");
                 txtAmount.Focus();
             }
             else if (cmbBank.SelectedValue == null)
             {
                 Messages.InformationMessage("Select bank ");
                 cmbBank.Focus();
             }
             else if (txtcheckNo.Text == string.Empty)
             {
                 Messages.InformationMessage("Enter cheque no");
                 txtcheckNo.Focus();
             }
             else if (txtCheckDate.Text == string.Empty)
             {
                 Messages.InformationMessage("Select cheque date");
                 txtCheckDate.Focus();
             }
             else
             {
                 if (PublicVariables.isMessageAdd)
                 {
                     isOk = false;
                     PDCReceivableMasterSP spPdcreceivable = new PDCReceivableMasterSP();
                     if (!isInEditMode)
                     {
                         if (Messages.SaveMessage())
                             if (!spPdcreceivable.PDCReceivableCheckExistence(txtVoucherNo.Text.Trim(), decPDCReceivableVoucherTypeId, 0))
                             {
                                 SaveFunction();
                             }
                             else
                             {
                                 Messages.InformationMessage("Voucher number already exist");
                             }
                     }
                     else
                     {
                         if (Messages.UpdateMessage())
                             if (isInEditMode && spPdcreceivable.PDCReceivableVoucherCheckRreferenceUpdating(decPDCReceivableEditId, decPDCReceivableVoucherTypeId))
                             {
                                 MessageBox.Show("Can't update,reference exist", "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
                             }
                             else
                             {
                                 SaveFunction();
                             }
                     }
                 }
                 if (isOk)
                 {
                     if (CheckUserPrivilege.PrivilegeCheck(PublicVariables._decCurrentUserId, this.Name, btnSave.Text))
                     {
                         PDCReceivableMasterSP spPdcreceivable = new PDCReceivableMasterSP();
                         if (isInEditMode && spPdcreceivable.PDCReceivableVoucherCheckRreferenceUpdating(decPDCReceivableEditId, decPDCReceivableVoucherTypeId))
                         {
                             MessageBox.Show("Can't update,reference exist", "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
                         }
                         else
                         {
                             SaveFunction();
                         }
                     }
                     else
                     {
                         Messages.NoPrivillageMessage();
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("PR8:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }