Beispiel #1
0
        public ActionResult ExcelUploadClick(string importDataType)
        {
            var result = new DirectResult();

            var fileUploadField = this.GetCmp <FileUploadField>("fileUploadField");

            if (fileUploadField.HasFile)
            {
                var excelImportManager = new ExcelImportManager();
                try
                {
                    string orgNamePath = GetOrganizationNamePath();
                    string createBy    = GetCurrentUserName();
                    string areaPath    = GetOrganizationAreaPath();
                    excelImportManager.ImportData(importDataType, fileUploadField.PostedFile.InputStream, areaPath, orgNamePath, createBy);
                    if (string.IsNullOrEmpty(excelImportManager.ErrorInfo))
                    {
                        X.Msg.Show(MessageBoxConfig(Success, TiShi, MessageBox.Icon.INFO));
                    }
                    else
                    {
                        X.Msg.Show(MessageBoxConfig(Success + "<br/>" + excelImportManager.ErrorInfo, TiShi, MessageBox.Icon.INFO));
                    }
                }
                catch (Exception ex)
                {
                    X.Msg.Show(MessageBoxConfig(ex.ToString(), Fail, MessageBox.Icon.INFO));
                }
            }
            else
            {
                result.IsUpload = true;
                X.Msg.Show(MessageBoxConfig(NoFile, TiShi, MessageBox.Icon.ERROR));
            }


            return(result);
        }
Beispiel #2
0
        private void toolStripDropDownButton1_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            var item = sender as ToolStripDropDownButton;
            if (item != null) _billType = e.ClickedItem.Text;
            var result = openFileDialog1.ShowDialog();
            if (result == DialogResult.Cancel) return;

            var excelPath = openFileDialog1.FileName;
            var excelImportManager = new ExcelImportManager();
            //try
            //{
            switch (_billType)
            {
                case "请购单":
                    _list = excelImportManager.Import<PurchaseRequisition>(excelPath);
                    break;
                case "采购订单":
                    _list = excelImportManager.Import<PurchaseOrder>(excelPath);
                    break;
                case "进货单":
                    _list = excelImportManager.Import<PurchaseArrival>(excelPath);
                    break;
                case "采购入库单":
                    _list = excelImportManager.Import<InputWarehouse>(excelPath);
                    break;
                case "报价单":
                    _list = excelImportManager.Import<SaleQuotation>(excelPath);
                    break;
                case "销售订单":
                    _list = excelImportManager.Import<SaleOrder>(excelPath);
                    break;
                case "销售出库单":
                    _list = excelImportManager.Import<OutputWarehouse>(excelPath);
                    break;
                case "销货单":
                    _list = excelImportManager.Import<SaleDelivery>(excelPath);
                    break;
            }
            //}
            //catch
            //{
            //	MessageBox.Show("Excel文件已被其他程序打开");
            //	return;
            //}
            try
            {
                new PriceHandler().Handler(_list);
            }
            catch (Exception ex)
            {
                _list = null;
                MessageBox.Show(ex.Message);
                return;
            }

            ShowToView(_list);
        }
