Beispiel #1
0
        void fileUpload()
        {
            if (!string.IsNullOrEmpty(vm.BuildUpdateFile()))
            {
                MessageBox.Show("版本号有重复,请修改版本号");
                return;
            }
            updateProgress.Dispatcher.Invoke(new Action(() =>
            {
                updateProgress.Visibility = System.Windows.Visibility.Visible;
            }));

            AdvertManage.BLL.FileOperate fileUpdate = new AdvertManage.BLL.FileOperate();
            for (int i = 0; i < vm.FilePaths.Count; i++)
            {
                string p        = vm.FilePaths[i];
                string fullpath = string.Format(@"{0}{1}", vm.DirPath, p);
                fileUpdate.UpdateFile(fullpath, p, (SeatManage.EnumType.SeatManageSubsystem)(int) vm.SystemType);

                updateProgress.Dispatcher.Invoke(new Action(() =>
                {
                    updateProgress.Value = ((double)i / (vm.FilePaths.Count - 1)) * 100;
                    lblProgress.Content  = (int)updateProgress.Value + "%";
                }));
            }

            updateProgress.Dispatcher.Invoke(new Action(() =>
            {
                updateProgress.Visibility = System.Windows.Visibility.Collapsed;
                lblProgress.Content       = "已经完成";
            }));
            vm.SystemUpdate();
            MessageBox.Show("上传完成");
            if (HandlerOver != null)
            {
                HandlerOver(this, new EventArgs());
            }
        }
Beispiel #2
0
        /// <summary>
        /// 根据ID获取优惠券信息
        /// </summary>
        /// <returns></returns>
        public static bool GetSlipCustomer(int id)
        {
            //TODO:未测试
            try
            {
                Model.AMS_SlipCustomerModel  advertModel           = BLL.SlipReleaseCampusBLL.GetSlipReleaseListById(id);
                AdvertManage.BLL.FileOperate advertfileOperate     = new AdvertManage.BLL.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 (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   = advertModel.EffectDate;
                        seatModel.EndDate      = advertModel.EndDate;
                        seatModel.ImageName    = advertModel.ImageUrl;
                        seatModel.No           = advertModel.Number;
                        seatModel.SlipTemplate = advertModel.SlipTemplate;
                        seatModel.IsPrint      = 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   = advertModel.EffectDate;
                        seatModel.EndDate      = advertModel.EndDate;
                        seatModel.ImageName    = advertModel.ImageUrl;
                        seatModel.No           = advertModel.Number;
                        seatModel.SlipTemplate = advertModel.SlipTemplate;
                        seatModel.IsPrint      = advertModel.IsPrint;
                        SeatManage.Bll.AMS_SlipCustomer.AddSlipCustomer(seatModel);
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                SeatManage.SeatManageComm.WriteLog.Write(string.Format("获取优惠券客户失败:{0}", ex.Message));
                return(false);
            }
        }
Beispiel #3
0
        public bool DownLoad(string downloadpath)
        {
            try
            {
                downloadpath = downloadpath + "\\PrintTemplate_" + AdvertManage.BLL.ServerDateTime.Now.Value.ToShortDateString();
                DirectoryInfo dir = new DirectoryInfo(downloadpath);
                if (!dir.Exists)
                {
                    dir.Create();
                }
                else
                {
                    throw new Exception("存在相同的文件夹,请重新选择目录!");
                }
                //创建一个xml对象
                XmlDocument xmlDoc = new XmlDocument();
                //创建开头
                XmlDeclaration dec = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);
                xmlDoc.AppendChild(dec);
                //创建根节点
                XmlElement root = xmlDoc.CreateElement("Root");
                //创建二级节点
                XmlElement SecNode = xmlDoc.CreateElement("PrintTemplate");
                SecNode.SetAttribute("Template", _Template.ToString());
                SecNode.SetAttribute("StartTime", _StartTime.ToShortDateString());
                SecNode.SetAttribute("EndTime", _EndTime.ToShortDateString());
                SecNode.SetAttribute("Describe", _Describe);
                //下载图片
                List <string> imagepath = GetImagesName(_Template.ToString());
                //下载打印模版中的图片
                AdvertManage.BLL.FileOperate fileOperate = new AdvertManage.BLL.FileOperate();
                for (int i = 0; i < imagepath.Count; i++)
                {
                    string fileFullName = string.Format(@"{0}{1}", downloadpath + "\\", imagepath[i]);
                    if (!File.Exists(fileFullName))//文件不存在,则下载。
                    {
                        if (!fileOperate.FileDownLoad(fileFullName, imagepath[i], SeatManage.EnumType.SeatManageSubsystem.SeatSlip))
                        {
                            return(false);//下载失败,返回false;
                        }
                    }
                }

                root.AppendChild(SecNode);
                //在根节点中添加二级节点
                root.AppendChild(SecNode);
                //添加根节点
                xmlDoc.AppendChild(root);
                //写入XML
                string xmlpath = downloadpath + "\\TemplateInfo.xml";
                //写入文件
                FileStream   fs = new FileStream(xmlpath, FileMode.Create, FileAccess.Write);
                StreamWriter sw = new StreamWriter(fs);
                sw.Write(xmlDoc.OuterXml);
                sw.Close();
                fs.Close();


                return(true);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
                return(false);
            }
        }
