public void Delete(AscmUnloadingPointMap ascmUnloadingPointMap)
 {
     try
     {
         YnDaoHelper.GetInstance().nHibernateHelper.Delete<AscmUnloadingPointMap>(ascmUnloadingPointMap);
     }
     catch (Exception ex)
     {
         YnBaseClass2.Helper.LogHelper.GetLog().Error("删除失败(Delete AscmUnloadingPointMap)", ex);
         throw ex;
     }
 }
Пример #2
0
        public ContentResult UnloadingPointMapSave(HttpPostedFileBase imgUpload, AscmUnloadingPointMap ascmUnloadingPointMap_Model, int? id)
        {
            JsonObjectResult jsonObjectResult = new JsonObjectResult();
            try
            {
                string userName = string.Empty;
                if (User.Identity.IsAuthenticated)
                {
                    userName = User.Identity.Name;
                }
                if (ascmUnloadingPointMap_Model.name == null || ascmUnloadingPointMap_Model.name.Trim() == "")
                    throw new Exception("卸货位名称不能为空");
                string name = ascmUnloadingPointMap_Model.name.Trim();

                AscmWarehouse ascmWarehouse = AscmWarehouseService.GetInstance().Get(ascmUnloadingPointMap_Model.warehouseId);
                if (ascmWarehouse == null)
                    throw new Exception("仓库不能为空");

                AscmUnloadingPointMap ascmUnloadingPointMap = null;
                if (id.HasValue)
                {
                    ascmUnloadingPointMap = AscmUnloadingPointMapService.GetInstance().Get(id.Value);
                    if (ascmUnloadingPointMap == null)
                        throw new Exception("保存卸货位地图失败!");
                }

                string imgUrl = ""; //smallImgUrl = "";
                int imgWidth = 0, imgHeight = 0;
                if (imgUpload != null)
                {
                    string fileName = imgUpload.FileName;
                    string fileExtension = System.IO.Path.GetExtension(fileName).ToLower();
                    //if (fileExtension != ".jpg" && fileExtension != ".jpeg" && fileExtension != ".gif" && fileExtension != ".png")
                    //    throw new Exception("只能上传后缀名为.jpg|.gif|.png的图片");
                    System.Drawing.Imaging.ImageFormat imageFormat = null;
                    if (fileExtension == ".jpg" || fileExtension == ".jpeg")
                        imageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;
                    else if (fileExtension == ".gif")
                        imageFormat = System.Drawing.Imaging.ImageFormat.Gif;
                    else if (fileExtension == ".png")
                        imageFormat = System.Drawing.Imaging.ImageFormat.Png;
                    else
                        throw new Exception("只能上传后缀名为.jpg|.jpeg|.gif|.png的图片");

                    string serverPath = Server.MapPath(Request.ApplicationPath);
                    string serverDirectory = System.IO.Path.Combine(serverPath, "_data\\UnloadingPointMap");
                    if (!Directory.Exists(serverDirectory))
                    {
                        Directory.CreateDirectory(serverDirectory);
                    }
                    string serverImgName = System.IO.Path.GetFileNameWithoutExtension(fileName) + "_" + System.DateTime.Now.ToString("yyyyMMddHHmmss") + fileExtension;
                    string serverImgPath = System.IO.Path.Combine(serverDirectory, serverImgName);
                    //StreamWriter streamWriter = new StreamWriter(serverImgPath, true, System.Text.Encoding.GetEncoding("GB2312"));
                    imgUpload.SaveAs(serverImgPath);
                    //imgUrl = System.IO.Path.Combine(Request.ApplicationPath, "_data/UnloadingPointMap", serverImgName);
                    imgUrl = (Request.ApplicationPath == "/" ? "" : Request.ApplicationPath) + "/_data/UnloadingPointMap/" + serverImgName;

                    //string serverSmallImgName = System.IO.Path.GetFileNameWithoutExtension(fileName) + "_small_" + System.DateTime.Now.ToString("yyyyMMddHHmmss") + fileExtension;
                    //string serverSmallImgPath = System.IO.Path.Combine(serverDirectory, serverSmallImgName);
                    System.Drawing.Image img = System.Drawing.Image.FromStream(imgUpload.InputStream);
                    imgWidth = img.Width;
                    imgHeight = img.Height;
                    //System.Drawing.Image newImg = new System.Drawing.Bitmap(img, 300, 140);
                    //newImg.Save(serverSmallImgPath, imageFormat);
                    //smallImgUrl = (Request.ApplicationPath == "/" ? "" : Request.ApplicationPath) + "/_data/UnloadingPointMap/" + serverSmallImgName;

                    DeleteUnloadingPointMapImg(ascmUnloadingPointMap);
                }

                if (ascmUnloadingPointMap == null)
                {
                    ascmUnloadingPointMap = new AscmUnloadingPointMap();
                    int maxId = YnDaoHelper.GetInstance().nHibernateHelper.GetMaxId("select max(id) from AscmUnloadingPointMap");
                    ascmUnloadingPointMap.id = ++maxId;
                    ascmUnloadingPointMap.createUser = userName;
                    ascmUnloadingPointMap.createTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
                }
                object object1 = YnDaoHelper.GetInstance().nHibernateHelper.GetObject("select count(*) from AscmUnloadingPointMap where id<>" + ascmUnloadingPointMap.id + " and warehouseId='" + ascmWarehouse.id + "' and name='" + name + "'");
                if (object1 == null)
                    throw new Exception("查询异常!");
                int count = 0;
                if (int.TryParse(object1.ToString(), out count) && count > 0)
                    throw new Exception("仓库【" + ascmWarehouse.id + "】已存在卸货位地图名称");

                ascmUnloadingPointMap.name = name;
                ascmUnloadingPointMap.ascmWarehouse = ascmWarehouse;
                ascmUnloadingPointMap.warehouseId = ascmWarehouse.id;
                if (!string.IsNullOrEmpty(ascmUnloadingPointMap_Model.direction))
                    ascmUnloadingPointMap.direction = ascmUnloadingPointMap_Model.direction.Trim();
                ascmUnloadingPointMap.width = ascmUnloadingPointMap_Model.width;
                ascmUnloadingPointMap.height = ascmUnloadingPointMap_Model.height;
                if (imgUpload != null)
                {
                    ascmUnloadingPointMap.imgUrl = imgUrl;
                    //ascmUnloadingPointMap.smallImgUrl = smallImgUrl;
                    ascmUnloadingPointMap.imgWidth = imgWidth;
                    ascmUnloadingPointMap.imgHeight = imgHeight;
                }
                if (!string.IsNullOrEmpty(ascmUnloadingPointMap_Model.description))
                    ascmUnloadingPointMap.description = ascmUnloadingPointMap_Model.description.Trim();
                if (!string.IsNullOrEmpty(ascmUnloadingPointMap_Model.memo))
                    ascmUnloadingPointMap.memo = ascmUnloadingPointMap_Model.memo.Trim();
                ascmUnloadingPointMap.modifyUser = userName;
                ascmUnloadingPointMap.modifyTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");

                if (id.HasValue)
                    AscmUnloadingPointMapService.GetInstance().Update(ascmUnloadingPointMap);
                else
                    AscmUnloadingPointMapService.GetInstance().Save(ascmUnloadingPointMap);

                jsonObjectResult.result = true;
                jsonObjectResult.id = ascmUnloadingPointMap.id.ToString();
                jsonObjectResult.message = "";
            }
            catch (Exception ex)
            {
                jsonObjectResult.message = ex.Message;
            }
            string sReturn = JsonConvert.SerializeObject(jsonObjectResult);
            return Content(sReturn);
        }
