public ActionResult Edit(Item_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   = _itemBLL.Update(Model, out lstMsg);
            List <GetCatetory_model> lstcombobox  = new List <GetCatetory_model>();
            List <GetMeasure_model>  _lstcombobox = new List <GetMeasure_model>();

            _itemBLL.GetCategory(true, out lstcombobox);
            _itemBLL.GetMeasure(true, out _lstcombobox);
            ViewBag.Category = lstcombobox;
            ViewBag.Measure  = _lstcombobox;
            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());
        }
        public ActionResult Add(Item_model Model)
        {
            List <string>            lstMsg       = new List <string>();
            List <GetCatetory_model> lstcombobox  = new List <GetCatetory_model>();
            List <GetMeasure_model>  _lstcombobox = new List <GetMeasure_model>();

            _itemBLL.GetCategory(true, out lstcombobox);
            _itemBLL.GetMeasure(true, out _lstcombobox);
            ViewBag.Category = lstcombobox;
            ViewBag.Measure  = _lstcombobox;
            int returnCode = _itemBLL.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());
        }
示例#3
0
        public int GetDetail(int id, out Item_model Model)
        {
            int returnCode = (int)Common.ReturnCode.Succeed;

            Model = new Item_model();
            try
            {
                if (id != 0)
                {
                    string sql = "SELECT p.`id`, p.`category_id`, c.`name` AS `category_name`, p.`code`, p.`name`, p.`specification`, p.`description`, p.`dangerous`, p.`discontinued_datetime`, ";
                    sql  += "p.`inventory_measure_id`, m1.`name` AS `inventory_measure_name`, p.`inventory_expired`, p.`inventory_standard_cost`, p.`inventory_list_price`, p.`manufacture_day`, ";
                    sql  += "p.`manufacture_make`, p.`manufacture_tool`, p.`manufacture_finished_goods`, p.`manufacture_size`, p.`manufacture_size_measure_id`, m2.`name` AS `manufacture_size_measure_name`, ";
                    sql  += "p.`manufacture_weight`, p.`manufacture_weight_measure_id`, m3.`name` AS `manufacture_weight_measure_name`, p.`manufacture_style`, p.`manufacture_class`, ";
                    sql  += "`manufacture_color` FROM `product_item` AS p ";
                    sql  += "LEFT OUTER JOIN `product_measure` AS m1 ON ( p.`inventory_measure_id` = m1.`id`) ";
                    sql  += "LEFT OUTER JOIN `product_measure` AS m2 ON ( p.`manufacture_size_measure_id` = m2.`id`) ";
                    sql  += "LEFT OUTER JOIN `product_measure` AS m3 ON ( p.`manufacture_weight_measure_id` = m3.`id`) ";
                    sql  += "LEFT OUTER JOIN `product_category` AS c ON ( p.`category_id` = c.`id`) ";
                    sql  += "WHERE p.`id` = @id ";
                    Model = db.Query <Item_model>(sql, new { id = id }).SingleOrDefault();
                }
            }
            catch (Exception ex)
            {
                return((int)Common.ReturnCode.UnSuccess);
            }
            return(returnCode);
        }
        public ActionResult Edit(int id)
        {
            if (string.IsNullOrEmpty(id.ToString()))
            {
                TempData["Error"] = "Data has already been deleted by other user!";
                return(RedirectToAction("Index"));
            }

            Item_model Model      = new Item_model();
            int        returnCode = _itemBLL.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 Item_model();
            }

            List <GetCatetory_model> lstcombobox  = new List <GetCatetory_model>();
            List <GetMeasure_model>  _lstcombobox = new List <GetMeasure_model>();

            _itemBLL.GetCategory(true, out lstcombobox);
            _itemBLL.GetMeasure(true, out _lstcombobox);
            ViewBag.Category = lstcombobox;
            ViewBag.Measure  = _lstcombobox;

            return(View(Model));
        }
示例#5
0
        public bool isError(Item_model Model, int action, out List <string> listError)
        {
            bool flag = false;

            listError = new List <string>();
            if ((int)Common.ActionType.Add == action)
            {
                var result = db.Query <Item_model>("SELECT * FROM `product_item` WHERE `code` = @code", new { code = Model.code.Trim() }).ToList();
                if (result.Count != 0)
                {
                    flag = true;
                    listError.Add("[Code] is duplicate!");
                }
            }
            if ((int)Common.ActionType.Update == action)
            {
                var result = db.Query <Item_model>("SELECT * FROM `product_item` WHERE `code` = @code AND `id` <> @id", new { code = Model.code.Trim(), id = Model.id }).ToList();
                if (result.Count != 0)
                {
                    flag = true;
                    listError.Add("[Code] is duplicate!");
                }
            }
            return(flag);
        }
