Esempio n. 1
0
        /// <summary>
        /// 处理增值税业务中的证书
        /// </summary>
        /// <param name="vat"></param>
        private void CertificateFileHandel(ValueAddedTaxInfo vat)
        {
            string fileIdentity  = vat.CertificateFileName;
            string getConfigPath = AppSettingManager.GetSetting("Customer", "CertificateFilesPath");

            if (!string.IsNullOrEmpty(fileIdentity))
            {
                if (!fileIdentity.Contains(getConfigPath))
                {
                    string fileName = Path.GetFileName(Encoding.UTF8.GetString(Convert.FromBase64String(fileIdentity)));
                    vat.CertificateFileName = getConfigPath + "\\" + fileName;
                    if (!Path.IsPathRooted(getConfigPath))
                    {
                        //是相对路径:
                        getConfigPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, getConfigPath);
                    }
                    string getDestinationPath = Path.Combine(getConfigPath, fileName);
                    string getFolder          = Path.GetDirectoryName(getDestinationPath);
                    if (!Directory.Exists(getFolder))
                    {
                        Directory.CreateDirectory(getFolder);
                    }
                    //将上传的文件从临时文件夹剪切到目标文件夹:
                    FileUploadManager.MoveFile(fileIdentity, getDestinationPath);

                    FileUploadManager.DeleteFile(fileIdentity);
                }
            }
        }
Esempio n. 2
0
        private void MoveFile(string fileIdentity, out string destinationPath)
        {
            string configPath = AppSettingManager.GetSetting("Invoice", "InvoiceReportFilesPath");

            if (!Path.IsPathRooted(configPath))
            {
                configPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, configPath);
            }
            destinationPath = Path.Combine(configPath, fileIdentity);
            string folder = Path.GetDirectoryName(destinationPath);

            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }
            FileUploadManager.MoveFile(fileIdentity, destinationPath);
        }
Esempio n. 3
0
        public string MoveVendorFileAttachments(string fileIdentity)
        {
            string getConfigPath = AppSettingManager.GetSetting("PO", "VendorAttachmentFilesPath");

            if (!Path.IsPathRooted(getConfigPath))
            {
                //是相对路径:
                getConfigPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, getConfigPath);
            }
            string fileName           = Guid.NewGuid().ToString() + FileUploadManager.GetFileExtensionName(fileIdentity);
            string getDestinationPath = Path.Combine(getConfigPath, fileName);
            string getFolder          = Path.GetDirectoryName(getDestinationPath);

            if (!Directory.Exists(getFolder))
            {
                Directory.CreateDirectory(getFolder);
            }
            //将上传的文件从临时文件夹剪切到目标文件夹:
            FileUploadManager.MoveFile(fileIdentity, getDestinationPath);
            return(fileName);
        }
