Пример #1
0
        public static IdentityProduct ExtractProductData(IDataReader reader)
        {
            var record = new IdentityProduct();

            //Seperate properties;
            record.Id   = Utils.ConvertToInt32(reader["Id"]);
            record.Code = reader["Code"].ToString();
            record.ProductCategoryId = Utils.ConvertToInt32(reader["ProductCategoryId"]);
            record.ProviderId        = Utils.ConvertToInt32(reader["ProviderId"]);
            record.Name = reader["Name"].ToString();
            //record.ShortDescription = reader["ShortDescription"].ToString();
            //record.Detail = reader["Detail"].ToString();
            //record.OtherInfo = reader["OtherInfo"].ToString();
            //record.Cost = reader["Cost"].ToString();
            //record.SaleOffCost = reader["SaleOffCost"].ToString();
            //record.UnitId = Utils.ConvertToInt32(reader["UnitId"]);
            //record.CurrencyId = Utils.ConvertToInt32(reader["CurrencyId"]);
            record.MinInventory = Utils.ConvertToDouble(reader["MinInventory"]);
            record.UnitId       = Utils.ConvertToInt32(reader["UnitId"]);
            //record.CreatedBy = Utils.ConvertToInt32(reader["CreatedBy"]);
            record.CreatedDate = reader["CreatedDate"] == DBNull.Value ? null : (DateTime?)reader["CreatedDate"];
            //record.LastUpdatedBy = reader["LastUpdatedBy"].ToString();
            //record.LastUpdated = reader["LastUpdated"] == DBNull.Value ? null : (DateTime?)reader["LastUpdated"];
            record.Status = Utils.ConvertToInt32(reader["Status"]);

            if (reader.HasColumn("WarehouseNum"))
            {
                record.WarehouseNum = Utils.ConvertToDouble(reader["WarehouseNum"]);
            }

            return(record);
        }
