private void btnDelete_Click(object sender, EventArgs e) { if (this.dsMain.Tables[0].Rows.Count <= 0) { return; } // Birendra : Bug-7710 on 15/12/2012 :Start: if (this.txtCatName.Text == "Primary") { MessageBox.Show("Default category won't be deleted.", this.pPApplText, MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } // Birendra : Bug-7710 on 15/12/2012 :End: int j = this.BindingContext[dsMain.Tables[0]].Position; if (MessageBox.Show("Are you sure to delete this Entry ?", this.pPApplText, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { this.pAddMode = false; this.pEditMode = false; string strSQL = ""; if (dsMain.Tables[0].Rows[j]["cost_cat_id"].ToString() != "") { DataSet dsData = new DataSet(); strSQL = "SELECT top 1 cost_cat_id FROM cost_cen_mast" + " Where cost_cat_id=" + dsMain.Tables[0].Rows[j]["cost_cat_id"].ToString(); dsData = oDataAccess.GetDataSet(strSQL, null, 20); if (dsData.Tables[0].Rows.Count > 0) { MessageBox.Show("There is one or more dependent entry !!!", this.pPApplText, MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } } string vDelString = string.Empty; vDelString = "Delete from " + _TableName + " Where Cost_cat_name='" + this.txtCatName.Text + "'"; oDataAccess.ExecuteSQLStatement(vDelString, null, 20, true); // Added By Pankaj B. on 16-02-2015 for Bug-25197 Start strSQL = "select cmastcode,dbexport from Tbl_DataExport_Mast where ctype='M' and cmastcode='cost_Cat_mast'"; dsExport = oDataAccess.GetDataSet(strSQL, null, 25); if (dsExport.Tables[0].Rows.Count != 0) { ExportTbl = dsExport.Tables[0].Rows[0]["dbexport"].ToString().Trim() + ".dbo." + _TableName; vDelString = "Delete from " + ExportTbl + " Where Cost_cat_name='" + this.txtCatName.Text + "'"; oDataAccess.ExecuteSQLStatement(vDelString, null, 20, true); } // Added By Pankaj B. on 16-02-2015 for Bug-25197 End this.dsMain.Tables[0].Rows[j].Delete(); this.dsMain.Tables[0].AcceptChanges(); ControlBind(this._TableName); ///added by satish pal for bug- dated 14/06/2013 } }
public int SaveFormData(string tableName, DataAccess_Net.clsDataAccess oDataAccess) { int id = 0; DataSet dsData = new DataSet(); StringBuilder strFieldNames = new StringBuilder(); StringBuilder strFieldValues = new StringBuilder(); string strSQL = ""; try { //strSQL = "SELECT * FROM " + tableName +" Where cost_cat_name = "+"'"+this.cmbGroup.Text +"'"; //dsData = oDataAccess.GetDataSet(strSQL, null, 20); //dsData.Tables[0].TableName = "TmpData"; // int j = this.BindingContext[dsMain.Tables[0]].Position; CurrencyManager cm = (CurrencyManager)this.BindingContext[dsMain.Tables[0]]; DataRow findRow = ((DataRowView)cm.Current).Row; int j = dsMain.Tables[0].Rows.IndexOf(findRow); //if (dsData.Tables[0].Rows.Count == 0) //{ // dsMain.Tables[0].Rows[0]["gr_cost_id"] = 9999; //} //else //{ // dsMain.Tables[0].Rows[j]["gr_cost_id"] = dsData.Tables[0].Rows[0]["cost_cat_id"]; //} //dsMain.Tables[0].AcceptChanges(); if (this.pAddMode) { oDataAccess.BeginTransaction(); strSQL = InsertStatment(tableName, null); oDataAccess.ExecuteSQLStatement(strSQL, null, 20, true); // Added By Pankaj B. on 16-02-2015 for Bug-25197 Start strSQL = "select cmastcode,dbexport from Tbl_DataExport_Mast where ctype='M' and cmastcode='cost_Cat_mast'"; dsExport = oDataAccess.GetDataSet(strSQL, null, 25); if (dsExport.Tables[0].Rows.Count != 0) { ExportTbl = dsExport.Tables[0].Rows[0]["dbexport"].ToString().Trim() + ".dbo." + tableName; strSQL = InsertStatment(ExportTbl, null); oDataAccess.ExecuteSQLStatement(strSQL, null, 20, true); } // Added By Pankaj B. on 16-02-2015 for Bug-25197 End oDataAccess.CommitTransaction(); } if (this.pEditMode) { oDataAccess.BeginTransaction(); strSQL = UpdateStatment(tableName, "cost_cat_id") + " where cost_cat_id=" + dsMain.Tables[0].Rows[j]["cost_cat_id"].ToString(); oDataAccess.ExecuteSQLStatement(strSQL, null, 20, true); // Added By Pankaj B. on 16-02-2015 for Bug-25197 Start strSQL = "select cmastcode,dbexport from Tbl_DataExport_Mast where ctype='M' and cmastcode='cost_Cat_mast'"; dsExport = oDataAccess.GetDataSet(strSQL, null, 25); if (dsExport.Tables[0].Rows.Count != 0) { ExportTbl = dsExport.Tables[0].Rows[0]["dbexport"].ToString().Trim() + ".dbo." + tableName; strSQL = UpdateStatment(ExportTbl, "cost_cat_id") + " where cost_cat_id=(select cost_cat_id from " + ExportTbl + " where cost_cat_name= '" + dsMain.Tables[0].Rows[j]["cost_cat_name"].ToString() + "')"; oDataAccess.ExecuteSQLStatement(strSQL, null, 20, true); } // Added By Pankaj B. on 16-02-2015 for Bug-25197 End oDataAccess.CommitTransaction(); } } catch (Exception ex) { // throw ex; errorhandle(ex.Message); } finally { //objParam = null; //colParams = null; //oDataAccess = null; } return(id); }