Пример #3
0
            public DisplayWarehouseMap GetDisplayWarehouseMap(AscmUnloadingPointMap ascmUnloadingPointMap, List<AscmUnloadingPointMapLink> listAscmUnloadingPointMapLink)
            {
                DisplayWarehouseMap displayWarehouseMap = new DisplayWarehouseMap();
                dlWidth = ascmUnloadingPointMap.width;
                dlHeight = ascmUnloadingPointMap.height;
                displayWarehouseMap.dlCss = "{" + string.Format("\"width\":\"{0}px\",\"height\":\"{1}px\"", dlWidth, dlHeight) + "}";
                displayWarehouseMap.dtCss = "{" + string.Format("\"width\":\"{0}px\",\"height\":\"{1}px\"", GetDtWidth(), GetDtHeight()) + "}";
                displayWarehouseMap.ddCss = "{" + string.Format("\"width\":\"{0}px\",\"height\":\"{1}px\",\"line-height\":\"{2}px\"", GetDdWidth(), GetDdHeight(), GetDdLineHeight()) + "}";
                displayWarehouseMap.dtImgCss = "{" + string.Format("\"max-height\":\"{0}px\",\"max-width\":\"{1}px\"", GetImgMaxHeight(), GetImgMaxWidth()) + "}";
                displayWarehouseMap.warehouseMapCss = "{" + string.Format("\"width\":\"{0}px\",\"height\":\"{1}px\",\"background\":\"url({2}) 0px 0px no-repeat\"", ascmUnloadingPointMap.imgWidth, ascmUnloadingPointMap.imgHeight, ascmUnloadingPointMap.imgUrl) + "}";

                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                foreach (AscmUnloadingPointMapLink ascmUnloadingPointMapLink in listAscmUnloadingPointMapLink)
                {
                    sb.Append(string.Format(unloadingPoint, ascmUnloadingPointMapLink.y, ascmUnloadingPointMapLink.x, DisplayUnloadingPointMonitor.DisplayUnloadingPoint(ascmUnloadingPointMapLink.pointStatus, ascmUnloadingPointMapLink.pointName)));
                }
                displayWarehouseMap.display = sb.ToString();

                return displayWarehouseMap;
            }
