protected void lnkConfirmServiceDateTime_OnCommand(object sender, CommandEventArgs e) { actualServiceDate = lblSelectedServiceDate.Text; STG_ServiceWork newSTG_ServiceWork = null; if (Session["stg_servWork"] == null) { //create a new service work appointment newSTG_ServiceWork = new STG_ServiceWork(); newSTG_ServiceWork.AccountID = Convert.ToInt32(lblAccountNumber.Text); newSTG_ServiceWork.ServiceDate = Convert.ToDateTime(actualServiceDate); newSTG_ServiceWork.ServiceStartTime = Convert.ToDateTime(ddlServiceStartTime.SelectedValue.ToString()); newSTG_ServiceWork.ServiceEndTime = Convert.ToDateTime(ddlServiceEndTime.SelectedValue.ToString()); newSTG_ServiceWork.Technician = "admin"; //default // create the session here Session["stg_servWork"] = newSTG_ServiceWork; } else { newSTG_ServiceWork = Session["stg_servWork"] as STG_ServiceWork; newSTG_ServiceWork.ServiceDate = Convert.ToDateTime(actualServiceDate); newSTG_ServiceWork.ServiceStartTime = Convert.ToDateTime(ddlServiceStartTime.SelectedValue.ToString()); newSTG_ServiceWork.ServiceEndTime = Convert.ToDateTime(ddlServiceEndTime.SelectedValue.ToString()); newSTG_ServiceWork.Technician = "admin"; //default } SaveSTG_ServiceWork(newSTG_ServiceWork); }
private void PopulateGridviewSchedule(DateTime myDate) { List <string> workHoursList = WorkHourDB.GetWorkHoursList(); List <DateTime> daysList; //contains the list of dates starting from sunday that fall within the week relative to the myDate variable DateTimeFormatInfo dtfi; DisplayGridviewHeader(myDate, out daysList, out dtfi); int cellNumberToUse = 0; foreach (DateTime d in daysList) { cellNumberToUse = GetTheCellNumberToUse(cellNumberToUse, d); // Prevent the user from scheduling previous days // disable linkbuttons where the date is < todays date if (d < DateTime.Now.ToLocalTime().AddDays(-1)) { foreach (GridViewRow row in gviewSchedule.Rows) { row.Cells[cellNumberToUse].Text = "-"; } } // get all appointments that fall on this day // STG_ServiceWorkList stg_servWorkList = STG_ServiceWorkManager.GetListByDate(d.Date); ServiceWorkList existingServiceWorkList = ServiceWorkManager.GetListByDate(d.Date); if (existingServiceWorkList != null) { foreach (ServiceWork s in existingServiceWorkList) { // find the start time of this service work string myStartTime = s.ServiceStartTime.ToShortTimeString(); int index = workHoursList.IndexOf(myStartTime.Replace(" ", "")); // determine how long the appointment is, i.e from 10:00AM to 11:00AM and then // calculate the number of 30 minute interval from that range. int myInterval = STG_ServiceWork.CalculateNumberOfIntervals(s.ServiceStartTime, s.ServiceEndTime); if (index != -1) { //found a match for (int i = index; i < (myInterval + index); i++) { gviewSchedule.Rows[i].Cells[cellNumberToUse].Text = "Service Work ID: " + s.ServiceWorkID.ToString(); gviewSchedule.Rows[i].Cells[cellNumberToUse].ToolTip = "Service Work ID: " + s.ServiceWorkID.ToString(); } } } } } // Display the reference date in the textbox txtRefDate.Text = myDate.ToString("d", dtfi); }
protected void lnkCompleteOrder_OnCommand(object sender, CommandEventArgs e) { STG_ServiceWork stg_servWork = Session["stg_servWork"] as STG_ServiceWork; ServiceWorkToBeDoneList workList = Session["workList"] as ServiceWorkToBeDoneList; // create an invoice Invoice newInvoice = new Invoice(); newInvoice.AccountID = Convert.ToInt32(lblAccountNumber.Text); newInvoice.InvoiceDate = DateTime.Now.ToLocalTime(); newInvoice.CreatedBy = User.Identity.Name.ToString(); //add service work subtotal + invoicelineitems subtotal double totalServiceWorkCharge = ServiceWork.CalculateTotalWorkCharge(workList); double totalServiceWorkChargeTax = ServiceWork.CalculateTotalTax(totalServiceWorkCharge, taxPercentage); newInvoice.SubTotal = totalServiceWorkCharge; //add service work tax + invoicelineitem tax newInvoice.TotalTaxCharged = totalServiceWorkChargeTax; // newInvoice.TotalAmount = (totalServiceWorkCharge + totalServiceWorkChargeTax); newInvoice.InvoiceID = InvoiceManager.Save(newInvoice); // save service work using stg_service work and invoice ID from invoice ServiceWork sWork = new ServiceWork(); sWork.AccountID = stg_servWork.AccountID; sWork.ServiceDate = stg_servWork.ServiceDate; sWork.ServiceStartTime = stg_servWork.ServiceStartTime; sWork.ServiceEndTime = stg_servWork.ServiceEndTime; //sWork.ServiceStatus = stg_servWork.ServiceStatus; sWork.Technician = ddlTechnician.SelectedValue.ToString(); sWork.InvoiceID = newInvoice.InvoiceID; sWork.SubTotal = totalServiceWorkCharge; sWork.TaxCharged = totalServiceWorkChargeTax; sWork.ServiceWorkID = ServiceWorkManager.Save(sWork); // save service work to be done using service work ID foreach (ServiceWorkToBeDone sWorkToBeDone in workList) { sWorkToBeDone.ServiceWorkID = sWork.ServiceWorkID; //save each work to be done in the DB sWorkToBeDone.WorkToBeDoneID = ServiceWorkToBeDoneManager.Save(sWorkToBeDone); } //clear the session variables PerformSessionCleanup(); }
private static STG_ServiceWork FillDataRecord(IDataRecord dr) { STG_ServiceWork stg_servWork = new STG_ServiceWork(); stg_servWork.STG_servID = dr.GetInt32(dr.GetOrdinal("STG_ServID")); stg_servWork.AccountID = dr.GetInt32(dr.GetOrdinal("AccountID")); stg_servWork.ServiceStatus = dr.GetString(dr.GetOrdinal("ServiceStatus")); stg_servWork.ServiceDate = dr.GetDateTime(dr.GetOrdinal("ServiceDate")); //use dr.getvalue stg_servWork.ServiceStartTime = Convert.ToDateTime(dr.GetValue(dr.GetOrdinal("ServiceStartTime")).ToString()); // dr.GetValue(dr.GetOrdinal("ServiceStartTime")) ;//dr.GetDateTime(dr.GetOrdinal("ServiceStartTime")).ToShortTimeString(); stg_servWork.ServiceEndTime = Convert.ToDateTime(dr.GetValue(dr.GetOrdinal("ServiceEndTime")).ToString()); //Convert.ToDateTime( dr.GetValue(dr.GetOrdinal("ServiceEndTime")).ToString()).ToShortTimeString().Replace(" ","");//dr.GetDateTime(dr.GetOrdinal("ServiceEndTime")).ToShortTimeString() ; stg_servWork.Technician = dr.GetString(dr.GetOrdinal("Technician")); return(stg_servWork); }
public static int Save(STG_ServiceWork stg_servWork) { 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.[InsertUpdateSTG_serviceWork]"; if (stg_servWork.STG_servID == -1) { cmd.Parameters.Add("@STG_servID", SqlDbType.Int).Value = DBNull.Value; } else { cmd.Parameters.Add("@STG_servID", SqlDbType.Int).Value = stg_servWork.STG_servID; } cmd.Parameters.Add("@AccountID", SqlDbType.Int).Value = stg_servWork.AccountID; cmd.Parameters.Add("@ServiceStatus", SqlDbType.VarChar).Value = stg_servWork.ServiceStatus; cmd.Parameters.Add("@ServiceDate", SqlDbType.DateTime).Value = stg_servWork.ServiceDate; cmd.Parameters.Add("@ServiceStartTime", SqlDbType.Time).Value = new TimeSpan(stg_servWork.ServiceStartTime.Hour, stg_servWork.ServiceStartTime.Minute, 0); cmd.Parameters.Add("@ServiceEndTime", SqlDbType.Time).Value = new TimeSpan(stg_servWork.ServiceEndTime.Hour, stg_servWork.ServiceEndTime.Minute, 0); cmd.Parameters.Add("@Technician", SqlDbType.VarChar).Value = stg_servWork.Technician; cmd.Parameters.Add("@CreatedDate", SqlDbType.DateTime).Value = stg_servWork.CreatedDate; cmd.Parameters.Add("@ModifiedDate", SqlDbType.DateTime).Value = stg_servWork.ModifiedDate; cmd.Parameters.Add("@CreatedBy", SqlDbType.VarChar).Value = stg_servWork.CreatedBy; cmd.Parameters.Add("@ModifiedBy", SqlDbType.VarChar).Value = stg_servWork.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 void SaveSTG_ServiceWork(STG_ServiceWork stg_servWork) { // // Before saving, check for conflicts with existing service works based on service date // // Retrieve existing service works for a specific date ServiceWorkList existingServiceWorkList = ServiceWorkManager.GetListByDate(Convert.ToDateTime(actualServiceDate), ddlServiceStartTime.SelectedValue.ToString()); bool foundConflict = false; bool recordSaved = false; if (existingServiceWorkList != null) { foreach (ServiceWork existingServiceWork in existingServiceWorkList) { while ((foundConflict == false) && (recordSaved == false)) { if ((stg_servWork.ServiceEndTime.TimeOfDay > existingServiceWork.ServiceStartTime.TimeOfDay)) { //do not allow the save foundConflict = true; lblBookingMessage.Text = "Cannot book the time. A conflict will occur with booking# " + existingServiceWork.ServiceWorkID; LoadWorkHousInGridview(); PopulateGridviewSchedule(Convert.ToDateTime(actualServiceDate)); //show the scheduler this.mPopupSetServiceDateTime.Show(); } else { //save the service appointment stg_servWork.STG_servID = STG_ServiceWorkManager.Save(stg_servWork); ShowTheConfirmedDateTime(); recordSaved = true; } } //end while loop } //end foreach loop } else { //there's no conflict so saving can be made //save the service appointment stg_servWork.STG_servID = STG_ServiceWorkManager.Save(stg_servWork); ShowTheConfirmedDateTime(); } }
protected void vwFinalizeOrder_Activate(object sender, EventArgs e) { //display the work orders, replacement parts and service datetime ServiceWorkToBeDoneList w = Session["workList"] as ServiceWorkToBeDoneList; gviewWorkOrdersReview.DataSource = w; gviewWorkOrdersReview.DataBind(); STG_ServiceWork stg_servWork = Session["stg_servWork"] as STG_ServiceWork; dtf = CultureInfo.CreateSpecificCulture("en-US").DateTimeFormat; dtf.ShortDatePattern = myCustomShortDatePattern; lblReviewServiceDateTime.Text = stg_servWork.ServiceDate.ToString("ddd") + " " + stg_servWork.ServiceDate.ToString("d", dtf) + " - " + ddlServiceStartTime.SelectedValue.ToString() + " to " + ddlServiceEndTime.SelectedValue.ToString(); lblReviewTechnician.Text = ddlTechnician.SelectedValue.ToString(); }
/// <summary> /// Shows the Service Work Schedule and allows the user to select a date and time for /// the serview work /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void lnkOpenScheduler_OnCommand(object sender, CommandEventArgs e) { //enable the gridview gviewSchedule.Enabled = true; // populate the gview schedule LoadWorkHousInGridview(); //populate the header rows with the current week DateTime todaysDate = System.DateTime.Now.ToLocalTime(); PopulateGridviewSchedule(todaysDate); //show the scheduler this.mPopupSetServiceDateTime.Show(); // if the session is not null, show the confirmed selected date and time if (Session["stg_servWork"] != null) { DateTimeFormatInfo dtfi; dtfi = CultureInfo.CreateSpecificCulture("en-US").DateTimeFormat; dtfi.ShortDatePattern = @"MM/dd/yyyy"; STG_ServiceWork sw = Session["stg_servWork"] as STG_ServiceWork; ddlServiceEndTime.SelectedValue = sw.ServiceEndTime.ToShortTimeString().Replace(" ", ""); ddlServiceStartTime.SelectedValue = sw.ServiceStartTime.ToShortTimeString().Replace(" ", ""); lblSelectedServiceDate.Text = sw.ServiceDate.ToString("ddd") + " " + sw.ServiceDate.ToString("d", dtfi); //show the confirmation panel pnlConfirmServiceWorkAppointment.Visible = true; } else { //hide the confirmation panel pnlConfirmServiceWorkAppointment.Visible = false; } }
public static int Save(STG_ServiceWork s) { return(STG_ServiceWorkDB.Save(s)); }