コード例 #1
0
        public bool isError(Measure_model Model, int action, out List <string> lstMessgae)
        {
            bool isError = false;

            lstMessgae = new List <string>();
            if ((int)Common.ActionType.Add == action)
            {
                var result = db.Query <Measure_model>("SELECT * FROM `product_measure` WHERE `code` = @code", new { code = Model.code.Trim() }).ToList();
                if (result.Count != 0)
                {
                    isError = true;
                    lstMessgae.Add("[Code] is duplicate!");
                }
            }
            if ((int)Common.ActionType.Update == action)
            {
                var result = db.Query <Measure_model>("SELECT * FROM `product_measure` WHERE `code` = @code AND `id` <> @id", new { code = Model.code.Trim(), id = Model.id }).ToList();
                if (result.Count != 0)
                {
                    isError = true;
                    lstMessgae.Add("[Code] is duplicate!");
                }
            }
            return(isError);
        }
コード例 #2
0
        public ActionResult Index(Measure_model Model, int?page)
        {
            var pageNumber = page ?? 1;
            List <Measure_model> lstModel = new List <Measure_model>();
            int total = new int();

            if (!string.IsNullOrEmpty(Session["m_code"] as string))
            {
                Model.code = Session["m_code"].ToString();
            }
            if (!string.IsNullOrEmpty(Session["m_name"] as string))
            {
                Model.name = Session["m_name"].ToString();
            }
            _measureBLL.Search(Model, out lstModel, out total, pageNumber);
            var list = new StaticPagedList <Measure_model>(lstModel, pageNumber, 15, total);

            ViewBag.ListSearch = lstModel.OrderByDescending(x => x.id);
            ViewBag.page       = 0;
            if (page != null)
            {
                ViewBag.page = pageNumber - 1;
            }
            return(View(new Tuple <Measure_model, IPagedList <Measure_model> >(Model, list)));
        }
コード例 #3
0
        public int Search(Measure_model searchCondition, out List <Measure_model> lstModel, out int total, int _page)
        {
            int returnCode = (int)Common.ReturnCode.Succeed;

            lstModel = new List <Measure_model>();
            _page    = _page * 15 - 15;
            total    = new int();
            try
            {
                string sql  = "SELECT `id`, `code`, `name`, `description` FROM `product_measure` WHERE TRUE ";
                string _sql = "SELECT COUNT(`id`) FROM product_measure AS i WHERE TRUE ";
                if (!string.IsNullOrEmpty(searchCondition.code))
                {
                    sql  += "AND `code` LIKE @code ";
                    _sql += "AND `code` LIKE @code ";
                }
                if (!string.IsNullOrEmpty(searchCondition.name))
                {
                    sql  += "AND `name` LIKE @name ";
                    _sql += "AND `name` LIKE @name ";
                }
                sql     += " LIMIT @page,15 ";
                lstModel = db.Query <Measure_model>(sql, new { code = '%' + searchCondition.code + '%', name = '%' + searchCondition.name + '%', page = _page }).ToList();
                total    = db.ExecuteScalar <int>(_sql, new { code = '%' + searchCondition.code + '%', name = '%' + searchCondition.name + '%' });
                return(returnCode);
            }
            catch (Exception ex)
            {
                return(returnCode = (int)Common.ReturnCode.UnSuccess);
            }
        }
コード例 #4
0
        public ActionResult Edit(Measure_model Model)
        {
            if (string.IsNullOrEmpty(Model.id.ToString()))
            {
                TempData["Error"] = "Data has already been deleted by other user!";
                return(RedirectToAction("Index"));
            }
            List <string> lstMsg     = new List <string>();
            int           returnCode = _measureBLL.Update(Model, out lstMsg);

            if (ModelState.IsValid)
            {
                if (!((int)Common.ReturnCode.Succeed == returnCode))
                {
                    if (lstMsg != null)
                    {
                        for (int i = 0; i < lstMsg.Count(); i++)
                        {
                            ModelState.AddModelError(string.Empty, lstMsg[i]);
                        }
                    }
                    return(View(Model));
                }
                TempData["Success"] = "Updated Successfully!";
                return(RedirectToAction("Index"));
            }
            return(View());
        }
コード例 #5
0
        public ActionResult IndexPost(Measure_model Model, int?page)
        {
            var pageNumber = page ?? 1;
            List <Measure_model> lstModel = new List <Measure_model>();
            int total = new int();

            _measureBLL.Search(Model, out lstModel, out total, pageNumber);
            var list = new StaticPagedList <Measure_model>(lstModel, pageNumber, 15, total);

            ViewBag.ListSearch      = lstModel.OrderByDescending(x => x.id);
            Session["m_code"]       = Model.code;
            Session["m_name"]       = Model.name;
            TempData["CountResult"] = total.ToString() + " row(s) found!";
            return(View(new Tuple <Measure_model, IPagedList <Measure_model> >(Model, list)));
        }
