/// <summary> /// update function /// </summary> public void EditFunction() { try { VoucherTypeBll BllVoucherType = new VoucherTypeBll(); VoucherTypeInfo infoVoucherType = new VoucherTypeInfo(); VoucherTypeTaxBll BllVoucherTypeTax = new VoucherTypeTaxBll(); VoucherTypeTaxInfo infoVoucherTypeTax = new VoucherTypeTaxInfo(); if (BllVoucherType.VoucherTypeCheckExistence(txtVoucherName.Text.Trim(), decVoucherTypeId) == false) { if (BllVoucherType.VoucherTypeChechReferences(decVoucherTypeId) == false) { infoVoucherType.VoucherTypeId = decVoucherTypeId; infoVoucherType.VoucherTypeName = txtVoucherName.Text.Trim(); infoVoucherType.TypeOfVoucher = cmbTypeOfVoucher.Text; infoVoucherType.MethodOfVoucherNumbering = cmbMethodOfvoucherNumbering.Text; infoVoucherType.Narration = txtNarration.Text.Trim(); if (cbxActive.Checked) { IsActive = true; } infoVoucherType.IsActive = IsActive; int inRowCount = dgvApplicableTaxes.RowCount; for (int i = 0; i <= inRowCount - 1; i++) { if (dgvApplicableTaxes.Rows[i].Cells["dgvcbxSelect"].Value != null && dgvApplicableTaxes.Rows[i].Cells["dgvcbxSelect"].Value.ToString() != "False") { isTax = bool.Parse(dgvApplicableTaxes.Rows[i].Cells["dgvcbxSelect"].Value.ToString()); } } infoVoucherType.IsTaxApplicable = isTax; infoVoucherType.IsDefault = false; infoVoucherType.Extra1 = string.Empty; infoVoucherType.Extra2 = string.Empty; infoVoucherType.MasterId = int.Parse(cmbDotMatrix.SelectedValue.ToString()); infoVoucherType.Declarartion = txtDeclaration.Text; infoVoucherType.Heading1 = txtHeading1.Text; infoVoucherType.Heading2 = txtHeading2.Text; infoVoucherType.Heading3 = txtHeading3.Text; infoVoucherType.Heading4 = txtHeading4.Text; if (BllVoucherType.CheckForDefaultVoucherType(decVoucherTypeId) == false) { BllVoucherType.VoucherTypeEdit(infoVoucherType); } else { BllVoucherType.VoucherTypeEditForDefaultVouchers(infoVoucherType); } //------------------------------------- Delete And Add Tax details From VoucherTypeTax Using VoucherTypeId-------------------------------// BllVoucherTypeTax.DeleteVoucherTypeTaxUsingVoucherTypeId(decVoucherTypeId); if (isTax) { for (int i = 0; i <= inRowCount - 1; i++) { if (dgvApplicableTaxes.Rows[i].Cells["dgvcbxSelect"].Value != null && dgvApplicableTaxes.Rows[i].Cells["dgvcbxSelect"].Value.ToString() != "False") { infoVoucherTypeTax.VoucherTypeId = decVoucherTypeId; infoVoucherTypeTax.TaxId = Convert.ToDecimal(dgvApplicableTaxes.Rows[i].Cells["dgvtxtTaxId"].Value.ToString()); infoVoucherTypeTax.Extra1 = string.Empty; infoVoucherTypeTax.Extra2 = string.Empty; BllVoucherTypeTax.VoucherTypeTaxAdd(infoVoucherTypeTax); } } } //-----------------------------------------------------------Deleted And Added--------------------------------------------------------// Messages.UpdatedMessage(); Clear(); } else { Messages.InformationMessage("You can't update,voucher already in use"); } } else { Messages.InformationMessage("Voucher name already exists"); } } catch (Exception ex) { MessageBox.Show("VT04:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// when cell double click for update function /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dgvVoucherType_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { try { if (e.RowIndex != -1) { isEditMode = true; btnSave.Text = "Update"; txtVoucherNameSearch.Focus(); btnDelete.Enabled = true; int inRowCount = dgvApplicableTaxes.RowCount; for (int i = 0; i < inRowCount; i++) { dgvApplicableTaxes.Rows[i].Cells["dgvcbxSelect"].Value = false; } VoucherTypeBll BllVoucherType = new VoucherTypeBll(); VoucherTypeInfo infoVoucherType = new VoucherTypeInfo(); decVoucherTypeId = Convert.ToDecimal(dgvVoucherType.CurrentRow.Cells["dgvtxtvoucherTypeId"].Value.ToString()); infoVoucherType = BllVoucherType.VoucherTypeView(decVoucherTypeId); txtVoucherName.Text = infoVoucherType.VoucherTypeName; cmbTypeOfVoucher.Text = infoVoucherType.TypeOfVoucher; cmbMethodOfvoucherNumbering.Text = infoVoucherType.MethodOfVoucherNumbering; txtNarration.Text = infoVoucherType.Narration; txtDeclaration.Text = infoVoucherType.Declarartion; cmbDotMatrix.SelectedValue = infoVoucherType.MasterId; txtHeading1.Text = infoVoucherType.Heading1; txtHeading2.Text = infoVoucherType.Heading2; txtHeading3.Text = infoVoucherType.Heading3; txtHeading4.Text = infoVoucherType.Heading4; if (infoVoucherType.IsActive) { cbxActive.Checked = true; } else { cbxActive.Checked = false; } List<DataTable> listObj = new List<DataTable>(); listObj = BllVoucherType.GetTaxIdForTaxSelection(decVoucherTypeId); foreach (DataRow dr in listObj[0].Rows) { string strTaxId = dr["taxId"].ToString(); for (int i = 0; i < inRowCount; i++) { if (dgvApplicableTaxes.Rows[i].Cells["dgvtxtTaxId"].Value.ToString() == strTaxId) { dgvApplicableTaxes.Rows[i].Cells["dgvcbxSelect"].Value = true; } } } if (BllVoucherType.CheckForDefaultVoucherType(decVoucherTypeId) == false) { txtVoucherName.Enabled = true; cmbTypeOfVoucher.Enabled = true; } else { txtVoucherName.Enabled = false; cmbTypeOfVoucher.Enabled = false; } if (cmbTypeOfVoucher.Text == "Sales Return" || cmbTypeOfVoucher.Text == "Sales Invoice" || cmbTypeOfVoucher.Text == "Purchase Return" || cmbTypeOfVoucher.Text == "Purchase Invoice") { dgvApplicableTaxes.Enabled = true; } else { dgvApplicableTaxes.Enabled = false; } } } catch (Exception ex) { MessageBox.Show("VT17:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// delete function /// </summary> public void DeleteFunction() { try { VoucherTypeTaxBll BllVoucherTypeTax = new VoucherTypeTaxBll(); VoucherTypeBll BllVoucherType = new VoucherTypeBll(); if (BllVoucherType.CheckForDefaultVoucherType(decVoucherTypeId) == false) { if (BllVoucherType.VoucherTypeChechReferences(decVoucherTypeId) == false) { BllVoucherType.VoucherTypeDelete(decVoucherTypeId); BllVoucherTypeTax.DeleteVoucherTypeTaxUsingVoucherTypeId(decVoucherTypeId); Messages.DeletedMessage(); SearchGridFill(); } else { Messages.ReferenceExistsMessage(); } } else { Messages.InformationMessage("You can't delete default voucher types"); } } catch (Exception ex) { MessageBox.Show("VT11:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }