/// <summary> /// 下载图片并且获取本地图片路径 /// </summary> /// <param name="url"></param> /// <returns></returns> Image imageLocation(string imageName) { /** * 判断图片在临时文件夹中是否存在。如果存在则不下载。 * 修改时间:2013-9-5 王随 */ string filePath = string.Format(@"{0}temp\{1}", AppDomain.CurrentDomain.BaseDirectory, imageName); if (!File.Exists(filePath)) {//如果本地文件不存在,则下载 AMS.ServiceProxy.FileOperate fileDownload = new AMS.ServiceProxy.FileOperate(); if (fileDownload.FileDownLoad(filePath, imageName, SeatManage.EnumType.SeatManageSubsystem.SeatSlip) != "") { return (null); } } Image img = Image.FromFile(filePath); return(img); }
public static bool Get(int AdID) { try { AMS.Model.AMS_AdvertisementSchoolCopy adModel = AMS.ServiceProxy.AdvertisementOperationService.GetSchoolAdvert(AdID); if (adModel != null) { //上传下载类 AMS.ServiceProxy.FileOperate advertfileOperate = new AMS.ServiceProxy.FileOperate(); SeatManage.Bll.FileOperate seatmanagefileOperate = new SeatManage.Bll.FileOperate(); seatmanagefileOperate.Downloaded += new SeatManage.Bll.EventHandleFileTransport(seatmanagefileOperate_Downloaded); advertfileOperate.DownloadError += new AMS.ServiceProxy.EventHandleFileOperateError(fileOperate_DownloadError); //创建model SeatManage.ClassModel.AMS_Advertisement model = new SeatManage.ClassModel.AMS_Advertisement(); model.AdContent = adModel.AdContent; model.EffectDate = adModel.EffectDate; model.EndDate = adModel.EndDate; model.ImageFilePath = SeatManage.ClassModel.AMS_Advertisement.GetDownloadFile(adModel.AdContent); model.Name = adModel.Name; model.Num = adModel.Num; model.Type = (SeatManage.EnumType.AdType)System.Enum.Parse(typeof(SeatManage.EnumType.AdType), adModel.Type.ToString()); //图片下载 foreach (string file in model.ImageFilePath) { string fileFullName = string.Format(@"{0}{1}", ServiceSet.TempFilePath, file); //开始下载文件 if (!File.Exists(fileFullName)) { bool downloadResult = false; string error = advertfileOperate.FileDownLoad(fileFullName, file, (SeatManage.EnumType.SeatManageSubsystem)System.Enum.Parse(typeof(SeatManage.EnumType.SeatManageSubsystem), model.Type.ToString())); if (error == "") { downloadResult = true; } else { downloadResult = false; } if (!downloadResult) { //下载失败,直接返回false return(false); } } } //图片上传 foreach (string file in model.ImageFilePath) { string fileFullName = string.Format(@"{0}{1}", ServiceSet.TempFilePath, file); //文件下载完成,执行上传操作 bool uploadResult = seatmanagefileOperate.UpdateFile(fileFullName, file, (SeatManage.EnumType.SeatManageSubsystem)System.Enum.Parse(typeof(SeatManage.EnumType.SeatManageSubsystem), model.Type.ToString())); if (!uploadResult) { //上传失败,直接返回false,不再尝试其他操作 return(false); } } SeatManage.ClassModel.AMS_Advertisement sameModel = SeatManage.Bll.AdvertisementOperation.GetAdModel(model.Num, model.Type); string errorMessage = ""; if (sameModel == null) { errorMessage = SeatManage.Bll.AdvertisementOperation.AddAdModel(model); } else { model.ID = sameModel.ID; errorMessage = SeatManage.Bll.AdvertisementOperation.UpdateAdModel(model); } if (errorMessage != "") { SeatManage.SeatManageComm.WriteLog.Write(string.Format("更新广告遇到错误:{0}", errorMessage)); return(false); } } return(true); } catch (Exception ex) { throw ex; } }
/// <summary> /// 根据ID获取优惠券信息 /// </summary> /// <returns></returns> public static bool GetSlipCustomer(int num) { //TODO:未测试 try { Model.AMS_SlipCustomer advertModel = AMS.ServiceProxy.ISlipCustomerService.GetSlipCustomerByID(num); AMS.ServiceProxy.FileOperate advertfileOperate = new AMS.ServiceProxy.FileOperate(); SeatManage.Bll.FileOperate seatmanagefileOperate = new SeatManage.Bll.FileOperate(); if (advertModel != null) { SeatManage.ClassModel.AMS_SlipCustomer seatModel = SeatManage.Bll.AMS_SlipCustomer.GetSlipCustomerByNum(advertModel.Number); if (seatModel == null) { //优惠券在数据库中不存在:先执行下载操作,然后更新 string ImageUrlFullName = string.Format(@"{0}{1}", ServiceSet.TempFilePath, advertModel.ImageUrl); try { advertfileOperate.FileDownLoad(ImageUrlFullName, advertModel.ImageUrl, SeatManage.EnumType.SeatManageSubsystem.SlipCustomer); } catch (Exception ex) { SeatManage.SeatManageComm.WriteLog.Write(string.Format("优惠券{0}下载失败:{1}", advertModel.Number, ex.Message)); } try { if (seatmanagefileOperate.UpdateFile(ImageUrlFullName, advertModel.ImageUrl, SeatManage.EnumType.SeatManageSubsystem.SlipCustomer)) { //上传完成,执行删除操作 File.Delete(ImageUrlFullName); } else { return(false); } } catch (Exception ex) { SeatManage.SeatManageComm.WriteLog.Write(string.Format("优惠券{0}上传失败:{1}", advertModel.Number, ex.Message)); } string CustomerImagefullName = string.Format(@"{0}{1}", ServiceSet.TempFilePath, advertModel.CustomerImage); advertfileOperate.FileDownLoad(CustomerImagefullName, advertModel.CustomerImage, SeatManage.EnumType.SeatManageSubsystem.SlipCustomer); if (seatmanagefileOperate.UpdateFile(CustomerImagefullName, advertModel.CustomerImage, SeatManage.EnumType.SeatManageSubsystem.SlipCustomer)) { File.Delete(CustomerImagefullName); } else { return(false); } if (Convert.ToBoolean(advertModel.IsPrint)) { XmlDocument Templatedoc = new XmlDocument(); Templatedoc.LoadXml(advertModel.SlipTemplate); XmlElement Templateroot = Templatedoc.DocumentElement; XmlNodeList Templatexnlist = ((XmlNode)Templateroot).ChildNodes; for (int j = 0; j < Templatexnlist.Count; j++) { if (Templatexnlist[j].Name == "Pic") { try { advertfileOperate.FileDownLoad((ServiceSet.TempFilePath + Templatexnlist[j].InnerText), Templatexnlist[j].InnerText, SeatManage.EnumType.SeatManageSubsystem.SlipCustomer); } catch (Exception ex) { SeatManage.SeatManageComm.WriteLog.Write(string.Format("优惠券{0}下载失败:{1}", advertModel.Number, ex.Message)); } try { if (seatmanagefileOperate.UpdateFile((ServiceSet.TempFilePath + Templatexnlist[j].InnerText), Templatexnlist[j].InnerText, SeatManage.EnumType.SeatManageSubsystem.SlipCustomer)) { //上传完成,执行删除操作 File.Delete(ServiceSet.TempFilePath + Templatexnlist[j].InnerText); } else { return(false); } } catch (Exception ex) { SeatManage.SeatManageComm.WriteLog.Write(string.Format("优惠券{0}上传失败:{1}", advertModel.Number, ex.Message)); } } } } } if (seatModel != null && seatModel.CampusNum == advertModel.CampusNum) { //获取学校数据库中的优惠券。如果存在并且校区编号相同执行更新。 seatModel.CampusNum = advertModel.CampusNum; seatModel.CustomerLogo = advertModel.CustomerImage; seatModel.EffectDate = Convert.ToDateTime(advertModel.EffectDate); seatModel.EndDate = Convert.ToDateTime(advertModel.EndDate); seatModel.ImageName = advertModel.ImageUrl; seatModel.No = advertModel.Number; seatModel.SlipTemplate = advertModel.SlipTemplate; seatModel.IsPrint = Convert.ToBoolean(advertModel.IsPrint); SeatManage.Bll.AMS_SlipCustomer.UpdateSlipCustomer(seatModel); } else { seatModel = new SeatManage.ClassModel.AMS_SlipCustomer(); seatModel.CampusNum = advertModel.CampusNum; seatModel.CustomerLogo = advertModel.CustomerImage; seatModel.EffectDate = Convert.ToDateTime(advertModel.EffectDate); seatModel.EndDate = Convert.ToDateTime(advertModel.EndDate); seatModel.ImageName = advertModel.ImageUrl; seatModel.No = advertModel.Number; seatModel.SlipTemplate = advertModel.SlipTemplate; seatModel.IsPrint = Convert.ToBoolean(advertModel.IsPrint); seatModel.Num = advertModel.Number; SeatManage.Bll.AMS_SlipCustomer.AddSlipCustomer(seatModel); } } return(true); } catch (Exception ex) { SeatManage.SeatManageComm.WriteLog.Write(string.Format("获取优惠券客户失败:{0}", ex.Message)); return(false); } }
/// <summary> /// 获取和更新打印模板 /// </summary> /// <param name="id"></param> /// <returns></returns> public static bool GetPrintTemplate(int id) { try { AMS.Model.AMS_PrintTemplate printTemplate = AMS.ServiceProxy.IPrintTemplateService.GetPrintTemplateByNum(id); if (printTemplate != null) { SeatManage.ClassModel.AMS_PrintTemplateModel model = new SeatManage.ClassModel.AMS_PrintTemplateModel(); model.Describe = printTemplate.Describe; model.EndDate = Convert.ToDateTime(printTemplate.EndDate); model.EffectDate = Convert.ToDateTime(printTemplate.EffectDate); model.Template = printTemplate.Template; model.Num = printTemplate.Number; List <string> imagesName = GetImagesName(model.Template); //下载打印模版中的图片 AMS.ServiceProxy.FileOperate fileOperate = new AMS.ServiceProxy.FileOperate(); for (int i = 0; i < imagesName.Count; i++) { string fileFullName = string.Format(@"{0}{1}", ServiceSet.TempFilePath, imagesName[i]); if (!File.Exists(fileFullName))//文件不存在,则下载。 { if (fileOperate.FileDownLoad(fileFullName, imagesName[i], SeatManage.EnumType.SeatManageSubsystem.SeatSlip) != "") { return(false);//下载失败,返回false; } } } //下载完成,执行上传操作。 SeatManage.Bll.FileOperate seatFileOperate = new SeatManage.Bll.FileOperate(); for (int i = 0; i < imagesName.Count; i++) { string fileFullName = string.Format(@"{0}{1}", ServiceSet.TempFilePath, imagesName[i]); if (File.Exists(fileFullName))//文件不存在,则下载。 { if (!seatFileOperate.UpdateFile(fileFullName, imagesName[i], SeatManage.EnumType.SeatManageSubsystem.SeatSlip)) { return(false);//下载失败,返回false; } } } if (SeatManage.Bll.T_SM_PrintTemplate.GetPrintTemplateByNum(printTemplate.Number) == null) { if (SeatManage.Bll.T_SM_PrintTemplate.AddPrintTemplate(model) == SeatManage.EnumType.HandleResult.Successed) { //打印模板添加成功,上传文件 for (int i = 0; i < imagesName.Count; i++) { string fileFullName = string.Format(@"{0}{1}", ServiceSet.TempFilePath, imagesName[i]); if (File.Exists(fileFullName))//文件存在则删除。 { File.Delete(fileFullName); } } return(true); } else { return(false); } } else { if (SeatManage.Bll.T_SM_PrintTemplate.UpdatePrintTemplate(model) == SeatManage.EnumType.HandleResult.Successed) { //打印模板添加成功,上传文件 for (int i = 0; i < imagesName.Count; i++) { string fileFullName = string.Format(@"{0}{1}", ServiceSet.TempFilePath, imagesName[i]); if (File.Exists(fileFullName))//文件存在则删除。 { File.Delete(fileFullName); } } return(true); } else { return(false); } } } else { //如果获取为空的,也作完成操作 return(true); } } catch (Exception ex) { throw ex; } }