コード例 #6
0
        public int GetDetail(int id, out Measure_model Model)
        {
            int returnCode = (int)Common.ReturnCode.Succeed;

            Model = new Measure_model();
            try
            {
                if (id != 0)
                {
                    string sql = "SELECT `id`, `code`, `name`, `description` FROM `product_measure` WHERE `id` = @id";
                    Model = db.Query <Measure_model>(sql, new { id = id }).SingleOrDefault();
                }
            }
            catch (Exception ex)
            {
                return((int)Common.ReturnCode.UnSuccess);
            }
            return(returnCode);
        }
コード例 #7
0
        public int Update(Measure_model Model, out List <string> lstMsg)
        {
            int returnCode = (int)Common.ReturnCode.Succeed;

            lstMsg = new List <string>();
            try
            {
                if (isError(Model, (int)Common.ActionType.Update, out lstMsg))
                {
                    returnCode = (int)Common.ReturnCode.UnSuccess;
                }
                string sql = "UPDATE `product_measure` SET `code` = @code, `name` = @name, `description` = @description WHERE `id` = @id";
                db.Execute(sql, new { code = Model.code, name = Model.name, description = Model.description, id = Model.id });
            }
            catch (Exception ex)
            {
                returnCode = (int)Common.ReturnCode.UnSuccess;
            }
            return(returnCode);
        }
コード例 #8
0
        public int Insert(Measure_model Model, out List <string> lstMsg)
        {
            int returnCode = (int)Common.ReturnCode.Succeed;

            lstMsg = new List <string>();
            try
            {
                if (isError(Model, (int)Common.ActionType.Add, out lstMsg))
                {
                    return((int)Common.ReturnCode.UnSuccess);
                }
                string sql = "INSERT INTO `product_measure` (`code`, `name`, `description`) VALUES (@code, @name, @description)";
                db.Execute(sql, new { code = Model.code.Trim(), name = Model.name.Trim(), description = Model.description.Trim() });
            }
            catch (Exception ex)
            {
                return((int)Common.ReturnCode.UnSuccess);
            }
            return(returnCode);
        }
コード例 #9
0
        public ActionResult View(int id)
        {
            if (string.IsNullOrEmpty(id.ToString()))
            {
                TempData["Error"] = "Data has already been deleted by other user!";
                return(RedirectToAction("Index"));
            }
            Measure_model Model      = new Measure_model();
            int           returnCode = _measureBLL.GetDetail(id, out Model);

            if (Model == null)
            {
                TempData["Error"] = "Data has already been deleted by other user!";
                return(RedirectToAction("Index"));
            }
            if (!((int)Common.ReturnCode.Succeed == returnCode))
            {
                Model = new Measure_model();
            }

            return(View(Model));
        }
コード例 #10
0
        public ActionResult Add(Measure_model Model)
        {
            List <string> lstMsg     = new List <string>();
            int           returnCode = _measureBLL.Insert(Model, out lstMsg);

            if (ModelState.IsValid)
            {
                if (!((int)Common.ReturnCode.Succeed == returnCode))
                {
                    if (lstMsg != null)
                    {
                        for (int i = 0; i < lstMsg.Count(); i++)
                        {
                            ModelState.AddModelError(string.Empty, lstMsg[i]);
                        }
                    }
                    return(View(Model));
                }
                TempData["Success"] = "Inserted Successfully!";
                return(RedirectToAction("Index"));
            }
            return(View());
        }
コード例 #11
0
 public int GetDetail(int id, out Measure_model model)
 {
     return(measure_bll.GetDetail(id, out model));
 }
コード例 #12
0
 public int Update(Measure_model model, out List <string> lstMsg)
 {
     return(measure_bll.Update(model, out lstMsg));
 }
コード例 #13
0
 public int Insert(Measure_model model, out List <string> lstMsg)
 {
     return(measure_bll.Insert(model, out lstMsg));
 }
コード例 #14
0
 public int Search(Measure_model model, out List <Measure_model> lstmodel, out int total, int _page)
 {
     return(measure_bll.Search(model, out lstmodel, out total, _page));
 }
コード例 #15
0
        public ActionResult Add()
        {
            Measure_model Model = new Measure_model();

            return(View(Model));
        }