Esempio n. 4
0
        /// <summary>
        /// 上传批量添加中文词库
        /// </summary>
        /// <param name="uploadFileInfo"></param>
        public virtual void BatchImportSegment(string uploadFileInfo)
        {
            //segmentInfoAppService.BatchImportSegment(uploadFileInfo);
            if (FileUploadManager.FileExists(uploadFileInfo))
            {
                string configPath = AppSettingManager.GetSetting("MKT", "PostSegmentInfoFilesPath");
                if (!Path.IsPathRooted(configPath))
                {
                    configPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, configPath);
                }
                string destinationPath = Path.Combine(configPath, uploadFileInfo);
                string folder          = Path.GetDirectoryName(destinationPath);
                if (!Directory.Exists(folder))
                {
                    Directory.CreateDirectory(folder);
                }
                FileUploadManager.MoveFile(uploadFileInfo, destinationPath);

                using (var reader = new StreamReader(destinationPath, Encoding.Default))
                {
                    var lines = new HashSet <string>();
                    while (!reader.EndOfStream)
                    {
                        var value = reader.ReadLine().Trim().Replace("\t", " ");
                        if (!string.IsNullOrEmpty(value))
                        {
                            lines.Add(value);
                        }
                    }

                    if (!lines.Any())
                    {
                        //throw new BizException("导入的txt文件没有任何内容");
                        throw new BizException(ResouceManager.GetMessageString("MKT.Keywords", "Keywords_HasNotActiveDataInTxt"));
                    }

                    if (lines.Count > 2000)
                    {
                        //throw new BizException("导入的关键字不能超过2000个");
                        throw new BizException(ResouceManager.GetMessageString("MKT.Keywords", "Keywords_KeywordsMoreThan2000"));
                    }
                    string companyCode = "8601";    //[Mark][Alan.X.Luo 硬编码]

                    int sameSegment       = 0;
                    int failedSegment     = 0;
                    int seccussfulSegment = 0;
                    lines.Where(e => !string.IsNullOrEmpty(e)).ForEach(e =>
                    {
                        var keywords               = e.Trim();
                        SegmentInfo item           = new SegmentInfo();
                        item.Keywords              = new LanguageContent();
                        item.Keywords.Content      = e;
                        item.Keywords.LanguageCode = "zh-CN";
                        item.CompanyCode           = "8601"; //[Mark][Alan.X.Luo 硬编码]
                        if (keywordDA.CheckSegmentInfo(item))
                        {
                            sameSegment++;
                        }
                        else if (e.Length > 50)
                        {
                            failedSegment++; //also can add a property to counting the case
                        }
                        else
                        {
                            item.Status      = KeywordsStatus.Waiting;
                            item.CompanyCode = companyCode;
                            keywordDA.AddSegmentInfo(item);

                            seccussfulSegment++;
                        }
                    });

                    StringBuilder message = new StringBuilder();
                    if (failedSegment > 0)
                    {
                        //message.AppendLine(failedSegment.ToString() + "条数据导入失败!");
                        message.AppendLine(failedSegment.ToString() + ResouceManager.GetMessageString("MKT.Keywords", "Keywords_ImportFailed"));
                    }

                    if (sameSegment > 0)
                    {
                        //message.AppendLine(sameSegment.ToString() + "条数据已经存在数据库!");
                        message.AppendLine(sameSegment.ToString() + ResouceManager.GetMessageString("MKT.Keywords", "Keywords_AlreadyInDataBase"));
                    }
                    if (seccussfulSegment > 0)
                    {
                        //message.AppendLine(seccussfulSegment.ToString() + "条数据导入成功!");
                        message.AppendLine(seccussfulSegment.ToString() + ResouceManager.GetMessageString("MKT.Keywords", "Keywords_ImportSuccess"));
                    }

                    if (!string.IsNullOrEmpty(message.ToString()))
                    {
                        throw new BizException(message.ToString());
                    }
                }
            }
            else
            {
                //throw new BizException("上传文件丢失!");
                throw new BizException(ResouceManager.GetMessageString("MKT.Keywords", "Keywords_UploadFileLost"));
            }
        }
        public void ConvertBasketTemplateFileToEntityList(string fileIdentity, out int successCount, out int failedCount, out string errorMsg, out List <BasketItemsInfo> failedList)
        {
            //1.移到一个新的文件夹中:
            string getConfigPath = AppSettingManager.GetSetting("PO", "VendorAttachmentFilesPath");

            if (!Path.IsPathRooted(getConfigPath))
            {
                //是相对路径:
                getConfigPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, getConfigPath);
            }
            string fileName           = Guid.NewGuid().ToString() + FileUploadManager.GetFileExtensionName(fileIdentity);
            string getDestinationPath = Path.Combine(getConfigPath, fileName);
            string getFolder          = Path.GetDirectoryName(getDestinationPath);

            if (!Directory.Exists(getFolder))
            {
                Directory.CreateDirectory(getFolder);
            }
            //将上传的文件从临时文件夹剪切到目标文件夹:
            FileUploadManager.MoveFile(fileIdentity, getDestinationPath);

            //2.解析Excel:
            DataTable dt                 = new DataTable();
            int       sCount             = 0;
            int       fCount             = 0;
            string    returnErrorMessage = string.Empty;

            List <string> stockNames = new List <string>();


            //获取仓库信息:
            List <string> validStockSysNo = new List <string>();
            var           configString    = AppSettingManager.GetSetting("PO", "ValidStockSysNo");

            if (!string.IsNullOrEmpty(configString))
            {
                validStockSysNo = configString.Split(',').ToList();
            }

            validStockSysNo.ForEach(x =>
            {
                WarehouseInfo winfo = InventoryBizInteract.GetWarehouseInfoBySysNo(Convert.ToInt32(x));

                if (winfo != null)
                {
                    stockNames.Add(winfo.WarehouseName);
                }
            });

            var connectionString = string.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=Excel 12.0;", Path.GetFullPath(getDestinationPath));

            using (OleDbConnection conn = new OleDbConnection(connectionString))
            {
                try
                {
                    conn.Open();
                    OleDbCommand cmd = new OleDbCommand("select * from [sheet1$]", conn);

                    OleDbDataAdapter adp = new OleDbDataAdapter(cmd);

                    adp.Fill(dt);
                }
                catch (Exception ex)
                {
                    throw new BizException("文件格式不正确!" + "\n" + ex.Message);
                }
            }

            if (dt.Rows.Count == 0)
            {
                throw new BizException("没有可导入的数据");
            }
            else if (dt.Rows.Count > 1000)
            {
                throw new BizException("商品信息超过1000条,请将文件拆分后重新进行上传!");
            }

            List <BasketItemsInfo> importList = new List <BasketItemsInfo>(dt.Rows.Count);

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow row = dt.Rows[i];

                int     vendorSysNo = -1;
                int     quantity    = -1;
                decimal orderPrice  = -1;

                int.TryParse(row[0].ToString().Trim(), out vendorSysNo);
                int.TryParse(row[2].ToString().Trim(), out quantity);
                decimal.TryParse(row[3].ToString().Trim(), out orderPrice);

                BasketItemsInfo importModel = new BasketItemsInfo
                {
                    VendorSysNo = vendorSysNo,
                    ProductID   = row[1].ToString().Trim(),
                    Quantity    = quantity,
                    OrderPrice  = orderPrice,
                    StockName   = row[4].ToString().Trim(),
                    IsTransfer  = row[5].ToString().Trim() != "是" && row[5].ToString().Trim() != "否" ? (int?)null : (row[5].ToString().Trim() == "是" ? 1 : 0)
                };

                importList.Add(importModel);
            }

            var query = from g in
                        (from item in importList
                         group item by new { item.VendorSysNo, item.ProductID, item.StockName }
                         into importGroup
                         select importGroup)
                        where g.Count() > 1
                        select g;

            if (query.Count() > 0)
            {
                var message = new StringBuilder("上传文件中存在重复记录:" + Environment.NewLine);

                foreach (var g in query)
                {
                    message.AppendFormat("供应商编号:{0}  商品编号:{1}  目标分仓:{2}{3}", g.Key.VendorSysNo, g.Key.ProductID, g.Key.StockName, Environment.NewLine);
                }

                throw new BizException(message.ToString());
            }

            List <BasketItemsInfo> messageList = new List <BasketItemsInfo>();

            failedList = new List <BasketItemsInfo>();

            foreach (var item in importList)
            {
                try
                {
                    BasketItemsInfo basketItem = new BasketItemsInfo();

                    if (item.VendorSysNo > 0)
                    {
                        int vendorSysNo;

                        if (Int32.TryParse(item.VendorSysNo.ToString(), out vendorSysNo))
                        {
                            basketItem.LastVendorSysNo = vendorSysNo;
                        }
                        else
                        {
                            throw new BizException("【供应商编号】有非法的值,必须是有效的供应商");
                        }
                    }
                    else
                    {
                        throw new BizException("【供应商编号】有非法的值,必须是有效的供应商");
                    }

                    if (string.IsNullOrEmpty(item.ProductID))
                    {
                        throw new BizException("【商品编号】有非法的值,必须是有效的商品编号");
                    }
                    else
                    {
                        basketItem.ProductID = item.ProductID;
                    }

                    if (item.OrderPrice < 0)
                    {
                        throw new BizException("【采购价格】不能为空");
                    }
                    else
                    {
                        basketItem.OrderPrice = Convert.ToDecimal(item.OrderPrice);
                    }

                    if (!item.IsTransfer.HasValue)
                    {
                        throw new BizException("【是否中转】有非法的值,必须为'是'或者'否'");
                    }
                    else
                    {
                        basketItem.IsTransfer = item.IsTransfer;
                    }

                    if (item.Quantity < 0)
                    {
                        throw new BizException("【数量】有非法的值,必须输入大于零的整数");
                    }
                    else
                    {
                        basketItem.Quantity = item.Quantity;
                    }

                    if (item.OrderPrice >= 0)
                    {
                        decimal orderPrice;

                        if (decimal.TryParse(item.OrderPrice.ToString(), out orderPrice))
                        {
                            if (orderPrice > 0)
                            {
                                basketItem.OrderPrice = orderPrice;
                            }
                            else
                            {
                                throw new BizException("【订购价格】有非法的值,必须为大于零的数");
                            }
                        }
                        else
                        {
                            throw new BizException("【订购价格】有非法的值,必须为大于零的数");
                        }
                    }

                    if (string.IsNullOrEmpty(item.StockName) ||
                        !stockNames.Contains(item.StockName))
                    {
                        throw new BizException(string.Format("【目标分仓】有非法的值,必须为:{0}", String.Join("、", stockNames.ToArray())));
                    }
                    else
                    {
                        basketItem.StockName = item.StockName;
                    }

                    messageList.Add(basketItem);
                }
                catch (BizException ex)
                {
                    item.ErrorMessage = ex.Message;
                    failedList.Add(item);
                }
                catch (Exception)
                {
                    //TODO:定message
                    item.ErrorMessage = "验证数据时出现未知错误";
                }
            }

            //调用服务,写入到采购篮中:
            List <BasketItemsInfo> returnItemsList = new List <BasketItemsInfo>();

            if (messageList.Count > 0)
            {
                returnItemsList = PurchaseOrderBasketProcessor.BatchImportAndCreateBasketItem(messageList, false);
                //构建失败列表并返回:
                for (int i = 0; i < returnItemsList.Count; i++)
                {
                    if (!string.IsNullOrEmpty(returnItemsList[i].ErrorMessage))
                    {
                        fCount++;
                        failedList.Add(returnItemsList[i]);
                    }
                    else
                    {
                        sCount++;
                    }
                }
                ;
            }

            for (int i = 0; i < failedList.Count; i++)
            {
                returnErrorMessage += (i + 1) + ":" + failedList[i].ErrorMessage.ToString() + Environment.NewLine;
            }

            successCount = sCount;
            failedCount  = failedList.Count;
            errorMsg     = returnErrorMessage;
        }
