Example #1
0
        public void SaveFile(string Remark, string ImgName)
        {
            string Messgae = "";
            string Name    = "";

            try
            {
                string fo = ImgName.Substring(ImgName.LastIndexOf('.'), ImgName.Length - ImgName.LastIndexOf('.'));

                if (fo.ToUpper() != ".JPG" && fo.ToUpper() != ".GIF" && fo.ToUpper() != ".BMP" && fo.ToUpper() != ".JPEG" && fo.ToUpper() != ".PNG")
                {
                    Messgae = "{ error:'', msg:'图片格式不正确!图片仅支持jpg、gif、bmp、jpeg、png格式!'}";

                    Response.Write(Messgae);
                    Response.End();
                }
                else
                {
                    //"123\\456-1).789".Substring("123\\456-1).789".LastIndexOf('\\')+1, "123\\456-1).789".LastIndexOf('.')-"123\\456-1).789".LastIndexOf("\\")-1)
                    Name = ImgName.Substring(ImgName.LastIndexOf('\\') + 1, ImgName.LastIndexOf('.') - ImgName.LastIndexOf("\\") - 1);

                    byte[] ReadFileResult = GetFileContent();

                    GrapSystemController GS = new GrapSystemController();
                    Image img = GS.byteArrayToImage(ReadFileResult);

                    //原始宽高
                    int ImgWidth  = img.Width;
                    int ImgHeight = img.Height;

                    string ImgSrcNew = "";
                    string Path      = "";
                    switch (Remark)
                    {
                    case "0": Path = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "Content\\gif\\" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + fo;
                        ImgSrcNew  = "../Content/gif/" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + fo;
                        break;

                    case "1": Path = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "Content\\GroundImg\\" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + fo;
                        ImgSrcNew  = "../Content/GroundImg/" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + fo;
                        break;

                    case "2": Path = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "Content\\jpg\\" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + fo;
                        ImgSrcNew  = "../Content/jpg/" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + fo;
                        break;
                    }


                    if (Remark != "0")
                    {
                        if (ImgWidth > 5052)
                        {
                            //重新赋宽高 1263*555
                            img = img.GetThumbnailImage(5052, ImgHeight * 5052 / ImgWidth, null, System.IntPtr.Zero);
                        }
                        using (Bitmap bitmap = new Bitmap(img))
                        {
                            using (MemoryStream stream = new MemoryStream())
                            {
                                bitmap.Save(Path);
                            }
                        }
                    }

                    else
                    {
                        img.Save(Path, System.Drawing.Imaging.ImageFormat.Gif);
                    }
                    img.Dispose();
                    string sql    = string.Format("insert into ImgResource (ImgName,ImgSrc,Remark) values ('{0}','{1}','{2}')", Name, ImgSrcNew, Remark);
                    bool   result = dal.ExcuteSql(sql);

                    if (!result)
                    {
                        Messgae = "{ error:'', msg:'导入失败!'}";
                    }
                    else
                    {
                        Messgae = "{ error:'', msg:'导入成功!'}";
                    }

                    Response.Write(Messgae);
                    Response.End();
                }
            }
            catch (Exception e)
            {
                if (e.Message == "GDI+ 中发生一般性错误。")
                {
                    Messgae = "{ error:'', msg:'导入出错!请检查导入图片,动态图中不可导入静态图'}";
                }
                else
                {
                    Messgae = "{ error:'', msg:'导入出错!" + e.Message + "'}";
                }
                Response.Write(Messgae);
                Response.End();
            }
        }
Example #2
0
        /// <summary>
        /// 修改或保存动画
        /// </summary>
        /// <param name="Name">动画的名称,保存后名称为Name+当前年月日时分秒</param>
        /// <param name="SensorNum">关联测点</param>
        /// <param name="Index">动画加载顺序 数值越低,动画在越底层</param>
        /// <param name="ImgSrc">动画的路径,获取后缀</param>
        /// <param name="ID">动画的id,有id则为修改,没有则是添加</param>
        /// <param name="Tag">关联测点值符号0大于1等于2小于</param>
        /// <param name="Value">关联测点值,与符号连用</param>
        public void SaveAdd(string Name, string SensorNum, string Index, string ImgSrc, string ID, string Tag, string Value, string SysCode)
        {
            string Message = "{data:'操作失败!'}";

            try
            {
                if (string.IsNullOrEmpty(ID))
                {
                    byte[] ReadFileResult = GetFileContent();

                    int index = Convert.ToInt32(Index);
                    //byte[] imgByte = System.IO.File.ReadAllBytes(@ImgSrc);
                    GrapSystemController GS = new GrapSystemController();
                    Image  img    = GS.byteArrayToImage(ReadFileResult);
                    float  width  = img.Width;
                    float  height = img.Height;
                    float  rateW  = width / 1263;
                    float  rateH  = height / 555;
                    double showValue;
                    if (string.IsNullOrEmpty(Value))
                    {
                        showValue = -1;
                    }
                    else
                    {
                        showValue = Convert.ToDouble(Value);
                    }
                    string fo        = ImgSrc.Substring(ImgSrc.LastIndexOf('.'), ImgSrc.Length - ImgSrc.LastIndexOf('.'));
                    string imgName   = Name + DateTime.Now.ToString("yyyyMMddHHmmss");
                    string ImgSrcNew = "../Content/gif/" + imgName + fo;

                    if (fo.IndexOf("gif") < 0)
                    {
                        using (Bitmap bitmap = new Bitmap(img))
                        {
                            using (MemoryStream stream = new MemoryStream())
                            {
                                bitmap.Save(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "Content\\gif\\" + imgName + fo);
                            }
                        }
                    }
                    else
                    {
                        img.Save(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "Content\\gif\\" + imgName + fo);
                    }
                    img.Dispose();



                    string sql = string.Format("insert into GifConfig (SensorNum,[Index],ImageSrc,RateW,RateH,RateL,RateT,Name,Tag,Value,SysCode) values ('{0}',{1},'{2}',{3},{4},0.5,0.5,'{5}',{6},'{7}','{8}')", SensorNum, Index, ImgSrcNew, rateW, rateH, Name, Convert.ToInt32(Tag), showValue, SysCode);

                    bool resul = dal.ExcuteSql(sql);

                    if (resul)
                    {
                        Message = "{ error:'', msg:'添加成功!'}";
                    }
                }
                else
                {
                    int    index = Convert.ToInt32(Index);
                    string sql   = string.Format("update GifConfig set Name='{0}',SensorNum='{1}',[Index]='{2}',Tag='{4}',Value='{5}'  where ID={3}", Name, SensorNum, Index, ID, Convert.ToInt32(Tag), string.IsNullOrEmpty(Value)?-1: Convert.ToDouble(Value));
                    bool   resul = dal.ExcuteSql(sql);

                    if (resul)
                    {
                        Message = "{ error:'', msg:'修改成功!'}";
                    }
                }
                Response.Write(Message);
                Response.End();
            }
            catch (Exception e)
            {
                Response.Write("{error:'',msg:'操作失败:" + e.Message + "'}");
                Response.End();
            }
        }