Ejemplo n.º 1
0
        public static string GetStatusLayout(int status)
        {
            switch (status)
            {
            case (int)DeliveryStatusEnum.New:
                return(LangHelper.Get("Delivery_Entity_Status_Enum_New"));             // 新建货运单

            case (int)DeliveryStatusEnum.Submit:
                return(LangHelper.Get("Delivery_Entity_Status_Enum_Submited"));        // 提交

            case (int)DeliveryStatusEnum.Processing:
                return(LangHelper.Get("Delivery_Entity_Status_Enum_Processing"));      // 处理中

            case (int)DeliveryStatusEnum.Delivering:
                return(LangHelper.Get("Delivery_Entity_Status_Enum_Delivering"));      // 运输中

            case (int)DeliveryStatusEnum.BadOrder:
                return(LangHelper.Get("Delivery_Entity_Status_Enum_BadOrder"));        // 坏单

            case (int)DeliveryStatusEnum.Cancel:
                return(LangHelper.Get("Delivery_Entity_Status_Enum_Cancel"));          // 取消

            case (int)DeliveryStatusEnum.Received:
                return(LangHelper.Get("Delivery_Entity_Status_Enum_Received"));        // 已收货

            case (int)DeliveryStatusEnum.Error:
                return(LangHelper.Get("Delivery_Entity_Status_Enum_Error"));           // 异常

            case (int)DeliveryStatusEnum.Success:
                return(LangHelper.Get("Delivery_Entity_Status_Enum_Success"));         // 成功

            default:
                return("undefined");
            }
        }
Ejemplo n.º 2
0
        // DataType: 数据类型
        public static string GetDataTypeLayout(int dataType)
        {
            switch (dataType)
            {
            case (int)DataTypeEnum.Inventory:
                return(LangHelper.Get("MapRule_Entity_DataType_Enum_Inventory"));    // 库存记录 Inventory

            case (int)DataTypeEnum.Delivery:
                return(LangHelper.Get("MapRule_Entity_DataType_Enum_Delivery"));    // 货运记录 Delivery

            default:
                return("undefined");
            }
        }
Ejemplo n.º 3
0
        public static string GetAssTypeLayout(int AssType)
        {
            switch (AssType)
            {
            case (int)AssTypeEnum.Export:
                return(LangHelper.Get("MapRule_Entity_AssType_Enum_Export"));    // 导出 Export

            case (int)AssTypeEnum.Import:
                return(LangHelper.Get("MapRule_Entity_AssType_Enum_Import"));    // 导入 Import

            default:
                return("undefined");
            }
        }
Ejemplo n.º 4
0
        public static string GetTypeLayout(int storeType)
        {
            switch (storeType)
            {
            case (int)StoreTypeEnum.SolidStore:
                return(LangHelper.Get("Store_Entity_Type_Enum_SolidStore"));

            case (int)StoreTypeEnum.SmartWarehouse:
                return(LangHelper.Get("Store_Entity_Type_Enum_SmartWarehouse"));

            default:
                return("undefined");
            }
        }
Ejemplo n.º 5
0
        public static string GetDeliveryTypeLayout(int deliveryType)
        {
            switch (deliveryType)
            {
            case (int)DeliveryTypeEnum.Transfer:
                return(LangHelper.Get("Delivery_Entity_Type_Enum_Transfer"));          // 调拨

            case (int)DeliveryTypeEnum.PurchaseIn:
                return(LangHelper.Get("Delivery_Entity_Type_Enum_PurchaseIn"));        // 购货入库

            case (int)DeliveryTypeEnum.SellingOut:
                return(LangHelper.Get("Delivery_Entity_Type_Enum_SellingOut"));        // 销售出库

            default:
                return("undefined");
            }
        }