Пример #2
0
        public IdentityProduct GetByCode(string code)
        {
            //Common syntax
            var             sqlCmd = @"Product_GetByCode";
            IdentityProduct info   = null;

            //For parameters
            var parameters = new Dictionary <string, object>
            {
                { "@Code", code }
            };

            try
            {
                using (var conn = new SqlConnection(_connectionString))
                {
                    using (var reader = MsSqlHelper.ExecuteReader(conn, CommandType.StoredProcedure, sqlCmd, parameters))
                    {
                        if (reader.Read())
                        {
                            info = ExtractProductData(reader);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                var strError = "Failed to execute Product_GetByCode. Error: " + ex.Message;
                throw new CustomSQLException(strError);
            }

            return(info);
        }
Пример #3
0
        public ActionResult ReflectStockTake(WarehouseActionModel model)
        {
            var strError = string.Empty;

            try
            {
                var productInfo   = new IdentityProduct();
                var warehouseInfo = new IdentityWarehouse();

                productInfo.Id   = model.ProductId;
                productInfo.Code = model.ItemCode;

                var productStore     = GlobalContainer.IocContainer.Resolve <IStoreProduct>();
                var productInfoCheck = productStore.GetById(model.ProductId);
                if (productInfoCheck == null || (productInfoCheck != null && productInfoCheck.Id <= 0))
                {
                    return(Json(new { success = false, message = ManagerResource.ERROR_PRODUCT_ITEM_NOTFOUND, title = ManagerResource.LB_NOTIFICATION }));
                }
                else
                {
                    productInfo = productInfoCheck;
                }
                //if (model.ProductId <= 0)
                //{
                //    if (!string.IsNullOrEmpty(model.ItemCode))
                //    {
                //        var productStore = GlobalContainer.IocContainer.Resolve<IStoreProduct>();
                //        var productInfoCheck = productStore.GetByCode(model.ItemCode);

                //        if (productInfoCheck == null || (productInfoCheck != null && productInfoCheck.Id <= 0))
                //            return Json(new { success = false, message = string.Format(ManagerResource.ERROR_PRODUCT_ITEM_CODE_NOTFOUND_FORMAT, model.ItemCode), title = ManagerResource.LB_NOTIFICATION, clientcallback = " ShowMyModalAgain();" });
                //        else
                //            productInfo = productInfoCheck;
                //    }
                //}

                //productInfo.WarehouseNum = model.WarehouseNum;
                warehouseInfo.ProductList.Add(productInfo);

                var activityInfo = new IdentityWarehouseActivity();
                activityInfo.ActivityType = (int)EnumWarehouseActivityType.ReflectStockTake;
                activityInfo.DeviceId     = RegisterNewDevice();
                activityInfo.StaffId      = GetCurrentStaffId();

                //Database execute
                _mainStore.ReflectStockTake(warehouseInfo, activityInfo);
            }
            catch (Exception ex)
            {
                strError = ManagerResource.LB_SYSTEM_BUSY;

                logger.Error("Failed to exec ReflectStockTake because: " + ex.ToString());

                return(Json(new { success = false, message = strError }));
            }

            return(Json(new { success = true, message = ManagerResource.LB_GOODS_REFLECT_STOCK_TAKE_SUCCESS, title = ManagerResource.LB_NOTIFICATION, clientcallback = " location.reload()" }));
        }
Пример #4
0
        public ActionResult GoodsReceipt(WarehouseActionModel model)
        {
            var strError = string.Empty;

            try
            {
                var productInfo   = new IdentityProduct();
                var warehouseInfo = new IdentityWarehouse();

                productInfo.Id   = model.ProductId;
                productInfo.Code = model.ItemCode;

                var qty = Utils.ConvertToDouble(model.WarehouseNum);
                if (qty <= 0)
                {
                    return(Json(new { success = false, message = ManagerResource.ERROR_QTY_MUST_LARGE_THAN_0, title = ManagerResource.LB_NOTIFICATION, clientcallback = " ShowMyModalAgain();" }));
                }

                if (model.ProductId <= 0)
                {
                    if (!string.IsNullOrEmpty(model.ItemCode))
                    {
                        var productStore     = GlobalContainer.IocContainer.Resolve <IStoreProduct>();
                        var productInfoCheck = productStore.GetByCode(model.ItemCode);

                        if (productInfoCheck == null || (productInfoCheck != null && productInfoCheck.Id <= 0))
                        {
                            return(Json(new { success = false, message = string.Format(ManagerResource.ERROR_PRODUCT_ITEM_CODE_NOTFOUND_FORMAT, model.ItemCode), title = ManagerResource.LB_NOTIFICATION, clientcallback = " ShowMyModalAgain();" }));
                        }
                        else
                        {
                            productInfo = productInfoCheck;
                        }
                    }
                }

                productInfo.WarehouseNum = qty;
                warehouseInfo.ProductList.Add(productInfo);

                var activityInfo = new IdentityWarehouseActivity();
                activityInfo.ActivityType = (int)EnumWarehouseActivityType.GoodsReceipt;
                activityInfo.DeviceId     = RegisterNewDevice();
                activityInfo.StaffId      = GetCurrentStaffId();

                //Database execute
                _mainStore.GoodsReceipt(warehouseInfo, activityInfo);
            }
            catch (Exception ex)
            {
                strError = ManagerResource.LB_SYSTEM_BUSY;

                logger.Error("Failed to exec GoodsReceipt because: " + ex.ToString());

                return(Json(new { success = false, message = strError }));
            }

            return(Json(new { success = true, message = ManagerResource.LB_GOODS_RECEIPT_SUCCESS, title = ManagerResource.LB_NOTIFICATION, clientcallback = " location.reload()" }));
        }
Пример #5
0
        public ActionResult Index(ManageProductModel model)
        {
            int currentPage = 1;
            int pageSize    = SystemSettings.DefaultPageSize;

            if (string.IsNullOrEmpty(model.SearchExec))
            {
                model.SearchExec = "Y";
                if (!ModelState.IsValid)
                {
                    ModelState.Clear();
                }
            }

            if (Request["Page"] != null)
            {
                currentPage = Utils.ConvertToInt32(Request["Page"], 1);
            }

            var filter = new IdentityProduct
            {
                Keyword           = !string.IsNullOrEmpty(model.Keyword) ? model.Keyword.Trim() : null,
                Status            = model.Status == null ? -1 : (int)model.Status,
                ProductCategoryId = model.ProductCategoryId == null ? 0 : (int)model.ProductCategoryId,
                ProviderId        = model.ProviderId == null ? 0 : (int)model.ProviderId
            };

            try
            {
                model.Providers         = CommonHelpers.GetListProvider();
                model.ProductCategories = CommonHelpers.GetListProductCategory();
                model.Units             = CommonHelpers.GetListUnit();

                model.SearchResults = _mainStore.GetByPage(filter, currentPage, SystemSettings.DefaultPageSize);
                if (model.SearchResults != null && model.SearchResults.Count > 0)
                {
                    model.TotalCount  = model.SearchResults[0].TotalCount;
                    model.CurrentPage = currentPage;
                    model.PageSize    = pageSize;
                }
            }
            catch (Exception ex)
            {
                this.AddNotification(NotifSettings.Error_SystemBusy, NotificationType.ERROR);

                logger.Error("Failed to get data because: " + ex.ToString());

                return(View(model));
            }

            return(View(model));
        }
Пример #6
0
        public ActionResult GetListProductInDropdown()
        {
            var strError = string.Empty;

            try
            {
                var keyword     = (Request["query"] != null) ? Request["query"].ToString() : string.Empty;
                int currentPage = 1;
                int pageSize    = SystemSettings.DefaultPageSize;

                var filter = new IdentityProduct
                {
                    Keyword = !string.IsNullOrEmpty(keyword) ? keyword.Trim() : null
                };

                var listProducts = _mainStore.GetActiveForChoosen(filter, currentPage, pageSize);

                List <ProductItemInDropdownListModel> returnList = new List <ProductItemInDropdownListModel>();

                var listUnits = CommonHelpers.GetListUnit();
                if (listProducts.HasData())
                {
                    foreach (var prd in listProducts)
                    {
                        var item = new ProductItemInDropdownListModel();
                        item.Id           = prd.Id;
                        item.Name         = prd.Name;
                        item.Code         = prd.Code;
                        item.WarehouseNum = Utils.DoubleToStringFormat(prd.WarehouseNum);

                        var currentUnit = listUnits.Where(x => x.Id == prd.UnitId).FirstOrDefault();

                        if (currentUnit != null)
                        {
                            item.UnitName = currentUnit.Name;
                        }

                        returnList.Add(item);
                    }
                }

                return(Json(new { success = true, data = returnList }));
            }
            catch (Exception ex)
            {
                strError = ManagerResource.COMMON_ERROR_EXTERNALSERVICE_TIMEOUT;

                logger.Error("Failed to GetListProductInDropdown because: " + ex.ToString());

                return(Json(new { success = false, data = string.Empty, message = strError }));
            }
        }
Пример #7
0
        private IdentityProduct ExtractCreateFormData(ProductCreateModel formData)
        {
            var myIdetity = new IdentityProduct();

            myIdetity.Name              = formData.Name;
            myIdetity.UnitId            = formData.UnitId;
            myIdetity.ProviderId        = formData.ProviderId;
            myIdetity.ProductCategoryId = formData.ProductCategoryId;
            myIdetity.MinInventory      = Utils.ConvertToDouble(formData.MinInventory);
            myIdetity.Code              = formData.Code;
            myIdetity.CreatedBy         = GetCurrentStaffId();
            myIdetity.Status            = formData.Status;

            return(myIdetity);
        }
Пример #8
0
        public int Insert(IdentityProduct identity)
        {
            //Common syntax
            var sqlCmd = @"Product_Insert";
            var newId  = 0;

            //For parameters
            var parameters = new Dictionary <string, object>
            {
                { "@Code", identity.Code },
                { "@ProductCategoryId", identity.ProductCategoryId },
                { "@ProviderId", identity.ProviderId },
                { "@Name", identity.Name },
                //{"@ShortDescription", identity.ShortDescription },
                //{"@Detail", identity.Detail },
                //{"@OtherInfo", identity.OtherInfo },
                //{"@Cost", identity.Cost },
                //{"@SaleOffCost", identity.SaleOffCost },
                //{"@CurrencyId", identity.CurrencyId },
                { "@MinInventory", identity.MinInventory },
                { "@UnitId", identity.UnitId },
                { "@CreatedBy", identity.CreatedBy },
                //{"@CreatedDate", identity.CreatedDate },
                //{"@LastUpdatedBy", identity.LastUpdatedBy },
                //{"@LastUpdated", identity.LastUpdated },
                { "@Status", identity.Status },
            };

            try
            {
                using (var conn = new SqlConnection(_connectionString))
                {
                    var returnObj = MsSqlHelper.ExecuteScalar(conn, CommandType.StoredProcedure, sqlCmd, parameters);

                    newId = Convert.ToInt32(returnObj);
                }
            }
            catch (Exception ex)
            {
                var strError = "Failed to execute Product_Insert. Error: " + ex.Message;
                throw new CustomSQLException(strError);
            }

            return(newId);
        }
Пример #9
0
        public ActionResult ChoosenProductSearch(ProductChoosenModel model)
        {
            int currentPage = 1;
            int pageSize    = SystemSettings.DefaultPageSize;

            if (Request["Page"] != null)
            {
                currentPage = Utils.ConvertToInt32(Request["Page"], 1);
            }

            if (Request["CurrentPage"] != null)
            {
                currentPage = Utils.ConvertToInt32(Request["CurrentPage"], 1);
            }

            var filter = new IdentityProduct
            {
                Keyword           = !string.IsNullOrEmpty(model.Keyword) ? model.Keyword.Trim() : null,
                ProductCategoryId = model.ProductCategoryId == null ? 0 : (int)model.ProductCategoryId,
                ProviderId        = model.ProviderId == null ? 0 : (int)model.ProviderId
            };

            try
            {
                model.Providers         = CommonHelpers.GetListProvider();
                model.ProductCategories = CommonHelpers.GetListProductCategory();
                model.Units             = CommonHelpers.GetListUnit();

                model.SearchResults = _mainStore.GetActiveForChoosen(filter, currentPage, SystemSettings.DefaultPageSize);
                if (model.SearchResults != null && model.SearchResults.Count > 0)
                {
                    model.TotalCount  = model.SearchResults[0].TotalCount;
                    model.CurrentPage = currentPage;
                    model.PageSize    = pageSize;
                }
            }
            catch (Exception ex)
            {
                this.AddNotification(NotifSettings.Error_SystemBusy, NotificationType.ERROR);

                logger.Error("Failed to show _ChoosenProductList form: " + ex.ToString());
            }

            return(PartialView("_ChoosenProductList", model));
        }
Пример #10
0
        private ProductEditModel RenderEditModel(IdentityProduct identity)
        {
            var editModel = new ProductEditModel();

            editModel.Id                = identity.Id;
            editModel.Name              = identity.Name;
            editModel.UnitId            = identity.UnitId;
            editModel.ProviderId        = identity.ProviderId;
            editModel.ProductCategoryId = identity.ProductCategoryId;
            editModel.Code              = identity.Code;
            editModel.MinInventory      = Utils.DoubleToStringFormat(identity.MinInventory);
            editModel.Status            = identity.Status;
            editModel.Providers         = CommonHelpers.GetListProvider();
            editModel.ProductCategories = CommonHelpers.GetListProductCategory();
            editModel.Units             = CommonHelpers.GetListUnit();

            return(editModel);
        }
Пример #11
0
        public bool Update(IdentityProduct identity)
        {
            //Common syntax
            var sqlCmd = @"Product_Update";

            //For parameters
            var parameters = new Dictionary <string, object>
            {
                { "@Id", identity.Id },
                { "@Code", identity.Code },
                { "@ProductCategoryId", identity.ProductCategoryId },
                { "@ProviderId", identity.ProviderId },
                { "@Name", identity.Name },
                //{"@ShortDescription", identity.ShortDescription },
                //{"@Detail", identity.Detail },
                //{"@OtherInfo", identity.OtherInfo },
                //{"@Cost", identity.Cost },
                //{"@SaleOffCost", identity.SaleOffCost },
                //{"@CurrencyId", identity.CurrencyId },
                { "@MinInventory", identity.MinInventory },
                { "@UnitId", identity.UnitId },
                { "@LastUpdatedBy", identity.LastUpdatedBy },
                { "@Status", identity.Status }
            };

            try
            {
                using (var conn = new SqlConnection(_connectionString))
                {
                    MsSqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, sqlCmd, parameters);
                }
            }
            catch (Exception ex)
            {
                var strError = "Failed to execute Product_Update. Error: " + ex.Message;
                throw new CustomSQLException(strError);
            }

            return(true);
        }
Пример #12
0
        public List <IdentityProduct> GetByPage(IdentityProduct filter, int currentPage, int pageSize)
        {
            //Common syntax
            var sqlCmd = @"Product_GetByPage";
            List <IdentityProduct> listData = null;

            //For paging
            int offset = (currentPage - 1) * pageSize;

            //For parameters
            var parameters = new Dictionary <string, object>
            {
                { "@Keyword", filter.Keyword },
                { "@Status", filter.Status },
                { "@ProviderId", filter.ProviderId },
                { "@ProductCategoryId", filter.ProductCategoryId },
                { "@Offset", offset },
                { "@PageSize", pageSize }
            };

            try
            {
                using (var conn = new SqlConnection(_connectionString))
                {
                    using (var reader = MsSqlHelper.ExecuteReader(conn, CommandType.StoredProcedure, sqlCmd, parameters))
                    {
                        listData = ParsingListFromReader(reader);
                    }
                }
            }
            catch (Exception ex)
            {
                var strError = "Failed to execute Product_GetByPage. Error: " + ex.Message;
                throw new CustomSQLException(strError);
            }

            return(listData);
        }
Пример #13
0
 public List <IdentityProduct> GetActiveForChoosen(IdentityProduct filter, int currentPage, int pageSize)
 {
     return(myRepository.GetActiveForChoosen(filter, currentPage, pageSize));
 }
Пример #14
0
 public bool Update(IdentityProduct identity)
 {
     return(myRepository.Update(identity));
 }
Пример #15
0
 public int Insert(IdentityProduct identity)
 {
     return(myRepository.Insert(identity));
 }
Пример #16
0
 public List <IdentityProduct> GetByPage(IdentityProduct filter, int currentPage, int pageSize)
 {
     return(myRepository.GetByPage(filter, currentPage, pageSize));
 }