Beispiel #4
0
 /// <summary>
 /// 导出离线版优惠券
 /// </summary>
 public bool SCDownLoad(string dripath)
 {
     try
     {
         foreach (SlipNodes schoolnode in _SchoolList)
         {
             foreach (SlipNodes campusnode in schoolnode.ChildNode)
             {
                 if (campusnode.IsChecked)
                 {
                     string        DialogLocad = dripath + "\\" + DateTime.Now.ToShortDateString() + "_" + schoolnode.Name + "_" + campusnode.Name + "_优惠劵广告\\";
                     DirectoryInfo d           = new DirectoryInfo(DialogLocad);
                     if (d.Exists)
                     {
                         throw new Exception("已存在相同的文件夹!");
                     }
                     d.Create();
                     //创建一个xml对象
                     XmlDocument xmlDoc = new XmlDocument();
                     //创建开头
                     XmlDeclaration dec = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);
                     xmlDoc.AppendChild(dec);
                     //创建根节点
                     XmlElement root = xmlDoc.CreateElement("Root");
                     //创建二级节点
                     XmlElement SecNode = xmlDoc.CreateElement("ADItems");
                     root.AppendChild(SecNode);
                     //遍历全部的项目
                     foreach (int itemid in _ReleaseSlipid)
                     {
                         AdvertManage.Model.AMS_SlipCustomerModel itemModel = AdvertManage.BLL.AMS_SlipCustomerBLL.GetSlipCustomerById(itemid);
                         XmlElement ThirdNode = xmlDoc.CreateElement("AD");
                         ThirdNode.SetAttribute("no", itemModel.Number);
                         ThirdNode.SetAttribute("CampusNum", campusnode.Number);
                         ThirdNode.SetAttribute("EffectDate", itemModel.EffectDate.ToString());
                         ThirdNode.SetAttribute("EndDate", itemModel.EndDate.ToString());
                         ThirdNode.SetAttribute("ImageUrl", itemModel.ImageUrl);
                         ThirdNode.SetAttribute("CustomerImage", itemModel.CustomerImage);
                         if (itemModel.IsPrint)
                         {
                             ThirdNode.SetAttribute("IsPrint", "1");
                         }
                         else
                         {
                             ThirdNode.SetAttribute("IsPrint", "0");
                         }
                         ThirdNode.SetAttribute("SlipTemplate", itemModel.SlipTemplate);
                         SecNode.AppendChild(ThirdNode);
                         //复制图片
                         AdvertManage.BLL.FileOperate fo = new AdvertManage.BLL.FileOperate();
                         if (itemModel.IsPrint)
                         {
                             XmlDocument Templatedoc = new XmlDocument();
                             Templatedoc.LoadXml(itemModel.SlipTemplate);
                             XmlElement  Templateroot   = Templatedoc.DocumentElement;
                             XmlNodeList Templatexnlist = ((XmlNode)Templateroot).ChildNodes;
                             for (int j = 0; j < Templatexnlist.Count; j++)
                             {
                                 if (Templatexnlist[j].Name == "Pic")
                                 {
                                     if (!fo.FileDownLoad((d.FullName + Templatexnlist[j].InnerText), Templatexnlist[j].InnerText, SeatManageSubsystem.SlipCustomer))
                                     {
                                         throw new Exception("优惠券图片下载失败!");
                                     }
                                 }
                             }
                         }
                         if (!fo.FileDownLoad((d.FullName + itemModel.CustomerImage), itemModel.CustomerImage, SeatManageSubsystem.SlipCustomer))
                         {
                             throw new Exception("优惠图片下载失败!");
                         }
                         if (!fo.FileDownLoad((d.FullName + itemModel.ImageUrl), itemModel.ImageUrl, SeatManageSubsystem.SlipCustomer))
                         {
                             throw new Exception("logo图片下载失败!");
                         }
                     }
                     //在根节点中添加二级节点
                     root.AppendChild(SecNode);
                     //添加根节点
                     xmlDoc.AppendChild(root);
                     //写入XML
                     string xmlpath = DialogLocad + "\\SlipCustomerList.xml";
                     //写入文件
                     FileStream   fs = new FileStream(xmlpath, FileMode.Create, FileAccess.Write);
                     StreamWriter sw = new StreamWriter(fs);
                     sw.Write(xmlDoc.OuterXml);
                     sw.Close();
                     fs.Close();
                 }
             }
         }
         return(true);
     }
     catch (Exception ex)
     {
         System.Windows.Forms.MessageBox.Show(ex.Message);
         return(false);
     }
 }