示例#6
0
        public int Update(Item_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_item` SET ";
                sql += "`category_id` = @category_id, `code` = @code, `name` = @name, `specification` = @specification, ";
                sql += "`description` = @description, `dangerous` = @dangerous, `discontinued_datetime` = @discontinued_datetime, ";
                sql += "`inventory_measure_id` = @inventory_measure_id, `inventory_expired` = @inventory_expired, `inventory_standard_cost` = inventory_standard_cost, ";
                sql += "`inventory_list_price` = inventory_list_price,`manufacture_make` = @manufacture_make, `manufacture_tool` = @manufacture_tool, ";
                sql += "`manufacture_finished_goods` = @manufacture_finished_goods, `manufacture_size` = @manufacture_size, `manufacture_size_measure_id` = @manufacture_size_measure_id, ";
                sql += "`manufacture_weight` = @manufacture_weight, `manufacture_weight_measure_id` = @manufacture_weight_measure_id, `manufacture_style` = @manufacture_style, ";
                sql += "`manufacture_class` = @manufacture_class, `manufacture_color` = @manufacture_color ";
                sql += "WHERE `id` = @id";
                db.Execute(sql, new
                {
                    category_id                   = Model.category_id,
                    id                            = Model.id,
                    code                          = Model.code,
                    name                          = Model.name,
                    specification                 = Model.specification,
                    description                   = Model.description,
                    dangerous                     = Model.dangerous,
                    discontinued_datetime         = Model.discontinued_datetime,
                    inventory_measure_id          = Model.inventory_measure_id,
                    inventory_expired             = Model.inventory_expired,
                    inventory_standard_cost       = Model.inventory_standard_cost,
                    inventory_list_price          = Model.inventory_list_price,
                    manufacture_day               = Model.manufacture_day,
                    manufacture_make              = Model.manufacture_make,
                    manufacture_tool              = Model.manufacture_tool,
                    manufacture_finished_goods    = Model.manufacture_finished_goods,
                    manufacture_size              = Model.manufacture_size,
                    manufacture_size_measure_id   = Model.manufacture_size_measure_id,
                    manufacture_weight            = Model.manufacture_weight,
                    manufacture_weight_measure_id = Model.manufacture_weight_measure_id,
                    manufacture_style             = Model.manufacture_style,
                    manufacture_class             = Model.manufacture_class,
                    manufacture_color             = Model.manufacture_color
                });
            }
            catch (Exception ex)
            {
                returnCode = (int)Common.ReturnCode.UnSuccess;
            }
            return(returnCode);
        }
示例#7
0
        public int Insert(Item_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_item`";
                sql += "(`category_id`, `code`, `name`, `specification`, `description`, `dangerous`, `discontinued_datetime`, ";
                sql += "`inventory_measure_id`, `inventory_expired`, `inventory_standard_cost`, `inventory_list_price`, `manufacture_day`, ";
                sql += "`manufacture_make`, `manufacture_tool`, `manufacture_finished_goods`, `manufacture_size`, `manufacture_size_measure_id`, ";
                sql += "`manufacture_weight`, `manufacture_weight_measure_id`, `manufacture_style`, `manufacture_class`, ";
                sql += "`manufacture_color`) VALUES (@category_id, @code, @name, @specification, @description, @dangerous, @discontinued_datetime, ";
                sql += "@inventory_measure_id, @inventory_expired, @inventory_standard_cost, @inventory_list_price, @manufacture_day, ";
                sql += "@manufacture_make, @manufacture_tool, @manufacture_finished_goods, @manufacture_size, @manufacture_size_measure_id, ";
                sql += "@manufacture_weight, @manufacture_weight_measure_id, @manufacture_style, @manufacture_class, @manufacture_color)";
                db.Execute(sql, new
                {
                    category_id                   = Model.category_id,
                    code                          = Model.code,
                    name                          = Model.name,
                    specification                 = Model.specification,
                    description                   = Model.description,
                    dangerous                     = Model.dangerous,
                    discontinued_datetime         = Model.discontinued_datetime,
                    inventory_measure_id          = Model.inventory_measure_id,
                    inventory_expired             = Model.inventory_expired,
                    inventory_standard_cost       = Model.inventory_standard_cost,
                    inventory_list_price          = Model.inventory_list_price,
                    manufacture_day               = Model.manufacture_day,
                    manufacture_make              = Model.manufacture_make,
                    manufacture_tool              = Model.manufacture_tool,
                    manufacture_finished_goods    = Model.manufacture_finished_goods,
                    manufacture_size              = Model.manufacture_size,
                    manufacture_size_measure_id   = Model.manufacture_size_measure_id,
                    manufacture_weight            = Model.manufacture_weight,
                    manufacture_weight_measure_id = Model.manufacture_weight_measure_id,
                    manufacture_style             = Model.manufacture_style,
                    manufacture_class             = Model.manufacture_class,
                    manufacture_color             = Model.manufacture_color
                });
            }
            catch (Exception ex)
            {
                return((int)Common.ReturnCode.UnSuccess);
            }
            return(returnCode);
        }
        public ActionResult View(int id)
        {
            if (string.IsNullOrEmpty(id.ToString()))
            {
                TempData["Error"] = "Data has already been deleted by other user!";
                return(RedirectToAction("Index"));
            }
            Item_model Model      = new Item_model();
            int        returnCode = _itemBLL.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 Item_model();
            }

            return(View(Model));
        }
示例#9
0
 public int GetDetail(int id, out Item_model model)
 {
     return(item_bll.GetDetail(id, out model));
 }
示例#10
0
 public int Update(Item_model model, out List <string> lstMsg)
 {
     return(item_bll.Update(model, out lstMsg));
 }
示例#11
0
 public int Insert(Item_model model, out List <string> lstMsg)
 {
     return(item_bll.Insert(model, out lstMsg));
 }