using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; using System.IO; using System.Linq; using System.Management; using System.Web; using System.Web.Configuration; using System.Web.Services; using SuperMap.RealEstate.MemberShip.Storage.Business; namespace PublicService { /// /// WebService1 的摘要说明 /// [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。 // [System.Web.Script.Services.ScriptService] public class WebService1 : System.Web.Services.WebService { protected static string _connectString = System.Configuration.ConfigurationManager.AppSettings["connectstring"]; //下载WebService所在服务器上的文件的方法 [WebMethod] public byte[] Down(string filename) { string filepath = @"D:\" + filename; if (Directory.Exists(filepath)) { try { FileStream s = File.OpenRead(filepath); return ConvertStreamToByteBuffer(s); } catch { return new byte[0]; } } else { return new byte[0]; } } public byte[] ConvertStreamToByteBuffer(Stream s) { MemoryStream ms = new MemoryStream(); int b; while ((b = s.ReadByte()) != -1) { ms.WriteByte((byte)b); } return ms.ToArray(); } /// /// 上传图片 /// /// /// [WebMethod] public void UpLoadImages(string images,string serverpart,string rundate,string runstaue,string checkdate) { Configuration config = config = WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath); AppSettingsSection appSetting = (AppSettingsSection)config.GetSection("appSettings"); appSetting.Settings["serverpart"].Value = serverpart; appSetting.Settings["rundate"].Value = rundate; appSetting.Settings["runstaue"].Value = runstaue; appSetting.Settings["checkdate"].Value = checkdate; config.Save(); string url = Server.MapPath(@"~/upImages/"); if (!Directory.Exists(url)) { Directory.CreateDirectory(url); } byte[] bytes = Convert.FromBase64String(images); System.IO.MemoryStream ms = new System.IO.MemoryStream(bytes); System.Drawing.Image img = System.Drawing.Image.FromStream(ms); GetSizeImage(img, 700, 900).Save(url + "/upload.jpg", ImageFormat.Jpeg); OracleHelper _OracleHelper = new OracleHelper(_connectString.Split(',')[0], _connectString.Split(',')[1], _connectString.Split(',')[2], _connectString.Split(',')[3]); DataSet ds = _OracleHelper.ExcuteSqlGetDataSet(@"SELECT IMAGEINFO_ID,IMAGE_DATE IMAGE_DATE FROM HIGHWAY_EXCHANGE.T_IMAGEINFO", "T_IMAGEINFO"); DataTable IMAGEINFOdt = ds.Tables[0]; if (IMAGEINFOdt.Rows.Count > 0) { _OracleHelper.ExcuteSql(@"INSERT INTO HIGHWAY_EXCHANGE.T_IMAGEINFO (IMAGEINFO_ID,FILEPATH,SERVERPART,STARTDATE,IMAGE_DATE,STATUE) VALUES (HIGHWAY_EXCHANGE.SEQ_IMAGEINFO.NEXTVAL,'" + url + "'/upload.jpg,'" + serverpart + "','" + rundate + "',TO_DATE('" + checkdate + "','yyyy-MM-dd HH:mi:ss'),0)"); } else { _OracleHelper.ExcuteSql(@"UPDATE HIGHWAY_EXCHANGE.T_IMAGEINFO SET IMAGE_DATE = TO_DATE('" + checkdate + "','yyyy-MM-dd HH:mi:ss') WHERE IMAGEINFO_ID = " + IMAGEINFOdt.Rows[0]["IMAGEINFO_ID"]); } } private Image GetSizeImage(Image image, int w, int h) { double pCtrl = (double)w / (double)h;//固定的宽高比例 double pImg = (double)image.Width / (double)image.Height;//图片宽高比例 Image newImage; if (pCtrl > pImg) { if (h < image.Height) { newImage = drawImage(image, (int)(h * pImg), h); } else { newImage = drawImage(image, image.Width, image.Height); } } else if (pCtrl < pImg) { if (image.Width > w) { newImage = drawImage(image, w, (int)(w / pImg)); } else { newImage = drawImage(image, image.Width, image.Height); } } else { if (image.Width > w) { newImage = drawImage(image, w, h); } else { newImage = drawImage(image, image.Width, image.Height); } } return newImage; } private Image drawImage(Image sourceImage, int width, int height) { Image bitmap = new Bitmap(width, height); Graphics img = Graphics.FromImage(bitmap); img.CompositingQuality = CompositingQuality.HighQuality; img.SmoothingMode = SmoothingMode.HighQuality; img.InterpolationMode = InterpolationMode.High; img.DrawImage(sourceImage, new Rectangle(0, 0, width, height)); return bitmap; } /// /// 上传图片 /// /// /// [WebMethod] public void ReSetProject() { OracleHelper _OracleHelper = new OracleHelper(_connectString.Split(',')[0], _connectString.Split(',')[1], _connectString.Split(',')[2], _connectString.Split(',')[3]); _OracleHelper.ExcuteSql(@"UPDATE HIGHWAY_EXCHANGE.T_IMAGEINFO SET STATUE = 1"); } } }