protected void lnkAddToWorkOrderGrid_OnCommand(object sender, CommandEventArgs e) { DropDownList ddlWorkType = (fviewWork.FindControl("ddlWorkType") as DropDownList); if (ddlWorkType.SelectedIndex == 0) { // display a label about making a work type selection lblMessage.Text = "Please select a work type"; lblMessage.ForeColor = System.Drawing.Color.Red; } else { //add the work order //create a new serviceWorkToBeDone object ServiceWorkToBeDone serviceWorkTBD = new ServiceWorkToBeDone(); serviceWorkTBD.WorkType = (fviewWork.FindControl("ddlWorkType") as DropDownList).SelectedItem.Text; serviceWorkTBD.WorkCharge = double.Parse((fviewWork.FindControl("txtWorkCharge") as TextBox).Text.ToString(), CultureInfo.InvariantCulture); //100; serviceWorkTBD.WorkNotes = (fviewWork.FindControl("txtWorkNotes") as TextBox).Text.Trim(); //create the collection ServiceWorkToBeDoneList workList = new ServiceWorkToBeDoneList(); // create a session variable if (Session["workList"] == null) { workList.Add(serviceWorkTBD); Session["workList"] = workList; } else { workList = Session["workList"] as ServiceWorkToBeDoneList; workList.Add(serviceWorkTBD); } gviewWorkList.DataSource = workList; gviewWorkList.DataBind(); //reset the fields in the formview (fviewWork.FindControl("ddlWorkType") as DropDownList).SelectedIndex = 0; (fviewWork.FindControl("txtWorkCharge") as TextBox).Text = ""; (fviewWork.FindControl("txtWorkNotes") as TextBox).Text = ""; lblMessage.Text = ""; //enable the scheduler linkbutton lnkOpenScheduler.Enabled = true; } }
public static int Save(ServiceWorkToBeDone sWork) { int result; MyDBConnection myConn = new MyDBConnection(); SqlConnection conn = new SqlConnection(); try { conn = myConn.OpenDB(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "dbo.InsertUpdateServiceWorkToBeDone"; if (sWork.WorkToBeDoneID == -1) { cmd.Parameters.Add("@WorkToBeDoneID", SqlDbType.Int).Value = DBNull.Value; } else { cmd.Parameters.Add("@WorkToBeDoneID", SqlDbType.Int).Value = sWork.WorkToBeDoneID; } cmd.Parameters.Add("@WorkType", SqlDbType.VarChar).Value = sWork.WorkType; cmd.Parameters.Add("@WorkCharge", SqlDbType.Decimal).Value = sWork.WorkCharge; cmd.Parameters.Add("@WorkNotes", SqlDbType.VarChar).Value = sWork.WorkNotes; cmd.Parameters.Add("@ServiceWorkID", SqlDbType.Int).Value = sWork.ServiceWorkID; cmd.Parameters.Add("@CreatedDate", SqlDbType.DateTime).Value = sWork.CreatedDate; cmd.Parameters.Add("@ModifiedDate", SqlDbType.DateTime).Value = sWork.ModifiedDate; cmd.Parameters.Add("@CreatedBy", SqlDbType.VarChar).Value = sWork.CreatedBy; cmd.Parameters.Add("@ModifiedBy", SqlDbType.VarChar).Value = sWork.ModifiedBy; DbParameter returnValue = cmd.CreateParameter(); returnValue.Direction = ParameterDirection.ReturnValue; cmd.Parameters.Add(returnValue); cmd.ExecuteNonQuery(); result = Convert.ToInt32(returnValue.Value); cmd.Dispose(); } finally { myConn.CloseDB(conn); } return(result); }
private static ServiceWorkToBeDone FillDataRecord(IDataRecord dr) { ServiceWorkToBeDone workToBeDone = new ServiceWorkToBeDone(); workToBeDone.WorkToBeDoneID = dr.GetInt32(dr.GetOrdinal("WorkToBeDoneID")); workToBeDone.WorkType = dr.GetString(dr.GetOrdinal("WorkType")); workToBeDone.WorkCharge = Convert.ToDouble(dr.GetDecimal(dr.GetOrdinal("WorkCharge"))); workToBeDone.WorkNotes = dr.GetString(dr.GetOrdinal("WorkNotes")); workToBeDone.ServiceWorkID = dr.GetInt32(dr.GetOrdinal("ServiceWorkID")); workToBeDone.CreatedDate = dr.GetDateTime(dr.GetOrdinal("CreatedDate")); workToBeDone.ModifiedDate = dr.GetDateTime(dr.GetOrdinal("ModifiedDate")); workToBeDone.CreatedBy = dr.GetString(dr.GetOrdinal("CreatedBy")); workToBeDone.ModifiedBy = dr.GetString(dr.GetOrdinal("ModifiedBy")); return(workToBeDone); }
public static int Save(ServiceWorkToBeDone sWork) { return(ServiceWorkToBeDoneDB.Save(sWork)); }