Exemplo n.º 1
0
        internal static DataSet GetSyncData(DateTime toDate)
        {
            MealSetTableAdapter mealSetTA = new MealSetTableAdapter();
            ScheduleTableAdapter scheduleTA = new ScheduleTableAdapter();
            ScheduleMealSetDetailTableAdapter scheduleMealSetDetailTA = new ScheduleMealSetDetailTableAdapter();
            ServingTimeTableAdapter servingTimeTA = new ServingTimeTableAdapter();
            TransactionHistoryTableAdapter transactionHistoryTA = new TransactionHistoryTableAdapter();
            TransactionTypeTableAdapter transactionTypeTA = new TransactionTypeTableAdapter();
            UserInfoTableAdapter userInfoTA = new UserInfoTableAdapter();
            UserTypeTableAdapter userTypeTA = new UserTypeTableAdapter();

            DateTime minDate = (DateTime)SqlDateTime.MinValue;

            DataSet ds = new DataSet();
            ds.Tables.Add(userTypeTA.GetDataByDate(minDate, toDate));
            ds.Tables.Add(userInfoTA.GetDataByDate(minDate, toDate));
            ds.Tables.Add(mealSetTA.GetDataByDate(minDate, toDate));
            ds.Tables.Add(servingTimeTA.GetDataByDate(minDate, toDate));
            ds.Tables.Add(scheduleTA.GetDataByDate(minDate, toDate));
            ds.Tables.Add(scheduleMealSetDetailTA.GetDataByDate(minDate, toDate));
            ds.Tables.Add(transactionTypeTA.GetDataByDate(minDate, toDate));
            ds.Tables.Add(transactionHistoryTA.GetDataByDate(minDate, toDate));

            return ds;
        }
Exemplo n.º 2
0
        public ActionResult AddNewServingTime(ServingTimeModel servingTimeModel)
        {
            if (!ModelState.IsValid)
            {
                return View(servingTimeModel);
            }

            ServingTimeTableAdapter servingTimeDataAdapter = new ServingTimeTableAdapter();
            DataTable servingTimeDT = servingTimeDataAdapter.GetData();

            try
            {
                string name = servingTimeModel.Name;
                TimeSpan startTime = servingTimeModel.startTime;
                TimeSpan endTime = servingTimeModel.endTime;

                if (startTime.Days > 0)
                {
                    startTime = TimeSpan.FromHours(startTime.Days);
                }

                if (endTime.Days > 0)
                {
                    endTime = TimeSpan.FromHours(endTime.Days);
                }

                TimeSpan startTimeDB, endTimeDB;

                if (startTime > endTime)
                {
                    ModelState.AddModelError("", "Thời gian bắt đầu không được lớn hơn thời gian kết thúc.");
                    return View(servingTimeModel);
                }

                foreach (System.Data.DataRow row in servingTimeDT.Rows)
                {
                    startTimeDB = row.Field<TimeSpan>("StartTime");
                    endTimeDB = row.Field<TimeSpan>("EndTime");

                    if ((startTime >= startTimeDB && startTime <= endTimeDB) || (endTime >= startTimeDB && endTime <= endTimeDB) || (startTime <= startTimeDB && endTime >= endTimeDB))
                    {
                        ModelState.AddModelError("", "Thời gian phục vụ mới trùng với thời gian phục vụ có trước đó. Vui lòng xác nhận lại!");
                        return View(servingTimeModel);
                    }
                }
                DateTime date = DateTime.Now;
                servingTimeDataAdapter.Insert(name, startTime, endTime, date, date);
                Session["addServingTime"] = "Thêm mới thành công!";
            }
            catch (Exception ex)
            {
                Log.ErrorLog(ex.Message);
                Session["addServingTime"] = "Thêm mới thất bại!";
            }
            return RedirectToAction("ViewServingTime", "Schedule");
        }
Exemplo n.º 3
0
        public ActionResult ViewServingTime()
        {
            DataTable dataTable = new DataTable();
            ServingTimeTableAdapter servingTimeAdapter = new ServingTimeTableAdapter();

            try
            {
                dataTable = servingTimeAdapter.GetData();
            }
            catch (Exception ex)
            {
                Log.ErrorLog(ex.Message);
            }

            return View(dataTable);
        }