Esempio n. 6
0
        /// <summary>
        /// 批量添加产品页面关键字
        /// </summary>
        /// <param name="item"></param>
        //public virtual void AddProductPageKeywords(ProductPageKeywords item)
        //{
        //    keywordDA.AddProductPageKeywords(item);
        //}

        /// <summary>
        /// 上传批量添加产品页面关键字
        /// </summary>
        /// <param name="uploadFileInfo"></param>
        public virtual void BatchImportProductKeywords(string uploadFileInfo)
        {
            if (FileUploadManager.FileExists(uploadFileInfo))
            {
                string configPath = AppSettingManager.GetSetting("MKT", "PostProductKeywordsFilePath");
                if (!Path.IsPathRooted(configPath))
                {
                    configPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, configPath);
                }
                string ExtensionName   = FileUploadManager.GetFilePhysicalFullPath(uploadFileInfo);
                string destinationPath = Path.Combine(configPath, ExtensionName);
                string folder          = Path.GetDirectoryName(destinationPath);
                if (!Directory.Exists(folder))
                {
                    Directory.CreateDirectory(folder);
                }
                FileUploadManager.MoveFile(uploadFileInfo, destinationPath);


                DataTable table = keywordDA.ReadExcelFileToDataTable(destinationPath);
                if (table != null && table.Rows != null && table.Rows.Count > 0)
                {
                    if (table.Columns[0].ColumnName == "Item No#")
                    {
                        string        ProductID   = string.Empty;
                        List <string> ProductList = new List <string>();
                        for (int i = 0; i < table.Rows.Count; i++)
                        {
                            if (table.Rows[i]["Item No#"] != DBNull.Value &&
                                !string.IsNullOrEmpty(table.Rows[i]["Item No#"].ToString()))
                            {
                                ProductID = table.Rows[i]["Item No#"] == null ? string.Empty : table.Rows[i]["Item No#"].ToString().Trim();

                                if (!ProductList.Contains(ProductID))
                                {
                                    ProductList.Add(ProductID);
                                }
                            }
                        }
                        int count = string.IsNullOrEmpty(AppSettingManager.GetSetting("MKT", "ProductKeywordsExcelBatchCount")) ? 100 : int.Parse(AppSettingManager.GetSetting("MKT", "ProductKeywordsExcelBatchCount"));
                        if (ProductList.Count > count)
                        {
                            //throw new BizException(string.Format("导入的条数超过限制,最大{0}条!", count.ToString()));
                            throw new BizException(string.Format(ResouceManager.GetMessageString("MKT.Keywords", "Keywords_LimitCount"), count.ToString()));
                        }
                        else if (ProductList.Count == 0)
                        {
                            //throw new BizException("导入的Excel无有效数据,导入失败!");
                            throw new BizException(ResouceManager.GetMessageString("MKT.Keywords", "Keywords_HasNotActiveData"));
                        }
                        else
                        {
                            foreach (string id in ProductList)
                            {
                                //[Mark][Alan.X.Luo 硬编码]
                                keywordDA.InsertProductKeywordsListBatch(id, "8601");
                            }
                        }
                    }
                    else
                    {
                        //throw new BizException("导入的Excel文件列名无效!");
                        throw new BizException(ResouceManager.GetMessageString("MKT.Keywords", "Keywords_HasNotActiveData"));
                    }
                }
                else
                {
                    //throw new BizException("Execl中没有数据,或者工作簿名称不是Sheet1或者格式不正确!");
                    throw new BizException(ResouceManager.GetMessageString("MKT.Keywords", "Keywords_HasNotActiveData"));
                }
            }
        }