Ejemplo 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;
        }
Ejemplo n.º 2
0
        public ActionResult AddMealSet(MealSetViewModel model)
        {
            ViewBag.CheckRunTimes = "2";

            if (!ModelState.IsValid)
            {
                return View(model);
            }

            string updateBy = AccountInfo.GetUserName(Request);
            DateTime date = DateTime.Now;
            string mealSetName = model.MealSetName;
            string description = model.Description;
            bool canEatMore = model.CanEatMore;
            string imgPath = null;
            string savePath = null;

            MealSetTableAdapter mealSetAdapter = new MealSetTableAdapter();
            DataTable mealSetDT = mealSetAdapter.GetDataByName(mealSetName);

            foreach (DataRow row in mealSetDT.Rows)
            {
                if (StringExtensions.EqualsInsensitive(row["Name"].ToString(), mealSetName))
                {
                    ModelState.AddModelError("", "Tên suất ăn đã tồn tại.");
                    return View(model);
                }
            }

            if (!string.IsNullOrEmpty(model.Image))
            {
                savePath = _sourcePath + mealSetName.Replace(" ", "_") + ".jpg";
                var sourcePath = AppDomain.CurrentDomain.BaseDirectory + model.Image;

                System.IO.File.Move(sourcePath, savePath);
                imgPath = "\\Images\\MealSetImages\\" + mealSetName.Replace(" ", "_") + ".jpg";
            }

            try
            {

                string mealSetID = mealSetAdapter.InsertMealSetScalar(mealSetName, imgPath, description, canEatMore, date, updateBy, date).ToString();
                int id = int.Parse(mealSetID);
                XmlSync.SaveMealSetXml(id, mealSetName, canEatMore, date, updateBy, date, null);
                Log.ActivityLog("Insert into MealSet Table: MealSetName = " + mealSetName);
                Session["addMeslSet"] = "Thêm suất ăn thành công!";
            }
            catch (Exception ex)
            {
                Log.ErrorLog(ex.Message);
                Session["addMeslSet"] = "Thêm suất ăn thất bại!";
            }
            return RedirectToAction("AddMealSet", "MealSet");
        }
Ejemplo n.º 3
0
        public ActionResult ListMealSet(string search, string filter)
        {
            ViewBag.successMessage = "";

            ViewBag.notExistMealSet = "";

            MealSetTableAdapter mealSetAdapter = new MealSetTableAdapter();
            try
            {
                mealSetDT = mealSetAdapter.GetData();
            }
            catch (Exception ex)
            {
                Log.ErrorLog(ex.Message);
            }

            if (!(string.IsNullOrEmpty(search) && string.IsNullOrEmpty(filter)))
            {
                int type = -1;
                if (!string.IsNullOrEmpty(filter))
                {
                    int.TryParse(filter, out type);
                }

                string name = search;
                if (name == null)
                {
                    name = String.Empty;
                }

                bool type_ = false;
                if (type == 1)
                {
                    type_ = true;
                }
                var result = from row in mealSetDT.AsEnumerable()
                             where (name == String.Empty ? true : StringExtensions.ContainsInsensitive(row.Field<string>("Name"), name))
                             && (type < 0 ? true : row.Field<bool>("CanEatMore") == type_)
                             select row;

                try
                {
                    return View(result.CopyToDataTable());
                }
                catch (Exception ex)
                {
                    if (string.IsNullOrEmpty(search))
                    {
                        ViewBag.notExistMealSet = "Không tìm thấy kết quả nào";
                    }
                    else
                    {
                        ViewBag.notExistMealSet = "Không tìm thấy kết quả nào với từ khóa: " + search;
                    }
                    Log.ErrorLog(ex.Message);
                }
            }

            return View(mealSetDT);
        }
