Exemple #1
0
        public void SaveConfigShop(string name, string value)
        {
            XMLHelp xmlhelp = new Common.XMLHelp("/XmlConfig/shop.config");

            xmlhelp.SetXmlNodeValue("//" + name, value.ToString());
            xmlhelp.SavexmlDocument();
            RefreshConfigShop();
        }
Exemple #2
0
 /// <summary>
 /// 导出excel
 /// </summary>
 /// <typeparam name="T">集合列表里对象的类型</typeparam>
 /// <param name="list">数据列表</param>
 /// <returns></returns>
 protected FileResult ToExcel(DataTable list)
 {
     #region 获取XML
     XMLHelp xmlhelp = new Common.XMLHelp(string.Format("/XmlConfig/excel/{0}-{1}.xml", ControllerContext.RouteData.DataTokens["area"].ToString(), ControllerContext.RouteData.Values["controller"].ToString()));
     var     fields  = xmlhelp.GetList <Xml_Field>().Select(a => new KeyValuePair <string, string>(a.code, a.name)).ToList();
     #endregion
     var dirPath = Server.MapPath("/upload/toexcel/");
     if (System.IO.Directory.Exists(dirPath) == false)
     {
         System.IO.Directory.CreateDirectory(dirPath);
     }
     var filePath = string.Format("{0}{1}.xls", dirPath, System.Guid.NewGuid().ToString());
     ExcelHelp.ToExcelByNPOI(list, filePath, fields);
     return(File(filePath, "application/vnd.ms-excel"));
 }
Exemple #3
0
 /// <summary>
 /// 自动设置本系统域名网址
 /// </summary>
 /// <param name="Request"></param>
 public void AutoSetUrl(System.Web.HttpRequestBase Request)
 {
     try
     {
         //if (string.IsNullOrEmpty(entity.weburl) || entity.weburl.StartsWith("http://localhost") || entity.weburl.StartsWith("http://127.0.0.1"))
         {
             //修改成当前地址的
             var url = Request.Url.ToString();
             XmlSite.weburl = url.Substring(0, url.IndexOf("/", 7));
             XMLHelp xmlhelp = new Common.XMLHelp("/XmlConfig/site.config");
             xmlhelp.SetXmlNodeValue("//weburl", XmlSite.weburl);
             xmlhelp.SavexmlDocument();
         }
     }
     catch (Exception e)
     {
         LogHelper.Error("自动设置网址域名出错:" + Request?.Url);
     }
 }
Exemple #4
0
        public void RefreshConfigShop()
        {
            XMLHelp xmlhelp = new Common.XMLHelp("/XmlConfig/shop.config");

            xmlshop = new Xml_Shop();
            #region 通过反射来取各个字段
            var type = typeof(Xml_Shop);
            var ps   = type.GetProperties();
            foreach (var item in ps)
            {
                var name  = item.Name;
                var value = WebTools.ChangeType(xmlhelp.GetNodeValue(name), item.PropertyType);
                if (value != null && !string.IsNullOrEmpty(value.ToString()))
                {
                    item.SetValue(xmlshop, value);
                }
            }
            #endregion
        }
Exemple #5
0
        public void SaveShop(Xml_Shop entity)
        {
            XMLHelp xmlhelp = new Common.XMLHelp("/XmlConfig/shop.config");

            #region 通过反射来取各个字段
            var type = typeof(DataBase.Xml_Shop);
            var ps   = type.GetProperties();
            foreach (var item in ps)
            {
                var name  = item.Name;
                var value = item.GetValue(entity);
                if (value != null)
                {
                    xmlhelp.SetXmlNodeValue("//" + item.Name, value.ToString());
                }
            }
            #endregion
            xmlhelp.SavexmlDocument();
            RefreshConfigShop();
        }
        public ActionResult Save(DataBase.Xml_Site entity)
        {
            JsonHelp json = new JsonHelp()
            {
                Status = "n", Msg = "保存失败"
            };

            try
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendFormat("原值:");

                XMLHelp xmlhelp = new Common.XMLHelp("/XmlConfig/site.config");
                #region 通过反射来取各个字段
                var type = typeof(DataBase.Xml_Site);
                var ps   = type.GetProperties();
                #region 先列出原来的值
                {
                    var m = DB.XmlConfig.XmlSite;
                    foreach (var item in ps)
                    {
                        var name  = item.Name;
                        var value = item.GetValue(m);
                        if (value != null)
                        {
                            sb.AppendFormat("{0}:{1},", name, value);
                        }
                    }
                }
                #endregion
                foreach (var item in ps)
                {
                    var name  = item.Name;
                    var value = item.GetValue(entity);
                    if (value != null)
                    {
                        xmlhelp.SetXmlNodeValue("//" + item.Name, value.ToString());
                    }
                }
                #endregion
                xmlhelp.SavexmlDocument();
                DB.XmlConfig.RefreshConfigSite();
                #region 列出新的值
                {
                    var m = DB.XmlConfig.XmlSite;
                    sb.AppendFormat("新值:");
                    foreach (var item in ps)
                    {
                        var name  = item.Name;
                        var value = item.GetValue(m);
                        if (value != null)
                        {
                            sb.AppendFormat("{0}:{1},", name, value);
                        }
                    }
                }
                #endregion
                LogHelper.Info(sb.ToString());
                json.Status = "y";
                json.Msg    = "保存成功";
            }
            catch (Exception e)
            {
                LogHelper.Error("保存系统配置参数出错:" + e.Message);
            }
            return(Json(json));
        }