Beispiel #3
0
        public void Import(Stream fileStream)
        {
            var man       = new ExcelImportManager();
            var accColumn = man.Add(new ExecelImportColumn()
            {
                Name     = "会计单位",
                Required = true,
                Nullable = false
            });

            var deptColumn = man.Add(new ExecelImportColumn()
            {
                Name     = "部门",
                Required = true,
                Nullable = false
            });

            var empColumn = man.Add(new ExecelImportColumn()
            {
                Name     = "经办人",
                Required = true,
                Nullable = false
            });

            var timeColumn = man.Add(new ExecelImportColumn()
            {
                Name     = "日期",
                Required = true,
                Nullable = false
            });

            var planNumberColumn = man.Add(new ExecelImportColumn()
            {
                Name     = "计划号",
                Required = false,
                Nullable = true
            });

            var productLinksColumn = man.Add(new ExecelImportColumn()
            {
                Name     = "生产环节",
                Required = false,
                Nullable = true
            });
            var remarkColumn = man.Add(new ExecelImportColumn()
            {
                Name     = "摘要",
                Required = false,
                Nullable = true
            });


            var nameColumn = man.Add(new ExecelImportColumn()
            {
                Name     = "存货名称",
                Required = true,
                Nullable = false
            });

            var codeColumn = man.Add(new ExecelImportColumn()
            {
                Name     = "存货编码",
                Required = false,
                Nullable = true
            });

            var numberColumn = man.Add(new ExecelImportColumn()
            {
                Name     = "数量",
                Required = true,
                Nullable = false
            });

            var detailRemarkColumn = man.Add(new ExecelImportColumn()
            {
                Name     = "备注",
                Required = false,
                Nullable = true
            });

            var billList = new DmoCollection <ProduceOutput>();
            int i        = 0;

            using (var context = new TransactionContext()) {
                var bl = BIFactory.Create <IProduceOutputBL>(context);

                foreach (var row in man.Parse(fileStream))
                {
                    var bill = new ProduceOutput();
                    bl.InitNewDmo(bill);
                    i++;
                    bill.ID = i;
                    billList.Add(bill);
                    long accID = default(long);
                    if (accColumn.TryGetIDByName <AccountingUnit>(row, ref accID))
                    {
                        bill.AccountingUnit_ID = accID;
                    }

                    long deptID = default(long);
                    if (deptColumn.TryGetIDByName <Department>(row, ref deptID))
                    {
                        bill.Department_ID = deptID;
                    }

                    long empID = default(long);
                    if (empColumn.TryGetIDByName <Employee>(row, ref empID))
                    {
                        bill.Employee_ID = empID;
                    }

                    long planNumberID = default(long);
                    if (ExecelImportHelper.TryGetID <ProductPlan>(planNumberColumn, row, "PlanNumber", ref planNumberID))
                    {
                        bill.PlanNumber_ID = planNumberID;
                    }

                    long productLinksID = default(long);
                    if (productLinksColumn.TryGetIDByName <ProductLinks>(row, ref productLinksID))
                    {
                        bill.ProductLinks_ID = productLinksID;
                    }

                    DateTime time = default(DateTime);
                    if (timeColumn.TryGetValue(row, ref time))
                    {
                        bill.Time = time;
                    }

                    bill.Remark = remarkColumn.GetStringValue(row);

                    var  detail  = new ProduceOutput_Detail();
                    long goodsID = default(long);
                    if (codeColumn.TryGetIDByCode <Goods>(row, ref goodsID))
                    {
                        detail.Goods_ID = goodsID;
                    }
                    else if (nameColumn.TryGetIDByName <Goods>(row, ref goodsID))
                    {
                        detail.Goods_ID = goodsID;
                    }

                    decimal number = default(decimal);
                    if (numberColumn.TryGetValue(row, ref number))
                    {
                        detail.Number = number;
                    }

                    detail.Remark = detailRemarkColumn.GetStringValue(row);

                    DmoUtil.RefreshDependency(detail, "Goods_ID");
                    ConvertToSecondNumber(detail);
                    bill.Details.Add(detail);
                }

                foreach (var group in billList.GroupBy(x => new { x.Time, x.AccountingUnit_ID, x.Employee_ID, x.Department_ID, x.PlanNumber_ID, x.ProductLinks_ID }))
                {
                    var dmo = group.FirstOrDefault();
                    foreach (var produceOutput in group)
                    {
                        if (dmo.ID == produceOutput.ID)
                        {
                            continue;
                        }
                        foreach (var detail in produceOutput.Details)
                        {
                            dmo.Details.Add(detail);
                        }
                    }
                    dmo.ID = 0;
                    bl.Insert(dmo);
                }
                context.Commit();
            }
        }