Ejemplo n.º 6
0
        public static string GetChangeTypeLayout(int changeType)
        {
            switch (changeType)
            {
            case (int)InventoryLogTypeEnum.Delivery:
                return(LangHelper.Get("InventoryLog_Entity_Type_Enum_Delivery"));             // 由货运单影响: Updated by Delivery

            case (int)InventoryLogTypeEnum.Adjustment:
                return(LangHelper.Get("InventoryLog_Entity_Type_Enum_Adjustment"));           // 由库存调整影响:Updated by Adjustment

            case (int)InventoryLogTypeEnum.Import:
                return(LangHelper.Get("InventoryLog_Entity_Type_Enum_Import"));               // 由导入影响:Updated by Import

            default:
                return("undefined");
            }
        }
Ejemplo n.º 7
0
        public static string GetFileTypeLayout(int fileType)
        {
            switch (fileType)
            {
            case (int)FileTypeEnum.XLS:
                return(LangHelper.Get("FileData_Entity_FileType_Enum_XLS"));        // .xls excel 2003 format

            case (int)FileTypeEnum.XLSX:
                return(LangHelper.Get("FileData_Entity_FileType_Enum_XLSX"));       // .xlsx excel 2007 above format

            case (int)FileTypeEnum.CSV:
                return(LangHelper.Get("FileData_Entity_FileType_Enum_CSV"));        // .csv with delimited format

            default:
                return("undefined");
            }
        }
