private void DataGridHeaderDetails_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         if (DataGridHeaderDetails.Rows.Count > 0)
         {
             int RowIndex = DataGridHeaderDetails.CurrentCell.RowIndex;
             SalesId = Convert.ToInt32(DataGridHeaderDetails.Rows[RowIndex].Cells[0].Value.ToString());
             int    ColumnIndex = DataGridHeaderDetails.CurrentCell.ColumnIndex;
             string text        = DataGridHeaderDetails.Columns[ColumnIndex].HeaderText;
             if (text.Equals("Edit"))
             {
                 if (SalesId != 0)
                 {
                     new Sales(SalesId).ShowDialog();
                 }
                 else
                 {
                     messageShow.singlemsgtext("Only invoice number search allowed to edit");
                 }
             }
             else if (text.Equals("Delete"))
             {
                 string result = messageShow.show("Delete!", "Do you want to delete the bill permanently?");
                 if (result == "1")
                 {
                     var SalesDetails = new DomainModel.Transactions.SalesDetails
                     {
                         SalesId          = Convert.ToInt32(DataGridHeaderDetails.Rows[DataGridHeaderDetails.CurrentCell.RowIndex].Cells["sales_id"].Value.ToString()),
                         CustomerName     = "",
                         CustomerMobileNo = 0,
                         GrossAmount      = 0,
                         DiscountPer      = 0,
                         DiscountAmount   = 0,
                         NetAmount        = 0,
                         PaymentType      = 1,
                         PaidAmount       = 0,
                         DuesAmount       = 0,
                         DtSalesDetails   = null,
                         OperationType    = 3
                     };
                     long DeletedId = _SalesRepository.InsertUpdateSalesDetails(SalesDetails);
                     if (DeletedId > 0)
                     {
                         messageShow.singlemsgtext("Successfully deleted the bill.");
                         GetBrandList(0, DropDownBrandName.Text.ToString(), 3);
                         OperationType = 1;
                         GetDataGridDetails();
                     }
                     else
                     {
                         messageShow.singlemsgtext("Error occured while deleting the bill.");
                     }
                 }
                 else
                 {
                     return;
                 }
             }
             else
             {
                 if (BrandCode != 0)
                 {
                     LblInvoiceNo.Text = "Brand Code : " + BrandCode.ToString();
                 }
                 else
                 {
                     LblInvoiceNo.Text = "Invoice Number : " + DataGridHeaderDetails.Rows[RowIndex].Cells[2].Value.ToString();
                 }
                 OperationType = 3;
                 GetDataGridDetails();
             }
         }
     }
     catch (Exception _exception)
     {
         CmC.InsertException(_exception);
         messageShow.singlemsgtext(CmC.ExceptionErrorMessage);
     }
 }
 private void DataGridHeaderDetails_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         if (DataGridHeaderDetails.Rows.Count > 0)
         {
             int RowIndex = DataGridHeaderDetails.CurrentCell.RowIndex;
             PurchaseId = Convert.ToInt32(DataGridHeaderDetails.Rows[RowIndex].Cells[0].Value.ToString());
             int    ColumnIndex = DataGridHeaderDetails.CurrentCell.ColumnIndex;
             string text        = DataGridHeaderDetails.Columns[ColumnIndex].HeaderText;
             if (text.Equals("Delete"))
             {
                 string result = messageShow.show("Delete!", "Do you want to delete the purchased item(s) permanently?");
                 if (result == "1")
                 {
                     var purchase_details = new DomainModel.Transactions.PurchaseDetails
                     {
                         PurchaseId        = PurchaseId,
                         PurchaseInvoiceNo = "",
                         SupplierCode      = 0,
                         NetAmount         = 0,
                         PaymentType       = 0,
                         PaidAmount        = 0,
                         DuesAmount        = 0,
                         DtPurchaseDetails = null,
                         OperationType     = 3
                     };
                     int id = _purchaseRepository.InsertUpdatePurchaseDetails(purchase_details);
                     if (id > 0)
                     {
                         messageShow.singlemsgtext("Sccessfully deleted the purchase item.");
                         GetBrandList(0, DropDownBrandName.Text.ToString(), 3);
                         OperationType = 1;
                         GetDataGridDetails();
                     }
                     else if (id == -1)
                     {
                         messageShow.singlemsgtext("This purchased items already sold, so you can't delete this item(s).");
                     }
                     else
                     {
                         messageShow.singlemsgtext("Error occured while deleting the bill.");
                     }
                 }
                 else
                 {
                     return;
                 }
             }
             if (BrandCode != 0)
             {
                 LblInvoiceNo.Text = "Brand Code : " + BrandCode.ToString();
             }
             else
             {
                 LblInvoiceNo.Text = "Invoice Number : " + DataGridHeaderDetails.Rows[RowIndex].Cells[2].Value.ToString();
             }
             OperationType = 3;
             GetDataGridDetails();
         }
     }
     catch (Exception _exception)
     {
         CmC.InsertException(_exception);
         messageShow.singlemsgtext(CmC.ExceptionErrorMessage);
     }
 }