Ejemplo n.º 1
0
        /// <summary>
        /// 导入仓库支持的承运商
        /// </summary>
        /// <param name="sExcelFile">Excel文件名</param>
        /// <param name="sSheetName">Sheet名</param>
        public void ImportWarehouseShipping(string sExcelFile, string sSheetName)
        {
            try
            {
                ExcelData oExcel = new ExcelData(sExcelFile, sSheetName);
                DataColumn colOrgan = oExcel.ExcelTable.Columns["组织"];
                DataColumn colWhCode = oExcel.ExcelTable.Columns["仓库"];
                DataColumn colShipper = oExcel.ExcelTable.Columns["承运商"];
                DataColumn colRemark = oExcel.ExcelTable.Columns["备注"];

                string sLastOrgan = "";
                string sLastWarehouse = "";
                WarehouseInformation oWarehouse = null;
                foreach (DataRow row in oExcel.ExcelTable.Rows)
                {
                    string sOrgCode = row[colOrgan].ToString();
                    string sWhCode = row[colWhCode].ToString();
                    string sShipper = row[colShipper].ToString();
                    string sRemark = row[colRemark].ToString();

                    if ((sWhCode != sLastWarehouse) || (sOrgCode != sLastOrgan))
                    {
                        oWarehouse = (from w in dbEntity.WarehouseInformations
                                      where w.Parent.Code == sOrgCode && w.Code == sWhCode
                                      select w).FirstOrDefault();
                        sLastOrgan = sOrgCode;
                        sLastWarehouse = sWhCode;
                    }
                    var oShipper = (from s in dbEntity.ShippingInformations
                                    where s.Parent.Code == sOrgCode && s.Code == sShipper
                                    select s).FirstOrDefault();
                    if (oShipper != null)
                    {
                        var oWhShipper = (from r in dbEntity.WarehouseShippings
                                       where r.WhID == oWarehouse.Gid && r.ShipID == oShipper.Gid
                                       select r).FirstOrDefault();
                        if (oWhShipper == null)
                        {
                            oWhShipper = new WarehouseShipping { Warehouse = oWarehouse, Shipper = oShipper };
                            dbEntity.WarehouseShippings.Add(oWhShipper);
                        }
                        oWhShipper.Remark = sRemark;
                        dbEntity.SaveChanges();
                    }
                    if (Utility.ConfigHelper.GlobalConst.IsDebug)
                        Debug.WriteLine("{0} {1} {2}", this.ToString(), sShipper, sRemark);
                }
                oEventBLL.WriteEvent(String.Format("导入WarehouseShipping成功: {0} {1}", sExcelFile, sSheetName),
                    ModelEnum.ActionLevel.GENERIC, ModelEnum.ActionSource.SYSTEM, this.ToString());
            }
            catch (Exception ex)
            {
                oEventBLL.WriteEvent(String.Format("导入WarehouseShipping错误: {0} {1} {2}", sExcelFile, sSheetName, ex.Message),
                    ModelEnum.ActionLevel.ERROR, ModelEnum.ActionSource.SYSTEM, this.ToString());
            }
        }
Ejemplo n.º 2
0
 public JsonResult ShippingAdd(Guid whID, Guid shipID)
 {
     bool result;
     WarehouseInformation warehouse = dbEntity.WarehouseInformations.Find(whID);
     if (warehouse == null || warehouse.Deleted)
     {
         //仓库不存在
         result = false;
     }
     else
     {
         WarehouseShipping warehouseShipping = (from ws in dbEntity.WarehouseShippings
                                                where ws.WhID == whID
                                                   && ws.ShipID == shipID
                                                select ws).SingleOrDefault();
         if (warehouseShipping == null)
         {
             //不存在记录
             warehouseShipping = new WarehouseShipping
             {
                 WhID = whID,
                 ShipID = shipID
             };
             dbEntity.WarehouseShippings.Add(warehouseShipping);
             dbEntity.SaveChanges();
             result = true;
         }
         else
         {
             if (warehouseShipping.Deleted)
             {
                 //存在已删除记录
                 warehouseShipping.Deleted = false;
                 dbEntity.SaveChanges();
                 result = true;
             }
             else
             {
                 //存在未删除记录
                 result = false;
             }
         }
     }
     return Json(result, JsonRequestBehavior.AllowGet);
 }