Exemplo n.º 4
0
        public JsonResult GetEatingTime()
        {
            try
            {
                ServingTimeTableAdapter servingTimeTA = new ServingTimeTableAdapter();
                DataTable servingTimeDT = servingTimeTA.GetData();

                IList<ServingTimeJsonModel> servingTime = new List<ServingTimeJsonModel>();

                foreach (DataRow row in servingTimeDT.Rows)
                {
                    ServingTimeJsonModel model = new ServingTimeJsonModel();

                    model.ServingTimeID = row.Field<int>("ServingTimeID");
                    model.Name = row.Field<string>("Name");
                    model.StartTimeStr = row.Field<TimeSpan>("StartTime").ToString(@"hh\:mm");

                    TimeSpan? temp = row.Field<TimeSpan?>("EndTime");
                    if (temp == null)
                    {
                        model.EndTimeStr = null;
                    }
                    else
                    {
                        model.EndTimeStr = temp.Value.ToString(@"hh\:mm");
                    }

                    servingTime.Add(model);
                }

                return Json(new { servingTime = servingTime }, JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                Log.ErrorLog(ex.ToString());
                return Json("error", JsonRequestBehavior.AllowGet);
            }
        }
Exemplo n.º 5
0
        public ActionResult EditServingTime(ServingTimeModel servingTimeModel, string servingTimeID)
        {
            if (!ModelState.IsValid)
            {
                return View(servingTimeModel);
            }

            ServingTimeTableAdapter servingTimeTableAdapter = new ServingTimeTableAdapter();
            DataTable servingTimeDT = servingTimeTableAdapter.GetData();

            try
            {
                int servingTimeId = Convert.ToInt32(servingTimeID);
                string name = servingTimeModel.Name;
                TimeSpan startTime = servingTimeModel.startTime;
                TimeSpan endTime = servingTimeModel.endTime;
                if (startTime.Days > 0)
                {
                    startTime = TimeSpan.FromHours(startTime.Days);
                }

                if (endTime.Days > 0)
                {
                    endTime = TimeSpan.FromHours(endTime.Days);
                }
                TimeSpan startTimeDB, endTimeDB;

                if (startTime > endTime)
                {
                    ModelState.AddModelError("", "Thời gian bắt đầu không được lớn hơn thời gian kết thúc.");
                    return View(servingTimeModel);
                }

                foreach (System.Data.DataRow row in servingTimeDT.Rows)
                {
                    if (!(row.Field<int>("ServingTimeID") == servingTimeId))
                    {
                        startTimeDB = row.Field<TimeSpan>("StartTime");
                        endTimeDB = row.Field<TimeSpan>("EndTime");

                        if ((startTime >= startTimeDB && startTime <= endTimeDB) || (endTime >= startTimeDB && endTime <= endTimeDB) || (startTime <= startTimeDB && endTime >= endTimeDB))
                        {
                            ModelState.AddModelError("", "Thời gian phục vụ mới trùng với thời gian phục vụ có trước đó. Vui lòng xác nhận lại!");
                            return View(servingTimeModel);
                        }
                    }
                }

                DateTime insertDate = servingTimeModel.insertDate;
                DateTime lastUpdate = DateTime.Now;

                servingTimeTableAdapter.UpdateServingTimeByID(name, startTime, endTime, insertDate, lastUpdate, servingTimeId);
                Session["editServingTime"] = "Cập nhật thành công!";
            }
            catch (Exception ex)
            {
                Log.ErrorLog(ex.Message);
                Session["editServingTime"] = "Cập nhật thất bại!";
            }
            return RedirectToAction("EditServingTime", "Schedule", new { @servingTimeID = servingTimeID });
        }
Exemplo n.º 6
0
 public ActionResult EditServingTime(string servingTimeID)
 {
     ServingTimeModel servingTimeModel = new ServingTimeModel();
     DataTable servingTimeDataTable = new DataTable();
     ServingTimeTableAdapter servingTimeAdapter = new ServingTimeTableAdapter();
     try
     {
         int servingTimeId = Convert.ToInt32(servingTimeID);
         servingTimeDataTable = servingTimeAdapter.GetDataByID(servingTimeId);
         servingTimeModel.servingTimeID = servingTimeDataTable.Rows[0].Field<int>("ServingTimeID");
         servingTimeModel.Name = Convert.ToString(servingTimeDataTable.Rows[0]["Name"]);
         servingTimeModel.startTime = (TimeSpan)servingTimeDataTable.Rows[0]["StartTime"];
         servingTimeModel.endTime = (TimeSpan)servingTimeDataTable.Rows[0]["EndTime"];
         servingTimeModel.insertDate = Convert.ToDateTime(servingTimeDataTable.Rows[0]["InsertedDate"]);
         servingTimeModel.lastUpdate = Convert.ToDateTime(servingTimeDataTable.Rows[0]["LastUpdated"]);
     }
     catch (Exception ex)
     {
         Log.ErrorLog(ex.Message);
         return RedirectToAction("Error", "Error");
     }
     return View(servingTimeModel);
 }
Exemplo n.º 7
0
 public ActionResult DeleteServingTime(string servingTimeID)
 {
     ServingTimeTableAdapter servingTimeTableAdapter = new ServingTimeTableAdapter();
     ScheduleTableAdapter scheduleTableAdapter = new ScheduleTableAdapter();
     try
     {
         int id = Convert.ToInt32(servingTimeID);
         servingTimeTableAdapter.DeleteServingTimeByID(id);
         Session["deleteServingTime"] = "Xóa thành công!";
     }
     catch (Exception ex)
     {
         Log.ErrorLog(ex.Message);
         Session["deleteServingTime"] = "Xóa thất bại! Thời gian phục vụ này đang được sử dụng.";
     }
     return RedirectToAction("ViewServingTime", "Schedule");
 }