public static Job AddOrderToList(Job job) { if (job.OrderID != null) { var tmplist = SiteUtilities.GetJobsByOrderId(job.OrderID); if (tmplist.Count == 0) { return job; } } return null; }
/// <summary> /// Update current job with new values /// </summary> /// <param name="job"></param> /// <param name="connection"></param> public static void UpdateJob(Job job, SqlConnection connection) { try { connection.Open(); // 1. create a command object identifying // the stored procedure SqlCommand cmd = new SqlCommand( "JOB_UpdateJob", connection); // 2. set the command object so it knows // to execute a stored procedure cmd.CommandType = CommandType.StoredProcedure; // 3. add parameter to command, which // will be passed to the stored procedure SetParametersForJob(cmd, job); // execute the command cmd.ExecuteReader(); } finally { if (connection != null) { connection.Close(); } } }
private static void SetParametersForJob(SqlCommand cmd, Job job) { cmd.Parameters.Add(new SqlParameter("@JobID", job.JobId)); cmd.Parameters.Add(new SqlParameter("@JobName", job.JobName)); cmd.Parameters.Add(new SqlParameter("@Active", true)); cmd.Parameters.Add(new SqlParameter("@OrderID", job.OrderID)); cmd.Parameters.Add(new SqlParameter("@JobStartDate", job.JobStartDate)); cmd.Parameters.Add(new SqlParameter("@JobStartTime", job.JobStartTime)); cmd.Parameters.Add(new SqlParameter("@JobEndDate", job.JobEndDate)); cmd.Parameters.Add(new SqlParameter("@JobEndTime", job.JobEndTime)); cmd.Parameters.Add(new SqlParameter("@RentStartDate", job.RentStartDate)); cmd.Parameters.Add(new SqlParameter("@RentEndDate", job.RentEndDate)); cmd.Parameters.Add(new SqlParameter("@ContactPerson", job.ContactName)); cmd.Parameters.Add(new SqlParameter("@Address", job.Address)); cmd.Parameters.Add(new SqlParameter("@Comments", job.Comments)); cmd.Parameters.Add(new SqlParameter("@FullDay", job.FullDay)); cmd.Parameters.Add(new SqlParameter("@NeedUpdate", job.NeedUpdate)); cmd.Parameters.Add(new SqlParameter("@ParentJobID", job.ParentJobID)); cmd.Parameters.Add(new SqlParameter("@ContactPhone", job.Phone)); cmd.Parameters.Add(new SqlParameter("@Type", job.Type)); cmd.Parameters.Add(new SqlParameter("@Month", job.Month)); }
public static List<Job> GetOrdersFromMamut(Exception exception, HttpRequest request) { string mamutID = ""; int mamutStartValue = 0; int mamutMaxValue = 0; System.Configuration.Configuration rootWebConfig1 = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(request.ApplicationPath); if (rootWebConfig1.AppSettings.Settings.Count > 0) { KeyValueConfigurationElement mamutIDSetting = rootWebConfig1.AppSettings.Settings["MAMUT_ID"]; KeyValueConfigurationElement mamutStartNumber = rootWebConfig1.AppSettings.Settings["MAMUT_START_VALUE"]; KeyValueConfigurationElement mamutmaxNumber = rootWebConfig1.AppSettings.Settings["MAMUT_MAX_VALUE"]; mamutID = mamutIDSetting.Value; mamutStartValue = Convert.ToInt32(mamutStartNumber.Value); mamutMaxValue = Convert.ToInt32(mamutmaxNumber.Value); } List<Job> jobs = new List<Job>(); try { // Setup Connection to Mamut dynamic gba = Activator.CreateInstance(Type.GetTypeFromProgID("GBAAPI.Gba")); dynamic connectinfo = Activator.CreateInstance(Type.GetTypeFromProgID("GBAAPI.Connectinfo")); connectinfo.SetConnectBasicInfo(".", "mamut", 1, mamutID); gba.openConnection(connectinfo); dynamic Order = Activator.CreateInstance(Type.GetTypeFromProgID("GBAAPI.Orderheader")); dynamic Contact = Activator.CreateInstance(Type.GetTypeFromProgID("GBAAPI.Contact")); dynamic ContactPerson = Activator.CreateInstance(Type.GetTypeFromProgID("GBAAPI.Cperson")); Order.NewInit(gba); Contact.NewInit(gba); ContactPerson.NewInit(gba); if (Order.NewInit(gba) != null) { for (int i = mamutStartValue; i < mamutMaxValue; i++) { int retval = (int) Order.Get(i); if (retval == 1) { Order.Get(i); gbaapi.Iorderheader orderheader = Order; if (orderheader.Status == 5200 && orderheader.Lorderpicked) { MamutOrder mamutOrder = GetDatesFromMamut(orderheader); DateTime jobstartdate = DateTime.Now; DateTime jobenddate = DateTime.Now; string orderref = ""; string address = ""; string companyname = ""; string phone = ""; if (mamutOrder.JobStartDate.ToString() != "") { try { if (mamutOrder.JobStartDate > DateTime.MinValue) jobstartdate = mamutOrder.JobStartDate; } catch { jobstartdate = DateTime.MaxValue; } } if (mamutOrder.JobEndDate.ToString() != "") { try { if (mamutOrder.JobEndDate > DateTime.MinValue) jobenddate = mamutOrder.JobEndDate; } catch { jobenddate = DateTime.MaxValue; } } if (mamutOrder.YourRef != null) { try { orderref = mamutOrder.YourRef.Trim(); } catch { orderref = ""; } } if (mamutOrder.Address != null) { address = mamutOrder.Address; } Contact.Get(Order.ContID); Contact.Getcpers(); if (Contact.Contname != null) { companyname = Contact.Contname.Trim(); } ContactPerson.Get(Contact.Cpersid); if (Contact.Phone1 != null) { try { phone = ContactPerson.Phone1.Trim(); } catch { phone = ""; } } int id = Order.Orderid; Job job = new Job(Guid.NewGuid(), companyname, true, id.ToString(), jobstartdate, jobenddate, orderref, address, string.Empty, DateTime.MaxValue, DateTime.MaxValue, DateTime.MaxValue, DateTime.MaxValue, string.Empty, false, false, Guid.Empty, string.Empty, phone, 5, string.Empty); Job j = AddOrderToList(job); // If j == null job allready exist dont add it again if (j != null) { jobs.Add(j); } } } } } } catch { return null; } return jobs; }