コード例 #1
0
    protected async Task ProcessShifts()
    {
        int UserID = Str.Num(Request.QueryString["userid"]);

        Sling.User JobLead = await Sling.FindUser(UserID);

        lblJobLead.Text = (JobLead != null ? string.Format("{0} {1}", JobLead.FirstName, JobLead.LastName) : "User Not Found");

        Collection <Job> Jobs = new Collection <Job>();

        // look at all the shifts this job lead is assigned to
        foreach (Sling.CalendarEvent JobLeadShift in JobLead.CalendarEvents)
        {
            if (JobLeadShift.Type != "shift")
            {
                continue;
            }

            // prepare a job
            Job Job = new Job()
            {
                JobRno = JobLeadShift.JobRno
            };
            foreach (Sling.CalendarEvent Shift in Sling.Shifts)
            {
                // find every assigned to this job
                if (Shift.JobRno == JobLeadShift.JobRno)
                {
                    Job.cShifts.Add(Shift);
                }
            }

            if (Job.cShifts.Count > 0)
            {
                // sort the shift
                Sling.SortShiftCrew(Job.cShifts);
                if (Job.cShifts[0].User != null && Job.cShifts[0].User.ID != 0)
                {
                    Job.JobLeadUserID = Job.cShifts[0].User.ID;
                }

                // if the job lead is assigned to this job as a job lead
                if (Job.JobLeadUserID == UserID)
                {
                    // add to the list of jobs
                    Jobs.Add(Job);
                }
            }
        }

        // show the jobs
        foreach (Job Job in Jobs)
        {
            DateTime dtBeg = Job.cShifts[0].Beg;
            phJobs.Controls.Add(new HtmlGenericControl("h3")
            {
                InnerHtml = string.Format("Job #{0}&nbsp;&nbsp;{1}", Job.JobRno, dtBeg.ToString("ddd M/d/yyyy"))
            });

            HtmlGenericControl Div;
            phJobs.Controls.Add(Div = new HtmlGenericControl("div"));
            Div.Attributes.Add("class", "Job");
            Div.Attributes.Add("data-jobrno", Job.JobRno.ToString());

            string Html = string.Empty;
            foreach (Sling.CalendarEvent Shift in Job.cShifts)
            {
                Html += FormatCrew(Shift);
            }
            phJobs.Controls.Add(Div = new HtmlGenericControl("div")
            {
                InnerHtml = Html
            });
            Div.Attributes.Add("class", "Crew");
        }
    }
