示例#1
0
    protected async Task AddShift(int JobRno)
    {
        string Sql = string.Format(
            "Select JobDate, LoadTime, DepartureTime, ArrivalTime, MealTime, EndTime, " +
            "Customer, NumMenServing, Location, Crew, ProductionNotes " +
            "From mcJobs Where JobRno = {0}",
            JobRno);

        try
        {
            DataRow dr = db.DataRow(Sql);

            DateTime dtJob     = DB.DtTm(dr["JobDate"]);
            DateTime tmLoad    = DB.DtTm(dr["LoadTime"]);
            DateTime tmDepart  = DB.DtTm(dr["DepartureTime"]);
            DateTime tmArrival = DB.DtTm(dr["ArrivalTime"]);
            DateTime tmMeal    = DB.DtTm(dr["MealTime"]);

            DateTime tmBeg =
                tmLoad != DateTime.MinValue ? tmLoad :
                tmDepart != DateTime.MinValue ? tmDepart :
                tmArrival != DateTime.MinValue ? tmArrival :
                tmMeal != DateTime.MinValue ? tmMeal :
                DateTime.MinValue;

            tmBeg = new DateTime(dtJob.Year, dtJob.Month, dtJob.Day, tmBeg.Hour, tmBeg.Minute, tmBeg.Second);

            DateTime tmEnd = DB.DtTm(dr["EndTime"]);
            if (tmEnd > DateTime.MinValue)
            {
                tmEnd = new DateTime(dtJob.Year, dtJob.Month, dtJob.Day, tmEnd.Hour, tmEnd.Minute, tmEnd.Second);
            }
            else
            {
                tmEnd = tmBeg.AddHours(1);
            }

            if (dtJob > DateTime.MinValue && tmBeg > DateTime.MinValue)
            {
                string Customer  = DB.Str(dr["Customer"]);
                int    Servings  = DB.Int32(dr["NumMenServing"]);
                string Location  = DB.Str(dr["Location"]);
                string Crew      = DB.Str(dr["Crew"]);
                string ProdNotes = DB.Str(dr["ProductionNotes"]);

                ArrayList aSummary = new ArrayList();
                foreach (string SummaryPart in new string[]
                {
                    Customer,
                    string.Format("Job #{0}", JobRno),
                    string.Format("{0} Servings", Servings),
                    Location,
                    Crew,
                    ProdNotes
                })
                {
                    if (SummaryPart.Length > 0)
                    {
                        aSummary.Add(SummaryPart);
                    }
                }
                string Summary = string.Join(" - \\n", aSummary.ToArray());

                int SlingShiftId = await Sling.CreateShift(tmBeg, tmEnd, Sling.Location, Sling.Position, Summary);

                await Sling.PublishShift(SlingShiftId);

                Sql = string.Format("Update mcJobs Set SlingShiftId = {1} Where JobRno = {0}", JobRno, SlingShiftId);
                db.Exec(Sql);
            }
        }
        catch (Exception Ex)
        {
            Err Err = new Err(Ex, Sql);
            Response.Write(Err.Html());
        }
    }