Пример #4
0
 private void DeleteUnloadingPointMapImg(AscmUnloadingPointMap ascmUnloadingPointMap)
 {
     if (ascmUnloadingPointMap != null)
     {
         if (!string.IsNullOrEmpty(ascmUnloadingPointMap.imgUrl))
         {
             string serverOriginalImgUrl = Server.MapPath(ascmUnloadingPointMap.imgUrl);
             if (System.IO.File.Exists(serverOriginalImgUrl))
                 System.IO.File.Delete(serverOriginalImgUrl);
         }
         //if (!string.IsNullOrEmpty(ascmUnloadingPointMap.smallImgUrl))
         //{
         //    string serverOriginalSamllImgUrl = Server.MapPath(ascmUnloadingPointMap.smallImgUrl);
         //    if (System.IO.File.Exists(serverOriginalSamllImgUrl))
         //        System.IO.File.Delete(serverOriginalSamllImgUrl);
         //}
     }
 }
 public void Update(AscmUnloadingPointMap ascmUnloadingPointMap)
 {
     try
     {
         using (ITransaction tx = YnDaoHelper.GetInstance().nHibernateHelper.GetCurrentSession().BeginTransaction())
         {
             try
             {
                 YnDaoHelper.GetInstance().nHibernateHelper.Update<AscmUnloadingPointMap>(ascmUnloadingPointMap);
                 tx.Commit();//正确执行提交
             }
             catch (Exception ex)
             {
                 tx.Rollback();//回滚
                 YnBaseClass2.Helper.LogHelper.GetLog().Error("修改失败(Update AscmUnloadingPointMap)", ex);
                 throw ex;
             }
         }
     }
     catch (Exception ex)
     {
         YnBaseClass2.Helper.LogHelper.GetLog().Error("修改失败(Save AscmUnloadingPointMap)", ex);
         throw ex;
     }
 }