Ejemplo n.º 4
0
        public ActionResult EditMealSet(EditMealSetModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            MealSetTableAdapter mealSetAdapter = new MealSetTableAdapter();

            string updateBy = AccountInfo.GetUserName(Request);
            DateTime date = DateTime.Now;
            int mealSetID = model.MealSetID;
            string mealSetName = model.MealSetName;
            string description = model.Description;
            bool canEatMore = model.CanEatMore;

            DataTable dt = mealSetAdapter.GetDataByMealSetID(mealSetID);

            string savePath = "\\Images\\MealSetImages\\" + mealSetName.Replace(" ", "_") + ".jpg";

            if (!StringExtensions.EqualsInsensitive(dt.Rows[0]["Name"].ToString(), mealSetName))
            {
                DataTable mealSetDT = mealSetAdapter.GetDataByName(mealSetName);

                foreach (DataRow row in mealSetDT.Rows)
                {
                    if (StringExtensions.EqualsInsensitive(row["Name"].ToString(), mealSetName))
                    {
                        ModelState.AddModelError("", "Tên món ăn đã tồn tại.");
                        return View(model);
                    }
                }

                savePath = "\\Images\\MealSetImages\\" + mealSetName.Replace(" ", "_") + ".jpg";

            }
            if (model.Image != null)
            {
                if (model.Image.Contains("Temp2"))
                {
                    string oldImage = dt.Rows[0]["Image"].ToString();
                    var oldImagePath = AppDomain.CurrentDomain.BaseDirectory + oldImage;
                    System.IO.File.Delete(oldImagePath);
                }

                System.IO.File.Move(AppDomain.CurrentDomain.BaseDirectory + model.Image, AppDomain.CurrentDomain.BaseDirectory + savePath);
            }
            else
            {
                savePath = null;
            }

            try
            {
                mealSetAdapter.UpdateMealSet(mealSetName, savePath, description, canEatMore, updateBy, date, mealSetID);
                XmlSync.SaveMealSetXml(mealSetID, mealSetName, canEatMore, date, updateBy, date, null);
                Log.ActivityLog("Update to MealSet Table: MealSetID = " + mealSetID);
                Session["editMealSet"] = "Cập nhật thành công!";
            }
            catch (Exception ex)
            {
                Log.ErrorLog(ex.Message);
                Session["editMealSet"] = "Cập nhật thành công!";
            }

            return RedirectToAction("EditMealSet", "MealSet", new { @mealSetID = model.MealSetID});
        }
Ejemplo n.º 5
0
        public ActionResult EditMealSet(string mealSetID)
        {
            try
            {
                int id = int.Parse(mealSetID);

                EditMealSetModel model = new EditMealSetModel();
                MealSetTableAdapter mealSetAdapter = new MealSetTableAdapter();
                DataTable mealSetDT = mealSetAdapter.GetDataByMealSetID(id);
                model.MealSetID = id;
                model.MealSetName = mealSetDT.Rows[0]["Name"].ToString();
                model.Description = mealSetDT.Rows[0]["Description"].ToString();
                model.Image = mealSetDT.Rows[0]["Image"].ToString();
                model.CanEatMore = (bool)mealSetDT.Rows[0]["CanEatMore"];
                return View(model);
            }
            catch (Exception ex)
            {
                Log.ErrorLog(ex.Message);
                return RedirectToAction("Error", "Error");
            }
        }
Ejemplo n.º 6
0
        public ActionResult DeletemealSet(int mealSetID)
        {
            MealSetTableAdapter MealSetAdapter = new MealSetTableAdapter();
            DataTable MealSetData = MealSetAdapter.GetDataByMealSetID(mealSetID);

            try
            {
                int test = MealSetAdapter.Delete(mealSetID);

                if (!string.IsNullOrEmpty(MealSetData.Rows[0]["Name"].ToString()))
                {
                    var deleteFilePath = AppDomain.CurrentDomain.BaseDirectory + MealSetData.Rows[0]["Name"].ToString();
                    System.IO.File.Delete(deleteFilePath);
                }

                Session["deleteMealSet"] = "Xóa thành công!";

            }
            catch (Exception ex)
            {
                Log.ErrorLog(ex.Message);
                Session["deleteMealSet"] = "Xóa thất bại! Suất ăn đang được sử dụng.";
            }

            return RedirectToAction("ListMealSet","MealSet");
        }
