private void btnSave_Click(object sender, EventArgs e) { try { if (cmbXValue.SelectedIndex > -1 && cmbYValue.SelectedIndex > -1 && cmbZValue.SelectedIndex > -1) { if (DgvMasterSettings.Rows.Count > 0) { // Truncate Old Data SPMasterSettings objSpTrun = new SPMasterSettings(); objSpTrun.ExicuteRuntimeQuery("TRUNCATE TABLE Tbl_Wells_Details"); // Insert New Data string strXVal = cmbXValue.Text; string strYVal = cmbYValue.Text; string strZVal = cmbZValue.Text; for (int i = 0; i < DgvMasterSettings.Rows.Count; i++) { WellModel objModel = new WellModel(); WellSP objSp = new WellSP(); try { if (DgvMasterSettings.Rows[i].Cells[0].Value != null) { objModel.WellName = DgvMasterSettings.Rows[i].Cells[0].Value.ToString(); objModel.XValue = Convert.ToDecimal(DgvMasterSettings.Rows[i].Cells[strXVal].Value.ToString() != string.Empty ? DgvMasterSettings.Rows[i].Cells[strXVal].Value : 0); objModel.YValue = Convert.ToDecimal(DgvMasterSettings.Rows[i].Cells[strYVal].Value.ToString() != string.Empty ? DgvMasterSettings.Rows[i].Cells[strYVal].Value : 0); objModel.ZValue = Convert.ToDecimal(DgvMasterSettings.Rows[i].Cells[strZVal].Value.ToString() != string.Empty ? DgvMasterSettings.Rows[i].Cells[strZVal].Value : 0); objSp.WellsInsertUpdate(objModel); } } catch (Exception exe) { MessageBox.Show("Well Details Insert Error at: " + objModel.WellName, "EPMS", MessageBoxButtons.OK, MessageBoxIcon.Error); } } MessageBox.Show("All Data Saved to database Successfully..!", "EPMS", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Load the data first", "EPMS", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("X Y Z Values mandatory. Please select it first", "EPMS", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show(ex.Message, "EPMS", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void WellsInsertUpdate(WellModel objModel) { try { using (SqlConnection objConn = new SqlConnection(ConnectionString)) { objConn.Open(); SqlCommand objCmd = new SqlCommand("WellDetailsInsUpDel", objConn); objCmd.CommandType = CommandType.StoredProcedure; objCmd.Parameters.AddWithValue("@Well_Name", objModel.WellName); objCmd.Parameters.AddWithValue("@X_Val", objModel.XValue); objCmd.Parameters.AddWithValue("@Y_Val", objModel.YValue); objCmd.Parameters.AddWithValue("@Z_Val", objModel.ZValue); objCmd.ExecuteNonQuery(); objConn.Close(); } } catch (Exception ex) { MessageBox.Show("WellsInsertUpdate: " + ex.ToString()); } }