예제 #1
0
        public bool Save(MilkRunViewModel model, User user)
        {
            const int humanMilkProductId = 5;

            model.CreatedByUserId = user.UserID;
            var runLog        = _mapper.Map(model);
            var prods         = Enumerable.Repeat(humanMilkProductId, model.BoxQty).ToList();
            var dal           = new RunLogDAL();
            var vehicleTypeId = dal.GetVehicleId(model.VehicleType);

            if (!vehicleTypeId.HasValue)
            {
                throw new InvalidOperationException($"Unknown VehicleType [{model.VehicleType}] while trying to save milk run");
            }
            runLog.VehicleTypeID = vehicleTypeId.Value;
            if (model.RunLogId == 0)
            {
                return(dal.CreateRunLog(runLog, prods) > 0);
            }

            var to = dal.Get(model.RunLogId);

            UpdatePropertyValues(runLog, to);
            return(dal.Update(to));
        }
예제 #2
0
        public MilkRunEditViewModel GetRunLogForEdit(string runLogId)
        {
            using (var dal = new RunLogDAL())
            {
                var dataTable = dal.GetMilkRunLog(int.Parse(runLogId));
                var item      = dataTable.AsEnumerable().Select(x =>
                                                                new MilkRunEditViewModel
                {
                    RunLogId           = int.Parse(runLogId),
                    Controller         = x.Field <string>("Controller"),
                    Rider              = x.Field <string>("Rider"),
                    DutyDate           = x.Field <string>("DutyDate"),
                    CollectTime        = x.Field <string>("CollectTime"),
                    DeliverTime        = x.Field <string>("DeliverTime"),
                    HomeSafeTime       = x.Field <string>("HomeSafeTime"),
                    Vehicle            = x.Field <string>("Vehicle"),
                    CollectionPostcode = x.Field <string>("CollectionPostcode"),
                    CollectionHospital = x.Field <string>("CollectionHospital"),
                    TakenTo            = x.Field <string>("TakenTo"),
                    TakenToPostcode    = x.Field <string>("TakenToPostcode"),
                    BoxQty             = x.Field <int>("Quantity"),
                    Notes              = x.Field <string>("Notes"),
                }).FirstOrDefault();

                return(item);
            }
        }
예제 #3
0
        public bool IsMilkRun(int runLogId)
        {
            var dal    = new RunLogDAL();
            var runlog = dal.Get(runLogId);

            return(runlog.RunLogType == "M");
        }
예제 #4
0
        public List <RunLog> ListYesterdays()
        {
            List <RunLog> ret = new List <RunLog>();
            List <SERVDataContract.DbLinq.RunLog> lret = new RunLogDAL().ListYesterdays();

            foreach (SERVDataContract.DbLinq.RunLog rl in lret)
            {
                ret.Add(new RunLog(rl));
            }
            return(ret);
        }
예제 #5
0
        public List <RunLog> ListQueuedOrdersForMember(int memberId)
        {
            log.LogStart();
            List <RunLog> ret = new List <RunLog>();
            List <SERVDataContract.DbLinq.RunLog> lret = new RunLogDAL().ListQueuedOrdersForMember(memberId);

            foreach (SERVDataContract.DbLinq.RunLog rl in lret)
            {
                ret.Add(Get(rl.RunLogID));
            }
            return(ret);
        }
예제 #6
0
        public List <RunLog> ListRecent(int count)
        {
            log.LogStart();
            List <RunLog> ret = new List <RunLog>();
            List <SERVDataContract.DbLinq.RunLog> lret = new RunLogDAL().ListRecent(count);

            foreach (SERVDataContract.DbLinq.RunLog rl in lret)
            {
                ret.Add(new RunLog(rl));
            }
            return(ret);
        }
예제 #7
0
        public string[] GetMemberUniqueRuns(int memberID)
        {
            List <string> ret = new List <string>();
            DataTable     t   = new RunLogDAL().GetMemberUniqueRuns(memberID);

            if (t != null)
            {
                foreach (DataRow r in t.Rows)
                {
                    ret.Add(r["Location"] + "-" + r["Product"]);
                }
            }
            return(ret.ToArray());
        }
예제 #8
0
        public RunLog Get(int runLogID)
        {
            log.LogStart();
            SERVDataContract.DbLinq.RunLog metal = new RunLogDAL().Get(runLogID);
            RunLog ret = new RunLog(metal);

            ret.Products = new Dictionary <string, int>();
            foreach (SERVDataContract.DbLinq.RunLogProduct rlp in metal.RunLogProduct)
            {
                if (ret.Products.ContainsKey(rlp.ProductID.ToString()))
                {
                    ret.Products[rlp.ProductID.ToString()] = ret.Products[rlp.ProductID.ToString()] + rlp.Quantity;
                }
                else
                {
                    ret.Products.Add(rlp.ProductID.ToString(), rlp.Quantity);
                }
            }
            ret.Vehicle = metal.VehicleTypeID != null ? metal.VehicleType.VehicleType1 : "";
            return(ret);
        }
예제 #9
0
        public string ExecuteSQL(string sql)
        {
            DataTable ret = null;

            try
            {
                ret = new RunLogDAL().ExecuteSQL(sql);
            }
            catch (Exception ex)
            {
                return("<table class='sqlResults'><tr><td>" + ex.Message + "</td></tr></table>");
            }
            StringBuilder b = new StringBuilder();

            b.AppendLine("<table class='sqlResults'>");
            string line = "<tr>";

            foreach (DataColumn c in ret.Columns)
            {
                line += string.Format("<td>{0}</td>", c.ColumnName);
            }
            line += "</tr>";
            b.AppendLine(line);
            foreach (DataRow r in ret.Rows)
            {
                line = "<tr>";
                foreach (object s in r.ItemArray)
                {
                    line += string.Format("<td>{0}</td>", s.ToString());
                }
                line += "</tr>";
                b.AppendLine(line.Substring(0, line.Length - 1));
            }
            b.AppendLine("</table>");
            return(b.ToString());
        }