public string InsertCloseReason(ClsCloseReason data) { string errMsg = ""; PuroTouchSQLDataContext puroTouchContext = new PuroTouchSQLDataContext(); try { tblCloseReason oNewRow = new tblCloseReason() { idCloseReason = (Int32)data.idCloseReason, CloseReason = data.CloseReason, CreatedBy = data.CreatedBy, CreatedOn = (DateTime?)data.CreatedOn, //UpdatedBy = data.UpdatedBy, //UpdatedOn = (DateTime?)data.UpdatedOn, ActiveFlag = data.ActiveFlag }; puroTouchContext.GetTable <tblCloseReason>().InsertOnSubmit(oNewRow); // Submit the changes to the database. puroTouchContext.SubmitChanges(); //newID = oNewRow.idTaskType; } catch (Exception ex) { errMsg = ex.Message.ToString(); } return(errMsg); }
private ClsCloseReason populateObj(UserControl userControl) { ClsCloseReason oCloseReason = new ClsCloseReason(); oCloseReason.CloseReason = (userControl.FindControl("txtCloseReason") as RadTextBox).Text; oCloseReason.ActiveFlag = (userControl.FindControl("ActiveFlag") as RadButton).Checked; oCloseReason.UpdatedBy = (string)(Session["userName"]); oCloseReason.UpdatedOn = Convert.ToDateTime(DateTime.Now); return(oCloseReason); }
protected void rgGrid_UpdateCommand(object sender, GridCommandEventArgs e) { try { UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID); Label errorMsg = (Label)userControl.FindControl("lblErrorMessage"); ClsCloseReason oCloseReason = populateObj(userControl); oCloseReason.idCloseReason = Convert.ToInt16((userControl.FindControl("lblCloseReasonID") as Label).Text); string updateMsg = ""; if (IsValid) { if (oCloseReason != null) { updateMsg = cr.UpdateCloseReason(oCloseReason); if (updateMsg == "") { pnlsuccess.Visible = true; lblSuccess.Text = "Successfully updated " + "'" + oCloseReason.CloseReason + "'"; } else { errorMsg.Visible = true; errorMsg.Text = updateMsg; e.Canceled = true; } } } else { // display error errorMsg.Visible = true; errorMsg.Text = "Please enter Required fields"; e.Canceled = true; } } catch (Exception ex) { pnlDanger.Visible = true; lblDanger.Text = ex.Message.ToString(); e.Canceled = true; } }
protected void rgGrid_InsertCommand(object sender, GridCommandEventArgs e) { try { UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID); Label errorMsg = (Label)userControl.FindControl("lblErrorMessage"); ClsCloseReason oCloseReason = populateObj(userControl); string insertMsg = ""; if (IsValid) { if (oCloseReason != null) { insertMsg = cr.InsertCloseReason(oCloseReason); if (insertMsg == "") { pnlsuccess.Visible = true; lblSuccess.Text = "Successfully Added New CloseReason " + oCloseReason.CloseReason; } else { errorMsg.Visible = true; errorMsg.Text = insertMsg; e.Canceled = true; } } } else { // display error errorMsg.Visible = true; errorMsg.Text = "Please enter Required fields"; e.Canceled = true; } } catch (Exception ex) { pnlDanger.Visible = true; lblDanger.Text = ex.Message.ToString(); e.Canceled = true; } }
public string UpdateCloseReason(ClsCloseReason data) { string errMsg = ""; PuroTouchSQLDataContext puroTouchContext = new PuroTouchSQLDataContext(); try { if (data.idCloseReason > 0) { // Query the database for the row to be updated. var query = from qdata in puroTouchContext.GetTable <tblCloseReason>() where qdata.idCloseReason == data.idCloseReason select qdata; // Execute the query, and change the column values // you want to change. foreach (tblCloseReason updRow in query) { updRow.CloseReason = data.CloseReason; updRow.ActiveFlag = data.ActiveFlag; updRow.idCloseReason = data.idCloseReason; updRow.UpdatedBy = data.UpdatedBy; updRow.UpdatedOn = data.UpdatedOn; } // Submit the changes to the database. puroTouchContext.SubmitChanges(); } else { errMsg = "There is No Close Reason with ID = " + "'" + data.idCloseReason + "'"; } } catch (Exception ex) { errMsg = ex.Message.ToString(); } return(errMsg); }