示例#1
0
        public ActionResult SettledCompare(int SettledType)
        {
            SettledCompareViewModel vm = new SettledCompareViewModel();

            vm.DisplyMessage = SettledType == 0 ? "导入应收结算比对(客户运单号|运费|点费|燃油附加费|其他费用)" : "导入应付结算比对(客户运单号|运费|点费|燃油附加费|其他费用)";
            vm.SettledType   = SettledType;
            vm.Customers     = ApplicationConfigHelper.GetProjectUserCustomers(base.UserInfo.ProjectID, base.UserInfo.ID)
                               .Select(c => new SelectListItem()
            {
                Value = c.CustomerID.ToString(), Text = c.CustomerName
            });
            vm.SettledPodCompareCollection = Enumerable.Empty <SettledPodCompare>();
            return(View(vm));
        }
示例#2
0
        public ActionResult SettledCompare(SettledCompareViewModel vm)
        {
            vm.Customers = ApplicationConfigHelper.GetProjectUserCustomers(base.UserInfo.ProjectID, base.UserInfo.ID)
                           .Select(c => new SelectListItem()
            {
                Value = c.CustomerID.ToString(), Text = c.CustomerName
            });
            vm.DisplyMessage = vm.SettledType == 0 ? "导入应收结算比对(客户运单号|运费|点费|燃油附加费|其他费用)" : "导入应付结算比对(客户运单号|运费|点费|燃油附加费|其他费用)";

            if (Request.Files.Count > 0)
            {
                HttpPostedFileBase hpf = Request.Files[0] as HttpPostedFileBase;
                if (hpf.ContentLength > 0)
                {
                    string uploadFolderPath = Runbow.TWS.Common.Constants.UPLOAD_FOLDER_PATH;
                    string targetPath       = Path.Combine(Runbow.TWS.Common.Constants.UPLOAD_FOLDER_PATH, base.UserInfo.ProjectID.ToString(), Runbow.TWS.Common.Constants.TEMPFOLDER);
                    if (!Directory.Exists(targetPath))
                    {
                        Directory.CreateDirectory(targetPath);
                    }

                    string fileName = base.UserInfo.ID.ToString() + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + "_" + Path.GetFileName(hpf.FileName);
                    string fullPath = Path.Combine(targetPath, fileName);
                    hpf.SaveAs(fullPath);
                    hpf.InputStream.Close();

                    Runbow.TWS.Common.ExcelHelper excelHelper = new Runbow.TWS.Common.ExcelHelper(fullPath);
                    DataSet ds = excelHelper.GetAllDataFromAllSheets();
                    excelHelper.Dispose();
                    MyFile.Delete(fullPath);

                    if (ds == null || ds.Tables == null || ds.Tables[0].Rows.Count == 0)
                    {
                        vm.ErrorMessage = "Excel文件内容有误";
                    }
                    else
                    {
                        IList <SettledPodCompare> settledPodCompares = new List <SettledPodCompare>();
                        StringBuilder             errorMessage       = new StringBuilder();
                        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                        {
                            string  customerOrderNumber = string.Empty;
                            decimal excelShipAmt        = 0;
                            decimal excelBafAmt         = 0;
                            decimal excelPointAmt       = 0;
                            decimal excelOtherAmt       = 0;

                            if (ds.Tables[0].Columns.Contains("客户运单号"))
                            {
                                customerOrderNumber = ds.Tables[0].Rows[i]["客户运单号"].ToString();
                                if (string.IsNullOrEmpty(customerOrderNumber))
                                {
                                    errorMessage.Append("Excel中第").Append(i + 1).Append("行客户运单号列为空,请重新编辑Excel");
                                }
                            }
                            else
                            {
                                errorMessage.Append("Excel中无客户运单号列,请重新编辑").Append("<br />");
                            }

                            if (ds.Tables[0].Columns.Contains("运费"))
                            {
                                decimal tempShipAmt;
                                if (decimal.TryParse(ds.Tables[0].Rows[i]["运费"].ToString().Trim(), out tempShipAmt))
                                {
                                    excelShipAmt = tempShipAmt;
                                }
                            }

                            if (ds.Tables[0].Columns.Contains("点费"))
                            {
                                decimal tempPointAmt;
                                if (decimal.TryParse(ds.Tables[0].Rows[i]["点费"].ToString().Trim(), out tempPointAmt))
                                {
                                    excelPointAmt = tempPointAmt;
                                }
                            }

                            if (ds.Tables[0].Columns.Contains("燃油附加费"))
                            {
                                decimal tempBafAmt;
                                if (decimal.TryParse(ds.Tables[0].Rows[i]["燃油附加费"].ToString().Trim(), out tempBafAmt))
                                {
                                    excelBafAmt = tempBafAmt;
                                }
                            }

                            if (ds.Tables[0].Columns.Contains("其他费用"))
                            {
                                decimal tempOtherAmt;
                                if (decimal.TryParse(ds.Tables[0].Rows[i]["其他费用"].ToString().Trim(), out tempOtherAmt))
                                {
                                    excelOtherAmt = tempOtherAmt;
                                }
                            }

                            settledPodCompares.Add(new SettledPodCompare()
                            {
                                CustomerOrderNumber = customerOrderNumber,
                                CompareShipAmt      = excelShipAmt,
                                CompareBAFAmt       = excelBafAmt,
                                ComparePointAmt     = excelPointAmt,
                                CompareOtherAmt     = excelOtherAmt,
                                CompareTotalAmt     = excelShipAmt + excelBafAmt + excelPointAmt + excelOtherAmt,
                                SettledType         = vm.SettledType,
                                ProjectID           = base.UserInfo.ProjectID,
                                CustomerOrShipperID = vm.SettledType == 0 ? vm.CustomerID : vm.ShipperID,
                                RelatedCustomerID   = vm.CustomerID
                            });
                        }

                        if (errorMessage.Length > 0)
                        {
                            vm.ErrorMessage = errorMessage.ToString();
                            return(View(vm));
                        }

                        var Response = new SettledService().GetSettledPodByCondition(new GetSettledPodByConditionRequest()
                        {
                            CustomerOrderNumberCollection = settledPodCompares.Select(s => s.CustomerOrderNumber),
                            SettledType = vm.SettledType,
                            CustomerID  = vm.CustomerID,
                            ShipperID   = vm.ShipperID
                        });

                        if (Response.IsSuccess)
                        {
                            settledPodCompares.Each((i, s) => {
                                var tempSettledPod   = Response.Result.FirstOrDefault(r => r.CustomerOrderNumber == s.CustomerOrderNumber);
                                s.ActualDeliveryDate = DateTime.MinValue;
                                if (tempSettledPod != null)
                                {
                                    s.SystemNumber          = tempSettledPod.SystemNumber;
                                    s.CustomerOrShipperName = tempSettledPod.CustomerOrShipperName;
                                    s.PodID              = tempSettledPod.PodID;
                                    s.ID                 = tempSettledPod.ID;
                                    s.SettledNumber      = tempSettledPod.SettledNumber;
                                    s.StartCityID        = tempSettledPod.StartCityID;
                                    s.StartCityName      = tempSettledPod.StartCityName;
                                    s.EndCityID          = tempSettledPod.EndCityID;
                                    s.EndCityName        = tempSettledPod.EndCityName;
                                    s.ShipperTypeID      = tempSettledPod.ShipperTypeID;
                                    s.ShipperTypeName    = tempSettledPod.ShipperTypeName;
                                    s.PODTypeID          = tempSettledPod.PODTypeID;
                                    s.PODTypeName        = tempSettledPod.PODTypeName;
                                    s.TtlOrTplID         = tempSettledPod.TtlOrTplID;
                                    s.TtlOrTplName       = tempSettledPod.TtlOrTplName;
                                    s.ActualDeliveryDate = tempSettledPod.ActualDeliveryDate ?? DateTime.MinValue;
                                    s.BoxNumber          = tempSettledPod.BoxNumber;
                                    s.Weight             = tempSettledPod.Weight;
                                    s.GoodsNumber        = tempSettledPod.GoodsNumber;
                                    s.Volume             = tempSettledPod.Volume;
                                    s.Remark             = tempSettledPod.Remark;
                                    s.ShipAmt            = tempSettledPod.ShipAmt;
                                    s.BAFAmt             = tempSettledPod.BAFAmt;
                                    s.PointAmt           = tempSettledPod.PointAmt;
                                    s.OtherAmt           = tempSettledPod.OtherAmt;
                                    s.TotalAmt           = tempSettledPod.TotalAmt;
                                    s.Str1               = tempSettledPod.Str1;
                                    s.Str2               = tempSettledPod.Str2;
                                    s.Str3               = tempSettledPod.Str3;
                                    s.Str4               = tempSettledPod.Str4;
                                    s.Str5               = tempSettledPod.Str5;
                                    s.DateTime1          = tempSettledPod.DateTime1;
                                    s.DateTime2          = tempSettledPod.DateTime2;
                                    s.Creator            = tempSettledPod.Creator;
                                    s.CreateTime         = tempSettledPod.CreateTime;
                                    s.InvoiceID          = tempSettledPod.InvoiceID;
                                    s.IsAudit            = tempSettledPod.IsAudit;
                                }
                            });

                            vm.SettledPodCompareCollection = settledPodCompares;
                        }
                        else
                        {
                            vm.ErrorMessage = "获取系统结算信息失败!";
                        }
                    }
                }
                else
                {
                    vm.ErrorMessage = "Excel文件内容为空";
                }
            }
            else
            {
                vm.ErrorMessage = "请选择excel文件";
            }

            return(View(vm));
        }