Ejemplo n.º 8
0
        public static string GetProcessTypeLayout(int processType)
        {
            switch (processType)
            {
            case (int)FileProcessTypeEnum.All:
                return(LangHelper.Get("FileData_Entity_ProcessType_Enum_All"));

            case (int)FileProcessTypeEnum.NewOnly:
                return(LangHelper.Get("FileData_Entity_ProcessType_Enum_NewOnly"));

            case (int)FileProcessTypeEnum.UpdateOnly:
                return(LangHelper.Get("FileData_Entity_ProcessType_Enum_UpdateOnly"));

            default:
                return("undefined");
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Export a excel stream by the inventory query.
        /// </summary>
        /// <param name="queryInventory">the query of inventory</param>
        /// <param name="submitMapRule">the map rule submit</param>
        /// <returns>Excel memory stream</returns>
        public JsonNetPackResult Export(FileData submitFileData, Inventory queryInventory)
        {
            string message      = LangHelper.Get("Inventory_Result_Success_ExportSuccess");
            string downloadPath = "";                          // the return donwload path
            int    totalCount   = 0;                           // the data count in database
            int    successCount = 0;                           // the success exported row count
            int    duration     = 0;                           // the process duration
            int    status       = (int)FileStatusEnum.Success; // the export status

            // 把用户定义的EXCEL文件名拼后缀为完成名: export_20160905030507 + .xlsx
            submitFileData.FileName = FileData.GetFullExportFileName(submitFileData.FileType, submitFileData.FileName);

            try
            {
                using (db)
                { // transation 习惯使用using以保证数据操作在事务内
                    var           inventoryQueryList = GetInventoryQueryList(queryInventory);
                    List <Object> inventoryDataList  = inventoryQueryList.ToList <Object>();
                    totalCount = inventoryDataList.Count;

                    List <MapRuleItem> submitMapRuleItemList = submitFileData.MapRule.RuleItemList.ToList();// map rule item list.

                    MemoryStream ms = ExcelHelper.GetExportMemoryStream(typeof(Inventory), inventoryDataList, submitFileData, out successCount);
                    downloadPath = GenerateExportFile(ms, submitFileData.FileName);    // get the down load path by store the stream in server file

                    submitFileData.ProcessType      = (int)FileProcessTypeEnum.All;
                    submitFileData.FileName         = submitFileData.FileName;
                    submitFileData.Status           = status;
                    submitFileData.TotalCount       = totalCount;
                    submitFileData.SuccessCount     = successCount;
                    submitFileData.Duration         = duration;
                    submitFileData.UpdateEmployeeID = CurrentEmployee.ID;
                    submitFileData.UpdateDate       = CurrentUpdateDate;
                    db.FileDatasDB.Add(submitFileData);
                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
                return(new JsonNetPackResult(ERROR, e.Message, submitFileData));
            }

            message = String.Format(message, totalCount, successCount);
            return(new JsonNetPackResult(SUCCESS, message, submitFileData));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Epacket Add Package:
        /// 1. check the param data correct or not
        /// 2. check there are enough inventory
        /// 3. call the epacket add package api and response the track code
        /// 4. if #3 succeed, create new delivery(new->process), add items from apiRequest
        /// 5. add shipment and shipData( we will save the api request full data in stream object to database)
        /// </summary>
        /// <param name="employeeID">the employee who call this method</param>
        /// <param name="carrierID">the carrier caller defined</param>
        /// <param name="srcStoreID">the store which will out post the items</param>
        /// <param name="myRequest">the epacket api request</param>
        /// <param name="debugDON">default should be null, it is for the initial data importing</param>
        /// <returns>
        /// A formated return data:
        /// JsonNetPackResult.message:  if success, it return the DON number, otherwise, return the error message
        /// JsonApiReturnData.ApiRequest: the api calling request
        /// JsonApiReturnData.ApiResponse: the api calling response
        /// JsonApiReturnData.BizData: a full data of a delivery , containing delivery info, shipment info, src store info and so on.
        /// </returns>
        public JsonNetPackResult AddPackage(int employeeID, int carrierID, int srcStoreID, AddAPACPackageRequest myRequest, Boolean debug)
        {
            AddAPACPackageResponse myResponse = new AddAPACPackageResponse();

            if (debug)   // if debug , generate a test request
            {
                myRequest = GenTestAddPackageRequest();
            }

            Delivery newDelivery = null;

            // 1. check the param data correct or not
            Employee employee = db.EmployeesDB.Find(employeeID);

            if (employee == null)
            {
                return(new JsonNetPackResult(ERROR, "Employee not exist", new JsonApiReturnData(myRequest, myResponse, newDelivery)));
            }

            Carrier carrier = db.CarriersDB.Find(carrierID);

            if (carrier == null)
            {
                return(new JsonNetPackResult(ERROR, "Carrier not exist", new JsonApiReturnData(myRequest, myResponse, newDelivery)));
            }
            Store srcStore = db.StoresDB.Find(srcStoreID);

            if (srcStore == null)
            {
                return(new JsonNetPackResult(ERROR, "Store not exist", new JsonApiReturnData(myRequest, myResponse, newDelivery)));
            }

            EpacketAuth epacketAuth = carrier.Auth;

            if (epacketAuth == null)
            {
                return(new JsonNetPackResult(ERROR, "Auth not exist", new JsonApiReturnData(myRequest, myResponse, newDelivery)));
            }

            CommonHelper.CopyObjectValue(epacketAuth, myRequest.Auth); // 把carrier里面的auth 复制赋值到apiRequest.auth

            try
            {
                using (db)
                { // transation 习惯使用using以保证数据操作在事务内
                    // 2. check there are enough inventory 先判断是否有这个SKU,并且够数目
                    foreach (Item reqItem in myRequest.ItemList)
                    {
                        string    sku       = reqItem.SKUID;
                        int       postedQTY = reqItem.PostedQTY;
                        Inventory srcInv    = GetInventory(srcStore.ID, sku);

                        if (srcInv == null)
                        {
                            return(new JsonNetPackResult(ERROR, "Sorry,Sku " + sku + " not exist in " + srcStore.Name, new JsonApiReturnData(myRequest, myResponse, newDelivery)));
                        }

                        if (postedQTY > srcInv.Avail)
                        {
                            return(new JsonNetPackResult(ERROR, "Sorry,Sku " + sku + " not enough avail", new JsonApiReturnData(myRequest, myResponse, newDelivery)));
                        }
                    }
                    // 3. call the epacket add package api and response the track code 进行调用,如果有错误,返回之

                    string trackCode = "";

                    if (debug)                                                                          // debug
                    {
                        string ramStr = "TEST" + (new Random().Next(0, 99)).ToString().PadLeft(2, '0'); // ram number(0~100) , add zero to left
                        trackCode = ramStr;
                    }
                    else   // not debug

                    {
                        myResponse = myCall.AddAPACShippingPackage(myRequest);
                        if ((myResponse.Ack.ToUpper() != "SUCCESS") && (String.IsNullOrEmpty(myResponse.TrackCode)))
                        {
                            return(new JsonNetPackResult(ERROR, "Epacket API Calling Fail, More information please see Data.ApiResponse", new JsonApiReturnData(myRequest, myResponse, newDelivery)));
                        }
                        trackCode = myResponse.TrackCode;
                    }



                    // 接口调用成功,并且检查数据正常,则创建Delivery
                    newDelivery = new Delivery();
                    newDelivery.DeliveryType   = (int)DeliveryTypeEnum.SellingOut;
                    newDelivery.CarrierID      = carrierID;
                    newDelivery.SrcStoreID     = srcStoreID;
                    newDelivery.SrcStore       = null;
                    newDelivery.TarStoreID     = null;
                    newDelivery.ClientID       = employee.ClientID;
                    newDelivery.Client         = null;
                    newDelivery.UpdateEmployee = null;
                    newDelivery.Status         = (int)DeliveryStatusEnum.Processing;
                    newDelivery.DON            = GenerateNumber(employee.ClientID);


                    newDelivery.UpdateEmployeeID = employee.ID;
                    newDelivery.UpdateDate       = CurrentUpdateDate;
                    newDelivery.Version          = 1;
                    db.DeliveriesDB.Add(newDelivery);
                    db.SaveChanges();

                    List <DeliveryItem> newDyItemList = new List <DeliveryItem>();
                    // 接口调用的sku items塞进这个Delivery
                    if (myRequest.ItemList != null)
                    {
                        foreach (Item reqItem in myRequest.ItemList)
                        {
                            DeliveryItem dyItem = new DeliveryItem();
                            Product      prod   = db.ProductsDB.Where(p => p.SKU == reqItem.SKUID).First();

                            dyItem.ProductID        = prod.ID;
                            dyItem.OutQty           = reqItem.PostedQTY;
                            dyItem.UpdateDate       = new DateTime(DateTime.Now.Ticks);
                            dyItem.Product          = null;
                            dyItem.UpdateEmployee   = null;
                            dyItem.UpdateEmployeeID = employee.ID;
                            dyItem.UpdateDate       = CurrentUpdateDate;
                            dyItem.DeliveryID       = newDelivery.ID;
                            newDyItemList.Add(dyItem);
                        }
                    }
                    db.DeliveryItemsDB.AddRange(newDyItemList);
                    db.SaveChanges();

                    // Log Delivery
                    int dyLogID = 0;

                    if (!debug)
                    {
                        dyLogID = LogDeliveryChange(db, newDelivery.ID, (int)DeliveryStatusEnum.New, (int)DeliveryStatusEnum.Processing);
                    }


                    // 影响Inventory的可用
                    foreach (DeliveryItem outItem in newDyItemList)
                    {
                        Inventory srcInv = GetInventory(srcStore.ID, outItem.ProductID);

                        Inventory srcInv1 = (Inventory)srcInv.Clone();

                        if (srcInv == null)
                        { // check if inventory exist~
                            String msg = string.Format(LangHelper.Get("Product_Empty"), outItem.Product.SKU, srcStore.Name);
                            return(new JsonNetPackResult(ERROR, msg, new JsonApiReturnData(myRequest, myResponse, newDelivery)));
                        }

                        srcInv.Avail -= outItem.OutQty;
                        if (srcInv.Avail < 0)
                        {
                            String msg = string.Format(LangHelper.Get("Delivery_Avail_Not_Enough"), srcStore.Name, outItem.OutQty, srcInv.Avail);
                            return(new JsonNetPackResult(ERROR, msg, 0));
                        }
                        srcInv.OnHold          += outItem.OutQty;
                        srcInv.UpdateEmployeeID = employee.ID;
                        srcInv.UpdateDate       = CurrentUpdateDate;

                        Inventory srcInv2 = (Inventory)srcInv.Clone();

                        // Log Inventory
                        if (!debug)
                        {
                            int invLogID = LogInventoryChange(db, srcInv.ID, dyLogID, srcInv1, srcInv2);
                        }
                    }
                    db.SaveChanges();

                    // 创建Shipment
                    Shipment newShipment = new Shipment();
                    newShipment.DeliveryID       = newDelivery.ID;
                    newShipment.UpdateEmployeeID = employee.ID;
                    newShipment.TrackCode        = trackCode;
                    newShipment.UpdateDate       = CurrentUpdateDate;
                    db.ShipmentsDB.Add(newShipment);
                    db.SaveChanges();

                    // 创建EpackageShipData
                    EpacketShipData newShipData = new EpacketShipData();
                    newShipData.ShipmentID        = newShipment.ID;
                    newShipData.UpdateEmployeeID  = employee.ID;
                    newShipData.UpdateDate        = CurrentUpdateDate;
                    newShipData.PackageStreamData = new JsonNetResult(myRequest).ToJsonString();
                    db.EpacketShipDatasDB.Add(newShipData);
                    db.SaveChanges();

                    newDelivery = db.DeliveriesDB.Find(newDelivery.ID);
                }

                // 构造一个完整并返回

                return(new JsonNetPackResult(SUCCESS, newDelivery.DON, new JsonApiReturnData(myRequest, myResponse, newDelivery)));
            }
            catch (Exception e)
            {
                return(new JsonNetPackResult(ERROR, e.StackTrace, new JsonApiReturnData(myRequest, myResponse, newDelivery)));
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Read the Excel File and get the data list , import into our database
        /// </summary>
        /// <param name="submitFileData">submitFileData from UI</param>
        /// <returns>Json net pack result: containing success or error, and the imported row total counts </returns>
        public JsonNetPackResult Import(FileData submitFileData, int storeID)
        {
            string message      = LangHelper.Get("Inventory_Result_Success_ImportSuccess");
            int    totalCount   = 0;                            // the row count in imported excel
            int    successCount = 0;                            // the success count update db
            int    duration     = 0;                            // the process duration
            int    status       = (int)FileStatusEnum.Success;  // the import status


            // 检查 storeID是否有:必须要选择一个Store进行导入
            if (storeID < 1)
            {
                return(new JsonNetPackResult(ERROR, LangHelper.Get("Inventory_Result_Error_ImportStoreNoSelect"), 0));
            }

            // 检查文件后缀名是否正确:用FileType与当前上传文件后缀名对比!
            string suffix = submitFileData.UploadFile.FileName.Substring(submitFileData.UploadFile.FileName.LastIndexOf(".")).ToLower();//获取后缀

            if ((submitFileData.FileType == (int)FileTypeEnum.XLS) && (!suffix.ToLower().Equals(".xls")))
            { //2003
                // not a excel 2003 format file, it is not.xls file : 上传文件不是.xls Excel 2003 文件
                return(new JsonNetPackResult(ERROR, LangHelper.Get("FileData_Result_Error_NotXLS"), 0));
            }

            if ((submitFileData.FileType == (int)FileTypeEnum.XLSX) && (!suffix.ToLower().Equals(".xlsx")))
            { //2007
                // not a excel 2007 format file, it is not.xlsx file : 上传文件不是.xlsx Excel 2007 文件
                return(new JsonNetPackResult(ERROR, LangHelper.Get("FileData_Result_Error_NotXLSX"), 0));
            }

            if ((submitFileData.FileType == (int)FileTypeEnum.CSV) && (!suffix.ToLower().Equals(".csv")))
            { //csv
                // not a excel 2007 format file, it is not.xlsx file : 上传文件不是.csv文件
                return(new JsonNetPackResult(ERROR, LangHelper.Get("FileData_Result_Error_NotCSV"), 0));
            }

            try
            {
                using (db)
                { // transation 习惯使用using以保证数据操作在事务内
                    List <MapRuleItem> submitMapRuleItemList = submitFileData.MapRule.RuleItemList.ToList();
                    List <Object>      importInventoryList   = ExcelHelper.GetImportDataList(typeof(Inventory), submitFileData, out totalCount);

                    // the store you will import.
                    Store effStore = db.StoresDB.Find(storeID);

                    foreach (object obj in importInventoryList)
                    {
                        // Lion: 这里处理到数据库
                        Inventory inv          = (Inventory)obj;
                        int       existProduct = db.ProductsDB.Count(p => p.SKU == inv.Product.SKU);

                        if (existProduct == 0)//product.sku not exist
                        {
                            string msg = LangHelper.Get("Inventory_Result_Error_ImportSkuNotExist");
                            msg = string.Format(msg, inv.Product.SKU);
                            return(new JsonNetPackResult(ERROR, msg, 0));
                        }


                        Product product  = db.ProductsDB.Where(p => p.SKU == inv.Product.SKU).First();
                        int     existInv = db.InventoriesDB.Where(i => i.StoreID == storeID).Count(i => i.ProductID == product.ID);


                        if (existInv == 0)//  Inventory not exist the product insert new  inv
                        {
                            if ((submitFileData.ProcessType == (int)FileProcessTypeEnum.All) ||
                                (submitFileData.ProcessType == (int)FileProcessTypeEnum.NewOnly))
                            { // allow add!
                                Inventory newInv = new Inventory();
                                newInv.ProductID        = product.ID;
                                newInv.StoreID          = storeID;
                                newInv.Avail            = inv.Avail;
                                newInv.OnOut            = inv.OnOut;
                                newInv.OnIn             = inv.OnIn;
                                newInv.InSum            = inv.InSum;
                                newInv.OutSum           = inv.OutSum;
                                newInv.ShipMiss         = inv.ShipMiss;
                                newInv.OnHold           = inv.OnHold;
                                newInv.DiffSum          = inv.DiffSum;
                                newInv.UpdateEmployeeID = CurrentEmployee.ID;
                                newInv.UpdateDate       = CurrentUpdateDate;
                                successCount++;
                                db.InventoriesDB.Add(newInv);
                            }
                        }
                        else // Inventory  exist the product  update this
                        {
                            if ((submitFileData.ProcessType == (int)FileProcessTypeEnum.All) ||
                                (submitFileData.ProcessType == (int)FileProcessTypeEnum.UpdateOnly))
                            { // allow update!
                                Inventory getInv = db.InventoriesDB.Where(i => i.StoreID == storeID).Where(i => i.ProductID == product.ID).First();
                                getInv.Avail           += (inv.Avail == null ? 0 : inv.Avail);
                                getInv.OnOut           += (inv.OnOut == null ? 0 : inv.OnOut);
                                getInv.OnIn            += (inv.OnIn == null ? 0 : inv.OnIn);
                                getInv.InSum           += (inv.InSum == null ? 0 : inv.InSum);
                                getInv.OutSum          += (inv.OutSum == null ? 0 : inv.OutSum);
                                getInv.ShipMiss        += (inv.ShipMiss == null ? 0 : inv.ShipMiss);
                                getInv.OnHold          += (inv.OnHold == null ? 0 : inv.OnHold);
                                getInv.DiffSum         += (inv.DiffSum == null ? 0 : inv.DiffSum);
                                getInv.UpdateEmployeeID = CurrentEmployee.ID;
                                getInv.UpdateDate       = CurrentUpdateDate;
                                successCount++;
                            }
                        }
                    }


                    submitFileData.FileName         = submitFileData.UploadFile.FileName;
                    submitFileData.Status           = status;
                    submitFileData.TotalCount       = totalCount;
                    submitFileData.SuccessCount     = successCount;
                    submitFileData.Duration         = duration;
                    submitFileData.UpdateEmployeeID = CurrentEmployee.ID;
                    submitFileData.UpdateDate       = CurrentUpdateDate;
                    submitFileData.UploadFile       = null; // 把上传文件清空,避免返回数据量过大!
                    db.FileDatasDB.Add(submitFileData);
                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
                return(new JsonNetPackResult(ERROR, e.Message, submitFileData));
            }


            message = String.Format(message, totalCount, successCount);
            return(new JsonNetPackResult(SUCCESS, message, submitFileData));
        }