コード例 #2
0
    protected async Task Jobs()
    {
        // connect to sling, retrieve all the shifts and orgainize shifts into jobs
        await SetupSlingShifts();

        string JobDate = (rdoDay.Checked
            ? string.Format("= {0}", DB.PutDtTm(dtBeg))
            : string.Format("Between {0} And {1}", DB.PutDtTm(dtBeg), DB.PutDtTm(dtEnd)));
        string Sql = string.Format(
            "Select JobRno, JobDate, MealTime, Coalesce(cu.Name, c.Name) as Customer " +
            "From mcJobs j " +
            "Inner Join Contacts c On j.ContactRno = c.ContactRno " +
            "Left Join Customers cu on c.CustomerRno = cu.CustomerRno " +
            "Where JobDate {0} And IsNull(Crew, '') > '' Order By JobDate, MealTime",
            JobDate);

        Collection <Job> cJobs = new Collection <Job>();

        try
        {
            // gather information on the jobs;
            DataTable dt = db.DataTable(Sql);
            foreach (DataRow dr in dt.Rows)
            {
                int      JobRno   = DB.Int32(dr["JobRno"]);
                DateTime Date     = DB.DtTm(dr["JobDate"]);
                DateTime Time     = DB.DtTm(dr["MealTime"]);
                string   Customer = DB.Str(dr["Customer"]);

                Job Job;
                cJobs.Add(Job = new Job()
                {
                    JobRno = JobRno, Date = Date, Time = Time, Customer = Customer
                });

                // find the shifts connected with this job
                foreach (Sling.CalendarEvent Shift in Sling.Shifts)
                {
                    if (Job.JobRno == Shift.JobRno)
                    {
                        Job.cShifts.Add(Shift);
                    }
                }

                // sort shifts within this job, job lead in first shift
                Sling.SortShiftCrew(Job.cShifts);
                if (Job.cShifts.Count > 0 && Job.cShifts[0].User != null && Job.cShifts[0].User.ID != 0)
                {
                    Job.JobLeadUserID = Job.cShifts[0].User.ID;
                }
            }

            // track who the job leads are
            Collection <int> JobLeads = new Collection <int>();

            int[] JobsToSend = SendNoticeJobs();

            // show the jobs and leads
            int Count = 0;
            foreach (Job Job in cJobs)
            {
                if (Job.JobLeadUserID == 0)
                {
                    continue;
                }

                Sling.User JobLead     = Job.cShifts[0].User;
                string     JobLeadName = FormatCrew(Job.cShifts[0]);

                string Link = string.Empty;
                if (JobLeadName.Length > 0)
                {
                    Link = string.Format("<a href='JobLeadJobs.aspx?userid={0}' target='JobLead'>Jobs</a>", JobLead.ID);
                }

                TableCell td;
                TableRow  tr = new TableRow();
                tblJobs.Rows.Add(tr);

                tr.Cells.Add(new TableCell()
                {
                    CssClass = "JobRno", Text = Job.JobRno.ToString()
                });
                tr.Cells.Add(new TableCell()
                {
                    CssClass = "Date", Text = Fmt.Dt(Job.Date)
                });
                tr.Cells.Add(new TableCell()
                {
                    CssClass = "Time", Text = Fmt.Tm12Hr(Job.Time)
                });
                tr.Cells.Add(new TableCell()
                {
                    CssClass = "Customer", Text = Job.Customer
                });
                tr.Cells.Add(new TableCell()
                {
                    CssClass = "Crew", Text = JobLeadName
                });

                tr.Cells.Add(td = new TableCell()
                {
                    CssClass = "Send"
                });
                td.Controls.Add(Job.chkSend = new CheckBox()
                {
                    ID = "chkSend" + ++Count
                });
                Job.chkSend.Checked = (!fSendNotices || SendToJob(JobsToSend, Job.JobRno));

                tr.Cells.Add(new TableCell()
                {
                    CssClass = "Link", Text = Link
                });
                tr.Cells.Add(td = new TableCell()
                {
                    CssClass = "Notice"
                });
                td.Controls.Add(Job.lblNotice = new Label());

                if (fSendNotices && Job.chkSend.Checked)
                {
                    AddJobLead(JobLeads, Job.JobLeadUserID);
                }
            }

            // send the actual notices
            if (fSendNotices)
            {
                // for each job lead
                foreach (int JobLeadUserID in JobLeads)
                {
                    bool   fFirst    = true;
                    string Note      = string.Empty;
                    string FirstName = string.Empty;
                    string LastName  = string.Empty;

                    // look through the jobs for this job lead
                    // put all the jobs for this job lead
                    foreach (Job Job in cJobs)
                    {
                        if (Job.JobLeadUserID == JobLeadUserID && Job.chkSend.Checked)
                        {
                            if (!fFirst)
                            {
                                Note += "----------------------------------------\n";
                            }
                            fFirst = false;
                            Note  += string.Format("Job #: {0}\\nDate: {1}\\nTime: {2}\\nCustomer: {3}\\n{4}://{5}{6}{7}?userid={8}",
                                                   Job.JobRno,
                                                   Fmt.Dt(Job.Date),
                                                   Fmt.Tm12Hr(Job.Time),
                                                   Job.Customer,
                                                   Request.Url.Scheme,
                                                   Request.Url.Host,
                                                   (Request.Url.Port == 80 || Request.Url.Port == 403 ? "" : ":" + Request.Url.Port),
                                                   ResolveUrl("~/JobLeadJobs.aspx"),
                                                   JobLeadUserID);
                            Job.lblNotice.Text = "Sent";

                            FirstName = Job.cShifts[0].User.FirstName;
                            LastName  = Job.cShifts[0].User.LastName;
                        }
                    }

                    string Msg = string.Format(
                        "{{" +
                        "\"content\": \"{0}\"," +
                        "\"name\": \"{1} {2}\"," +
                        "\"personas\": [{{" +
                        "\"id\": {3}," +
                        "\"type\": \"user\"" +
                        "}}]," +
                        "\"private\": true" +
                        "}}",
                        Note,
                        FirstName,
                        LastName,
                        JobLeadUserID);

                    // send the message
                    await Sling.AddToPrivateConversation(Msg);
                }
            }
        }
        catch (Exception Ex)
        {
            Err Err = new Err(Ex, Sql);
            Response.Write(Err.Html());
        }
    }