/// <summary>
        /// 运输公司面单添加和编辑页面
        /// </summary>
        /// <param name="shippingGid">运输公司的Gid</param>
        /// <returns></returns>
        public ActionResult Index(Guid? shippingGid)
        {
            // 权限验证
            string strProgramCode = Request.RequestContext.RouteData.Values["Controller"].ToString() +
                Request.RequestContext.RouteData.Values["Action"].ToString();
            if (!base.Permission(strProgramCode))
                return RedirectToAction("ErrorPage", "Home", new { LiveAzure.Resource.Common.NoPermission });

            //运输公司的下拉列表
            List<SelectListItem> oList = new List<SelectListItem>();
            List<ShippingInformation> oShippers = dbEntity.ShippingInformations.Where(o=>o.Otype==(byte)ModelEnum.OrganizationType.SHIPPER).ToList();
            foreach (ShippingInformation item in oShippers)
            {
                oList.Add(new SelectListItem { Text = item.FullName.GetResource(CurrentSession.Culture), Value = item.Gid.ToString() });
            }
            ViewBag.shipperList = oList;

            //shippingGid为空表示第一次进入页面 ,不为空表示更变运输公司后重新加载页面
            if (shippingGid == null)
            {
                ShippingEnvelope oEnvelope = new ShippingEnvelope
                {
                    Template = NewLargeObject(CurrentSession.OrganizationGID)
                };
                return View(oEnvelope);
            }
            else
            {
                //oEnvelope为空表示此运输公司还没有模板,不为空表示已经有了模板
                ShippingEnvelope oEnvelope = dbEntity.ShippingEnvelopes.Where(o => o.ShipID == shippingGid).SingleOrDefault();
                if (oEnvelope != null)
                {
                    oEnvelope.Template = RefreshLargeObject(oEnvelope.Template, CurrentSession.OrganizationGID);
                    return View(oEnvelope);
                }
                else
                {
                    ShippingEnvelope newEnvelope = new ShippingEnvelope
                    {
                        ShipID = (Guid)shippingGid,
                        Template = NewLargeObject(CurrentSession.OrganizationGID)
                    };
                    return View(newEnvelope);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// 导入面单模板
        /// </summary>
        /// <param name="sExcelFile">Excel文件名</param>
        /// <param name="sSheetName">Sheet名</param>
        public void ImportShippingEnvelope(string sExcelFile, string sSheetName)
        {
            try
            {
                ExcelData oExcel = new ExcelData(sExcelFile, sSheetName);
                DataColumn colOrgan = oExcel.ExcelTable.Columns["组织"];
                DataColumn colShipper = oExcel.ExcelTable.Columns["承运商"];
                DataColumn colCode = oExcel.ExcelTable.Columns["代码"];
                DataColumn colStatus = oExcel.ExcelTable.Columns["状态"];
                DataColumn colDescription = oExcel.ExcelTable.Columns["描述"];
                DataColumn colMatterCN = oExcel.ExcelTable.Columns["中文内容"];
                DataColumn colMatterUS = oExcel.ExcelTable.Columns["英文内容"];
                DataColumn colRemark = oExcel.ExcelTable.Columns["备注"];

                foreach (DataRow row in oExcel.ExcelTable.Rows)
                {
                    string sOrganCode = row[colOrgan].ToString();
                    string sShipper = row[colShipper].ToString();
                    var oShipping = (from s in dbEntity.ShippingInformations
                                     where s.Parent.Code == sOrganCode && s.Code == sShipper
                                           && s.Otype == (byte)ModelEnum.OrganizationType.SHIPPER
                                     select s).FirstOrDefault();
                    string sCode = row[colCode].ToString();
                    byte nStatus;
                    Byte.TryParse(row[colStatus].ToString(), out nStatus);
                    string sDescription = row[colDescription].ToString();
                    GeneralLargeObject oTemplate = new GeneralLargeObject(2052, row[colMatterCN].ToString(), 1033, row[colMatterUS].ToString());
                    string sRemark = row[colRemark].ToString();

                    var oEnvelope = (from e in dbEntity.ShippingEnvelopes
                                     where e.Deleted == false
                                           && e.ShipID == oShipping.Gid && e.Code == sCode
                                     select e).FirstOrDefault();
                    if (oEnvelope == null)
                    {
                        oEnvelope = new ShippingEnvelope { Shipping = oShipping, Code = sCode };
                        dbEntity.ShippingEnvelopes.Add(oEnvelope);
                    }
                    oEnvelope.Estatus = nStatus;
                    oEnvelope.Matter = sDescription;
                    if (oEnvelope.Template == null)
                        oEnvelope.Template = oTemplate;
                    else
                        oEnvelope.Template.SetLargeObject(oTemplate);
                    oTemplate.Remark = sRemark;
                    dbEntity.SaveChanges();
                    if (Utility.ConfigHelper.GlobalConst.IsDebug)
                        Debug.WriteLine("{0} {1} {2}", this.ToString(), sCode, sRemark);
                }
                oEventBLL.WriteEvent(String.Format("导入ImportShippingEnvelope成功: {0} {1}", sExcelFile, sSheetName),
                    ModelEnum.ActionLevel.GENERIC, ModelEnum.ActionSource.SYSTEM, this.ToString());
            }
            catch (Exception ex)
            {
                oEventBLL.WriteEvent(String.Format("导入ImportShippingEnvelope错误: {0} {1} {2}", sExcelFile, sSheetName, ex.Message),
                    ModelEnum.ActionLevel.ERROR, ModelEnum.ActionSource.SYSTEM, this.ToString());
            }
        }
 /// <summary>
 /// 保存面单模板
 /// </summary>
 /// <param name="oEnvelope"></param>
 public void SaveEnvelopeTemplate(ShippingEnvelope oEnvelope)
 {
     ShippingEnvelope oldEnelope = dbEntity.ShippingEnvelopes.Where(o => o.ShipID == oEnvelope.ShipID && o.Code == oEnvelope.Code).SingleOrDefault();      //查出此运输公司是否已经有模板
     if (oldEnelope == null)         //没模板,添加操作
     {
         oEnvelope.Template = new GeneralLargeObject(oEnvelope.Template);
         dbEntity.ShippingEnvelopes.Add(oEnvelope);
         dbEntity.SaveChanges();
     }
     else                  //有模板,更新操作
     {
         oEnvelope.Template.SetLargeObject(oEnvelope.Template);
         if (ModelState.IsValid)
         {
             dbEntity.Entry(oldEnelope).State = EntityState.Modified;
             dbEntity.SaveChanges();
         }
     }
 }