1. using System; 
  2. using System.Collections.Generic; 
  3. using System.Text; 
  4. using System.Xml; 
  5. using Yefor.Framework.ToolKit; 
  6. using System.Data; 
  7. using System.IO; 
  8.  
  9. namespace Yefor.CM.Business.Extra 
  10.    public class PictureChange 
  11.     { 
  12.         #region 属性值 
  13.         private string xmlconfig = ""
  14.         public string Xmlconfig 
  15.         { 
  16.             set { xmlconfig = value; } 
  17.             get { return xmlconfig; } 
  18.         } 
  19.         private string xmlEmpConfig = ""
  20.         public string XmlEmpConfig 
  21.         { 
  22.             set { xmlEmpConfig = value; } 
  23.             get { return xmlEmpConfig; } 
  24.         } 
  25.         XmlDocument xmldoc = null
  26.         public enum taobaoState { AMState, PMState, defaultState }; 
  27.         #endregion 
  28.         #region 方法 
  29.  
  30.         public PictureChange() 
  31.         { 
  32.         //初始化 
  33.         } 
  34.         public PictureChange(string configPath) 
  35.         { 
  36.             xmlconfig = configPath; 
  37.         } 
  38.         public DataSet GetShopList() 
  39.         { 
  40.             xmldoc = new XmlDocument(); 
  41.             xmldoc.Load(xmlconfig); 
  42.             DataSet ds = new DataSet(); 
  43.             ds.ReadXml(new System.IO.StringReader(xmldoc.InnerXml));//转化为DATASET对象 
  44.             return ds; 
  45.         } 
  46.  
  47.         /// <summary> 
  48.         /// 从指定的XML文件读出数据为dataset 
  49.         /// </summary> 
  50.         /// <param name="filePath">文件路径</param> 
  51.         /// <returns></returns> 
  52.         public DataSet GetShopList(string filePath) 
  53.         { 
  54.             xmldoc = new XmlDocument(); 
  55.             xmldoc.Load(filePath); 
  56.             DataSet ds = new DataSet(); 
  57.             ds.ReadXml(new System.IO.StringReader(xmldoc.InnerXml));//转化为DATASET对象 
  58.             return ds; 
  59.         } 
  60.  
  61.         /// <summary> 
  62.         /// 获取指定目录下所有文件 
  63.         /// </summary> 
  64.         /// <param name="directoryPath"></param> 
  65.         /// <returns></returns> 
  66.         public IList<string> GetFileList(string directoryPath) 
  67.         { 
  68.             string PhyPath = System.Web.HttpContext.Current.Server.MapPath(directoryPath); 
  69.  
  70.             DirectoryInfo dirinfo = new DirectoryInfo(PhyPath); 
  71.             FileInfo[] fino = dirinfo.GetFiles(); 
  72.  
  73.             IList<string> arrlist = new List<string>(); 
  74.  
  75.  
  76.             foreach (FileInfo fn in fino) 
  77.             { 
  78.                 arrlist.Add(directoryPath + fn.Name); 
  79.             }//遍历所有文件名,拼接虚拟路径 
  80.  
  81.             return arrlist; 
  82.         } 
  83.  
  84.         /// <summary> 
  85.         /// 从指定的empid复制到指定的shopid 
  86.         /// </summary> 
  87.         /// <param name="empid"></param> 
  88.         /// <param name="shopid"></param> 
  89.         /// <returns></returns> 
  90.         public bool ExcuteEmp(string empid, string shopid) 
  91.         { 
  92.             bool isSuccess = false
  93.             string sourcePath = InitSourcePath(empid); 
  94.             string targetPath = InitTargetPath(shopid); 
  95.             IList<string> sourceFileList = GetFileList(sourcePath); 
  96.             IList<string> targetFileList = GetFileList(targetPath); 
  97.             try 
  98.             { 
  99.                 for (int i = 0; i < sourceFileList.Count; i++) 
  100.                 { 
  101.                     FileHelper.CopyFile(sourceFileList[i], targetFileList[i]); 
  102.                     //System.Web.HttpContext.Current.Response.Write(targetFileList[i]); 
  103.                 } 
  104.                 isSuccess = true
  105.             } 
  106.             catch (Exception ex) 
  107.             { 
  108.                 isSuccess = false
  109.                 //throw new Exception(ex.Message); 
  110.             } 
  111.  
  112.  
  113.  
  114.             return isSuccess; 
  115.         } 
  116.  
  117.        /// <summary> 
  118.        /// 根据ID获取内容 
  119.        /// </summary> 
  120.        /// <param name="shopid"></param> 
  121.        /// <returns></returns> 
  122.        private string InitTargetPath(string shopid) 
  123.        { 
  124.            string xnNodeName = "now"
  125.            xmldoc = new XmlDocument(); 
  126.            xmldoc.Load(xmlconfig);//tbshopstate.xml 
  127.            return GetXmlNoteRoot(xmldoc,shopid, xnNodeName); 
  128.        } 
  129.  
  130.        /// <summary> 
  131.        /// 找到指定的XML内容 
  132.        /// </summary> 
  133.        /// <param name="xdc"></param> 
  134.        /// <param name="id"></param> 
  135.        /// <param name="xnNodeName"></param> 
  136.        /// <returns></returns> 
  137.        private string GetXmlNoteRoot(XmlDocument xdc, string id, string xnNodeName) 
  138.        { 
  139.            string xmlTextPath = string.Empty; 
  140.  
  141.            XmlNodeList xlist2 = xdc.SelectSingleNode("root").ChildNodes; 
  142.            foreach (XmlNode xn in xlist2)//找到shoplist 
  143.            { 
  144.                if (xn.Attributes["id"].Value == id) 
  145.                { 
  146.                    xmlTextPath = xn[xnNodeName].InnerText; 
  147.                    break;//找到就退出循环 
  148.                } 
  149.            } 
  150.            return xmlTextPath; 
  151.        } 
  152.  
  153.  
  154.        /// <summary> 
  155.        /// 根据指定的id初始化 
  156.        /// </summary> 
  157.        /// <param name="empid"></param> 
  158.        /// <returns></returns> 
  159.        private string InitSourcePath(string empid) 
  160.        { 
  161.            xmldoc = new XmlDocument(); 
  162.            xmldoc.Load(xmlEmpConfig);//empConfig.xml 
  163.            string xnNodeName = "dirPath"
  164.            return GetXmlNoteRoot(xmldoc, empid, xnNodeName); 
  165.        } 
  166.  
  167.         /// <summary> 
  168.         /// 正常交接班的情况,递归算法 
  169.         /// </summary> 
  170.         /// <param name="shopid"></param> 
  171.         /// <param name="x"></param> 
  172.         /// <returns></returns> 
  173.         public bool XmlFileCopy(string shopid, taobaoState x) 
  174.         { 
  175.             bool isSuccess = false
  176.             IList<string> source = null;//源文件 
  177.             IList<string> target = null;//目标文件 
  178.             string[] picPath ={ """""""" };//四张图片的路径 
  179.             xmldoc = new XmlDocument(); 
  180.             xmldoc.Load(xmlconfig); 
  181.             XmlNodeList xnlist = xmldoc.SelectSingleNode("root").ChildNodes; 
  182.  
  183.             if (shopid == "000"
  184.             { 
  185.                 //所有店铺均复制各自设定的代码 
  186.  
  187.                 foreach (XmlNode xnd in xnlist)//遍历所有店铺ID,执行覆盖操作 
  188.                 { 
  189.                     if (xnd.Attributes["id"].Value == "000")//防止进入死循环 
  190.                     { 
  191.                         continue
  192.                     } 
  193.  
  194.                     XmlFileCopy(xnd.Attributes["id"].Value, x); 
  195.  
  196.                 } 
  197.  
  198.                 return true
  199.  
  200.             } 
  201.             else//指定店铺操作 
  202.             { 
  203.  
  204.                 foreach (XmlNode xn in xnlist) 
  205.                 { 
  206.                     if (xn.Attributes["id"].Value == shopid) 
  207.                     { 
  208.                         picPath[0] = xn["now"].InnerText; 
  209.  
  210.  
  211.                         picPath[1] = xn["picGroupA"].InnerText; 
  212.                         picPath[2] = xn["picGroupB"].InnerText; 
  213.                         picPath[3] = xn["picGroupC"].InnerText; 
  214.  
  215.  
  216.                         break;//找到所需值,退出循环 
  217.                     } 
  218.                 }//找到该店铺的图片 
  219.  
  220.                 source = GetFileList(picPath[Convert.ToInt32(x) + 1]);//Source Directory File List 
  221.                 target = GetFileList(picPath[0]);//target Directory File List 
  222.  
  223.             } 
  224.  
  225.             try 
  226.             { 
  227.                 //if (source.Count != target.Count) 
  228.                 //{ 
  229.                 //    throw new Exception("源文件数量和目标文件数量不一致"); 
  230.                 //} 
  231.  
  232.  
  233.                 for (int i = 0; i < source.Count; i++) 
  234.                 { 
  235.                     FileHelper.CopyFile(source[i], target[i]); 
  236.                 } 
  237.  
  238.  
  239.                 isSuccess = true
  240.             } 
  241.             catch (Exception ex) 
  242.             { 
  243.  
  244.                 //throw new Exception(ex.Message); 
  245.  
  246.                 isSuccess = false
  247.             } 
  248.  
  249.             return isSuccess; 
  250.         } 
  251.         #endregion 
  252.     }