Ejemplo n.º 7
0
        public ActionResult AddMealSetDish(string mealSetID, string search, string filter)
        {
            ViewBag.notExistMealSet = "";

            DishTypeTableAdapter dishTypeAdapter = new DishTypeTableAdapter();
            DataTable dishTypeDT = dishTypeAdapter.GetData();

            List<SelectListItem> items = new List<SelectListItem>();
            items.Add(new SelectListItem { Text = "Tất Cả", Value = "" });
            foreach (DataRow row in dishTypeDT.Rows)
            {
                items.Add(new SelectListItem { Text = row["TypeName"].ToString(), Value = row["DishTypeID"].ToString() });
            }
            ViewData["DishType"] = items;

            DataTable dishDT = new DataTable();
            DishInfoDetailTableAdapter adapter = new DishInfoDetailTableAdapter();

            try
            {
                dishDT = adapter.GetData();
            }
            catch (Exception ex)
            {
                Log.ErrorLog(ex.Message);
            }

            if (!(string.IsNullOrEmpty(search) && string.IsNullOrEmpty(filter)))
            {
                int type = -1;
                int.TryParse(filter, out type);

                string name = search;
                if (name == null)
                {
                    name = String.Empty;
                }

                var result = from row in dishDT.AsEnumerable()
                             where (name == String.Empty ? true : StringExtensions.ContainsInsensitive(row.Field<string>("Name"), name))
                             && (type < 1 ? true : row.Field<int>("DishTypeID") == type)
                             select row;

                try
                {
                    dishDT = result.CopyToDataTable();
                }
                catch (Exception ex)
                {
                    if (string.IsNullOrEmpty(search))
                    {
                        ViewBag.notExistMealSet = "Không tìm thấy kết quả nào";
                    }
                    else
                    {
                        ViewBag.notExistMealSet = "Không tìm thấy kết quả nào với từ khóa: " + search;
                    }
                    Log.ErrorLog(ex.Message);
                }
            }

            ViewData["listDish"] = dishDT;

            try
            {
                int id = int.Parse(mealSetID);
                MealSetDishInfoTableAdapter mealSetDishInfoAdapter = new MealSetDishInfoTableAdapter();
                ViewData["listMealSetDish"] = mealSetDishInfoAdapter.GetDataByMealSetID(id);

                MealSetTableAdapter mealSetAdapter = new MealSetTableAdapter();
                EditMealSetModel model = new EditMealSetModel();
                DataTable mealSetDT = mealSetAdapter.GetDataByMealSetID(id);

                model.MealSetID = id;
                model.MealSetName = mealSetDT.Rows[0]["Name"].ToString();
                model.Description = mealSetDT.Rows[0]["Description"].ToString();
                model.Image = mealSetDT.Rows[0]["Image"].ToString();
                model.CanEatMore = (bool)mealSetDT.Rows[0]["CanEatMore"];

                return View(model);
            }
            catch (Exception ex)
            {
                Log.ErrorLog(ex.Message);
                return RedirectToAction("Error", "Error");
            }
        }
Ejemplo n.º 8
0
        public JsonResult GetMeatSetForDDL()
        {
            try
            {
                MealSetTableAdapter mealSetTA = new MealSetTableAdapter();
                DataTable mealSetDT = mealSetTA.GetData();

                IList<MeatSetForDDLJsonModel> mealSet = new List<MeatSetForDDLJsonModel>();

                foreach (DataRow row in mealSetDT.Rows)
                {
                    MeatSetForDDLJsonModel model = new MeatSetForDDLJsonModel();

                    model.MealSetID = row.Field<int>("MealSetID");
                    model.Name = row.Field<string>("Name");

                    mealSet.Add(model);
                }

                return Json(new { mealSet = mealSet }, JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                Log.ErrorLog(ex.Message);
                return Json("error", JsonRequestBehavior.AllowGet);
            }
        }