前两天朋友叫自身模仿一个网址,刚刚开头,作者三个页面3个页面查看源码并复制和封存,花了自个儿无数光阴,3个字“累”,为了减轻工业作量,作者写了个网址“克隆工具”,1键克隆,比起人工操作, 
频率升高了200%以上,精确度也大大提升,尽管网上也不少网址克隆工具,但本人觉得作为2个程序员,要有点讨论精神,哈哈哈,能够依据本人的要求自由编写本身供给的职能。

前言:此”飞速变动后台“为自笔者参考discuz开源代码效果组装而成。无高深技术,只讲究快速生成,适合建设中型小型型网址。运用安妥能够批量生产网址后台。

懒人小工具:T四自动生成Model,Insert,Select,Delete以及导出Excel的法子
在开发的历程中,我们为了节省时间,往往会将多量再次机械的代码封装,思虑代码的复用性,那样大家能够省去很多时日来做其余事情。近年来跳槽到壹节webform开发的信用合作社,首借使付出协调集团用的ECRUISERP。起首致的原因为有个别引发进来的,未来感到其实某个后悔遗弃了很好的学习ABP以及新知识点像有的很前卫的前端框架进那些公司。但以往跳槽也不是一个明智之举,不佳意思扯远了,既来之则安之。近年来写了个小工具。主要针对webform开发进程中有的再一次的代码处理。
其实并未有啥尤其大的技术难度,其实webform开发貌似也并未有专门大的技术难度。
先是新建一个类库WorkHelper。
下一场新建类Program.cs,那里是作为主程序入口。

新近在做3个SL的档次,做完后,蒙受三个F5刷新的题材,本身也是首先次接触接触SL项目,记得再ASP.NET浏览器的缓存会自动保存最终一遍的浏览记录的。

上面作者将本身写的“网址克隆工具”完毕形式分享给我们,源码在文末有下载链接,有须要的情人可以下载来玩,也得以依据自个儿的急需做相应的修改或优化。

 

using System;
using System.Windows.Forms;

namespace DevLogHelper
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new BaseSqlBuilder());
        }

    }
}

之所以就在网上随处找资料,可惜命局不好,都没找到适合的资料。基本的化解措施都以透过再HTML页面扩展JS方法,屏蔽F伍刷新按钮的功力,可是那样的须求并不是大家项目中所要的,幸而在BAIDU和群里高手的辅助下,终于大体掌握了SL刷新的长河和缓解F五刷新再次回到最终次浏览页面包车型地铁考虑。。

一睹为快,先看看界面:

以三个谍报系统为例子,写出详细建设进度,分享一下,以备后用。涉及工具有:VS2010、PowerDesigner、SQL Server 二零零六、DBBuildCode、ultraedit。

为Main()方法加上STAThread标签。每一次只好运维1个窗口。
new
二个BaseSqlBuilder实例,BaseSqlBuilder实例是何许啊,正是我们明日的主旨了。

F伍刷新难点,急速变动后台。壹:SL刷新进度

金沙注册送58 1

 

金沙注册送58 2

SL自身就是HTML页面包车型大巴多少个插件程序,在浏览器退出或许F5刷新的时候,SL自身首先调用自个儿的APP.xaml
的 Application_Exit
方法,然后再次进入浏览器的时候加载Application_Startup方法,一般都以用Application_Startup
方法去设定SL程序的启航初步界面。

 

一、设计页面

1.png

知道了SL运行的进度本身想完结F五刷新难题就简单了,

归纳的工作流程:

 

实质上界面特别简单的。便是多少个label、多选框、容器。
看下代码:

二:F伍刷新解决思路

金沙注册送58 3

一、打开VS200玖,新建三个空网址,保存至News文件夹。

using System;
using System.Resources;
using System.Text;
using System.Windows.Forms;
using DevLogHelper.Resources;

namespace DevLogHelper
{
    public partial class BaseSqlBuilder : Form
    {
        readonly ResourceManager _rm = new ResourceManager(typeof(ResourceDevCode));
        public BaseSqlBuilder()
        {
            InitializeComponent();
        }

        private void BaseSqlBuilder_Load(object sender, EventArgs e)
        {

        }
        /// <summary>
        /// 生成
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCreate_Click(object sender, EventArgs e)
        {
            string msg = _rm.GetString("BaseSqlTip");
            try
            {
                BaseSql.BaseSql sq = new BaseSql.BaseSql();
                StringBuilder str = sq.BuilderCode(txtInput.Text, cbIsModel, txt_TableName.Text, ckb_Model.Checked, ckb_Insert.Checked,ckb_Update.Checked,ckb_Select.Checked,ckb_Delete.Checked,ckbExcel.Checked);
                txtResult.Text = str.ToString();
                Clipboard.SetDataObject(str.ToString());
            }
            catch (Exception ex)
            {
                msg = ex.Message;
            }
            labTip.Text = msg;
        }

    }
}

首先在当地建立单独存款和储蓄(老板KIE也能够,不过不晓得干什么用CEOKIE的话,SL项目用火狐浏览访问数据就有标题,以待现在切磋。)

 

 

窗体BaseSqlBuilder继承自Form不必多说。ResourceManager是何等啊,ResourceManager正是二个财富文件,用于拍卖消息,也许路径如何。前边补上海教室。
新建2个BaseSql用于拍卖sql。把页面上的控件新闻传递过去。封装1个数额的形式。

为了不难门船解说进程,本文的老板KIE就封存二个值:

类型代码目录结构:

金沙注册送58 4

能源文件以及缓解方案结构。

UserID:用户账号消息

金沙注册送58 5

 

金沙注册送58 6

PageAddress:最后次浏览页面地址

 

 

4R9QU1Y7XFDV43BKKBVDUK3.png

ExitTime:退出时间  

下边一步步完结程序效率:

二、添加新项:NewsList.aspx、News艾德it.aspx一个Web窗体,新建文件夹:Style(main.css、general.css),新建文件夹:Images(界面所需图片)。

跟踪BuilderCode到BaseSql类。

1>系统初步化加载的时候,判断本地存款和储蓄是不是有数据,并且判断当前时间与上次退出时间差
是不是低于5秒,(作者那边运用五秒作为刷新和重复登录的正式,当然仁同一视)

 

 

金沙注册送58 7

二>倘若地方条件建立,咋直接依照账号音信,加载系统主界面,并将Navigation
的IFRAM 地址指向本地存款和储蓄的上次保存地址即可。

1.新建主界面窗体(MainForm.cs):

金沙注册送58 8

87C8U$IKXP(%OJ{M~HT2YPA.png

3>若是不树立,显示登录界面,并排除本地存储数据,登录后再也赋值账号新闻

金沙注册送58 9

 

第二是对控件传递过来值得检查,参数是不是为空等。

四>伴随着SL界面包车型客车浏览,操作界面包车型大巴时候还要革新本地存款和储蓄的页面地址值

2.新建立模型型类(UrlModel.cs)

 

            string Table = inputSql[2].ToString();
            if (string.IsNullOrWhiteSpace(inputCode))
            {
                inputCode = "select *from " + Table;
            }
            StringBuilder returnstr = new StringBuilder();
            StringBuilder strBuilder = new StringBuilder();
            DataSet ds = SqlHelper.Query(inputCode);
            DataRow dr = null;
            DataTable dt = new DataTable();

5>Application_Exit 事件里,扩展 slcookie.ExitTime =
DateTime.Now.ToString(); 时间的赋值

public class UrlModel
    {
        public string RelatedPath { get; set; }
        public string AbsoluteUri { get; set; }
        public string CurrPath { get; set; }
        public string RootPath { get; set; }

        public string Host { get; set; }
        public int Port { get; set; }
        public string Scheme { get; set; }
    }

叁、设计NewsList.aspx(音讯列表)、NewsEdit.aspx(音讯编辑)页面。

此地假使传递过来的sql语句为空,大家会依照表名自动生成查询SQL。然后依据ado.net
链接数据库生成DataSet 、DataRow 、DataTable
等。当然那里得有SqlHelper。SqlHelper假设须求能够去本身源码上下载,稍后会放上源码。首倘使链接数据库。执行SQL了。

OK! 全部思路大约如此,以往自个儿将以三个回顾的实例来详细表达

三.新建服务类(Services)

 

     #region 封装实体Model

   #region 封装实体Model

            strBuilder.AppendLine(@"
               public class Model
            {
               ");
            for (int i = 0; i < dr.Table.Columns.Count; i++)
            {
                if (i == 0)
                {
                    Id = dr.Table.Columns[0].ToString();//一般情况第一个字段是主键,当然如果第一个字段不是主键,那就需要修改了
                }
                string Type = dr.Table.Columns[i].DataType.ToString();
                switch (Type)
                {
                    case "System.String":
                        strBuilder.AppendLine("       private string " + "_" + dr.Table.Columns[i] + ";");
                        strBuilder.AppendLine("       public string " + dr.Table.Columns[i] + "");
                        strBuilder.AppendLine("         {");
                        strBuilder.AppendLine("            get { return " + "_" + dr.Table.Columns[i] + "; }");
                        strBuilder.AppendLine("            set { " + "_" + dr.Table.Columns[i] + " = value; }");
                        strBuilder.AppendLine("          }");
                        break;
                    case "System.Int":
                        strBuilder.AppendLine("       private Int " + "_" + dr.Table.Columns[i] + ";");
                        strBuilder.AppendLine("       public Int " + dr.Table.Columns[i] + "");
                        strBuilder.AppendLine("         {");
                        strBuilder.AppendLine("            get { return " + "_" + dr.Table.Columns[i] + "; }");
                        strBuilder.AppendLine("             set { " + "_" + dr.Table.Columns[i] + " = value; }");
                        strBuilder.AppendLine("         }");
                        break;
                    case "System.Int32":
                        strBuilder.AppendLine("       private Int " + "_" + dr.Table.Columns[i] + ";");
                        strBuilder.AppendLine("       public Int " + dr.Table.Columns[i] + "");
                        strBuilder.AppendLine("         {");
                        strBuilder.AppendLine("            get { return " + "_" + dr.Table.Columns[i] + "; }");
                        strBuilder.AppendLine("             set { " + "_" + dr.Table.Columns[i] + " = value; }");
                        strBuilder.AppendLine("         }");
                        break;
                    case "System.DateTime":
                        strBuilder.AppendLine("       private System.DateTime " + "_" + dr.Table.Columns[i] + ";");
                        strBuilder.AppendLine("       public System.DateTime " + dr.Table.Columns[i] + "");
                        strBuilder.AppendLine("          {");
                        strBuilder.AppendLine("             get { return " + "_" + dr.Table.Columns[i] + "; }");
                        strBuilder.AppendLine("             set { " + "_" + dr.Table.Columns[i] + " = value; }");
                        strBuilder.AppendLine("          }");
                        break;
                    case "System.Decimal":
                        strBuilder.AppendLine("       private System.Decimal " + "_" + dr.Table.Columns[i] + ";");
                        strBuilder.AppendLine("       public System.Decimal " + dr.Table.Columns[i] + "");
                        strBuilder.AppendLine("        {");
                        strBuilder.AppendLine("            get { return " + "_" + dr.Table.Columns[i] + "; }");
                        strBuilder.AppendLine("            set { " + "_" + dr.Table.Columns[i] + " = value; }");
                        strBuilder.AppendLine("         }");
                        break;
                    default:
                        strBuilder.AppendLine("       private string " + "_" + dr.Table.Columns[i] + ";");
                        strBuilder.AppendLine("       public string " + dr.Table.Columns[i] + "");
                        strBuilder.AppendLine("        {");
                        strBuilder.AppendLine("             get { return " + "_" + dr.Table.Columns[i] + "; }");
                        strBuilder.AppendLine("             set { " + "_" + dr.Table.Columns[i] + " = value; }");
                        strBuilder.AppendLine("         }");
                        break;
                }
            }
            strBuilder.AppendLine(@"
              }
               ");

            #endregion

1、新建项目SLF伍

UrlParser:

金沙注册送58 10 

第2大家是生成Model。有了Model才有下边包车型大巴增加和删除改查的方法。
实在也很简短,dr.Table.Columns[i].DataType.ToString(),大家正是基于DataRow循环table列,判断字段类型,然后依据对应的字段类型封装成model.单选框暗中认可勾选的,那里先祛除勾选,输入表名,点击生成,然后和多少库表对应,看一下意义。

打开VS2010,新建Silverlight应用程序,

public class UrlParser
    {
        public static UrlModel Parse(string url)
        {
            UrlModel model = new UrlModel();

            //默认
            if (url.Length < 8)
                throw new Exception("url参数不正确");
            else if (!url.ToLower().StartsWith("http:") && !url.ToLower().StartsWith("https:"))
                throw new Exception("url格式有误");

            if (url.LastIndexOf('/') < 8)
                url = url + "/";

            Regex reg = new Regex("(?<scheme>(http|https))://(?<host>.+?)/", RegexOptions.Singleline);

            if (reg.IsMatch(url))
            {
                string scheme = reg.Match(url).Groups["scheme"].Value;
                string host = reg.Match(url).Groups["host"].Value;
                if (host.Contains(":"))
                {
                    var aa = host.Split(':');
                    if (aa.Length == 2)
                    {
                        model.Host = aa[0];
                        model.Port = int.Parse(aa[1]);
                    }
                }
                else
                {
                    model.Host = host;
                    model.Port = 80;
                }

                int index = url.IndexOf('/', 8);

                model.RelatedPath = url.Substring(index);
                model.AbsoluteUri = url;
                model.Scheme = scheme;
                model.CurrPath = url.Substring(0, url.LastIndexOf("/"));

                if (80 == model.Port)
                {
                    model.RootPath = string.Format("{0}://{1}", model.Scheme, model.Host);
                }
                else
                {
                    model.RootPath = string.Format("{0}://{1}:{2", model.Scheme, model.Host, model.Port);
                }
            }
            else
            {
                throw new Exception("url解析失败!");
            }

            return model;
        }
    }

 

金沙注册送58 11

金沙注册送58 12

WebPageService:

金沙注册送58 13

2.png

并勾选在新网站中承载应用程序

/// <summary>
    /// 网页处理服务工具
    /// </summary>
    public class WebPageService
    {
        private static string[] excludekeys = { "http:", "https:", "//", "#", "javascript:", "?", "tel:", "mailto:" };
        /// <summary>
        /// 获取所有html元素的href属性值,只获取站点本地的链接,站外的不获取
        /// </summary>
        /// <param name="html">页面的html源码</param>
        /// <returns></returns>
        public static List<UrlModel> GetLocalHrefs(string url,string html)
        {
            if (string.IsNullOrEmpty(html))
                return new List<UrlModel>();

            Dictionary<string, UrlModel> urls = GetHrefs(url,html);
            List<UrlModel> newUrls = new List<UrlModel>();

            if (null != urls)
            {
                foreach (string key in urls.Keys)
                {
                    string newkey = key.ToLower();
                    bool iscontained = false;
                    foreach (var exkey in excludekeys)
                    {
                        if (newkey.IndexOf(exkey) == 0)
                        {
                            iscontained = true;
                            break;
                        }
                    }

                    if (!iscontained) {
                        //只获取本地路径
                        newUrls.Add(urls[key]);
                    }
                }
            }

            return newUrls;
        }

        /// <summary>
        /// 获取所有html元素的src属性值,只获取站点本地的链接,站外的不获取
        /// </summary>
        /// <param name="html">页面的html源码</param>
        /// <returns></returns>
        public static List<UrlModel> GetLocalSrcs(string url,string html)
        {
            if (string.IsNullOrEmpty(html))
                return new List<UrlModel>();

            Dictionary<string, UrlModel> urls = GetSrc(url, html);
            List<UrlModel> newUrls = new List<UrlModel>();

            if (null != urls)
            {
                foreach (string key in urls.Keys)
                {
                    string newkey = key.ToLower();
                    bool iscontained = false;
                    foreach (var exkey in excludekeys)
                    {
                        if (newkey.IndexOf(exkey) == 0)
                        {
                            iscontained = true;
                            break;
                        }
                    }

                    if (!iscontained)
                    {
                        //只获取本地路径
                        newUrls.Add(urls[key]);
                    }
                }
            }

            return newUrls;
        }

        private static Dictionary<string, UrlModel> GetHrefs(string url,string html)
        {
            if (string.IsNullOrEmpty(html))
                return null;

            UrlModel currUrl = UrlParser.Parse(url);
            Dictionary<string, UrlModel> urls = new Dictionary<string, UrlModel>();
            Regex reg = new Regex("href=\"(?<Url>.+?)\"", RegexOptions.IgnoreCase);

            if (currUrl != null)
            {
                AddUrlModel(html, currUrl, urls, reg);
            }

            return urls;
        }

        private static Dictionary<string, UrlModel> GetSrc(string url,string html)
        {
            if (string.IsNullOrEmpty(html))
                return null;

            UrlModel currUrl = UrlParser.Parse(url);
            Dictionary<string, UrlModel> urls = new Dictionary<string, UrlModel>();
            Regex reg = new Regex("(src=\"(?<Url>.+?)\"|url\\((?<Url>.+?)\\))", RegexOptions.IgnoreCase);

            if (currUrl != null)
            {
                AddUrlModel(html, currUrl, urls, reg);
            }

            return urls;
        }

        private static void AddUrlModel(string html, UrlModel currUrl, Dictionary<string, UrlModel> urls, Regex reg)
        {
            if (reg.IsMatch(html))
            {
                MatchCollection matchs = reg.Matches(html);
                foreach (Match item in matchs)
                {
                    try
                    {
                        string strUrl = item.Groups["Url"].Value;
                        UrlModel model = new UrlModel();
                        model.RelatedPath = strUrl;
                        model.CurrPath = currUrl.CurrPath;
                        model.RootPath = currUrl.RootPath;
                        model.Scheme = currUrl.Scheme;
                        model.Port = currUrl.Port;
                        model.Host = currUrl.Host;

                        if (strUrl.StartsWith("/"))
                        {
                            //绝对目录情况下
                            model.AbsoluteUri = string.Format("{0}{1}", model.RootPath, model.RelatedPath);
                        }
                        else
                        {
                            //相对目录情况下
                            string currPath = model.CurrPath;
                            int depth = 0;
                            string path = model.RelatedPath;

                            if (path.StartsWith(".."))
                            {
                                try
                                {
                                    while (path.StartsWith(".."))
                                    {
                                        depth++;
                                        path = path.Substring(3);
                                        currPath = currPath.Substring(0, currPath.LastIndexOf("/"));
                                    }

                                    model.AbsoluteUri = string.Format("{0}/{1}", currPath, path);
                                }
                                catch
                                {

                                }
                            }
                            else
                            {
                                model.AbsoluteUri = string.Format("{0}/{1}", currPath, path);
                            }

                        }

                        strUrl = strUrl.Trim().ToLower();

                        urls.Add(strUrl, model);
                    }
                    catch
                    {
                    }
                }
            }
        }
    }

 

Model
是最实用的,就算以往大家在用mvc或然ABP等此外框架底层用codefirst等orm框架的时候,我们也得以用那种格局变通Model.

金沙注册送58 14

四.网页源码扒取类

 

    public bool InsertAgreement_YNSHigh_Authorize(Model model)
        {

            string strSql = @"
               INSERT Agreement_YNSHigh_Authorize(
                 AYA_Code,
                 AYHA_Code,
                 Ctg_ID,
                 HospitalCode,
                 HospitalName,
                 HospitalGrad,
                 HospitalRegionID,
                 DevelopmentLimitTime,
                 EffectiveTime,
                 MarketingManagementFee,
                 BidPrice,
                 DeliveryCode,
                 DeliveryName,
                 AgreeAdjuestType,
                 ChangeContent,
                 Status,
                 DeliveryPrice,
                 BasePrice,
                 CategoryCommodityName,
                 CategorySystemName,
                 CategoryCommName,
                 CategorySpec,
                 Formulation,
                 BusinessModel)
                 VALUES (
                    @AYA_Code,
                    @AYHA_Code,
                    @Ctg_ID,
                    @HospitalCode,
                    @HospitalName,
                    @HospitalGrad,
                    @HospitalRegionID,
                    @DevelopmentLimitTime,
                    @EffectiveTime,
                    @MarketingManagementFee,
                    @BidPrice,
                    @DeliveryCode,
                    @DeliveryName,
                    @AgreeAdjuestType,
                    @ChangeContent,
                    @Status,
                    @DeliveryPrice,
                    @BasePrice,
                    @CategoryCommodityName,
                    @CategorySystemName,
                    @CategoryCommName,
                    @CategorySpec,
                    @Formulation,
                   @BusinessModel)

                     ";
            SqlParameter[] parameters = new SqlParameter[]
                                                  {
                      new SqlParameter("@AYA_Code", SqlDbType.NVarChar, 255),
                     new SqlParameter("@AYHA_Code", SqlDbType.NVarChar, 255),
                     new SqlParameter("@Ctg_ID", SqlDbType.NVarChar, 255),
                     new SqlParameter("@HospitalCode", SqlDbType.NVarChar, 255),
                     new SqlParameter("@HospitalName", SqlDbType.NVarChar, 255),
                     new SqlParameter("@HospitalGrad", SqlDbType.NVarChar, 255),
                     new SqlParameter("@HospitalRegionID", SqlDbType.NVarChar, 255),
                     new SqlParameter("@DevelopmentLimitTime", SqlDbType.DateTime),
                     new SqlParameter("@EffectiveTime", SqlDbType.DateTime),
                      new SqlParameter("@MarketingManagementFee", SqlDbType.Decimal),
                      new SqlParameter("@BidPrice", SqlDbType.Decimal),
                     new SqlParameter("@DeliveryCode", SqlDbType.NVarChar, 255),
                     new SqlParameter("@DeliveryName", SqlDbType.NVarChar, 255),
                     new SqlParameter("@AgreeAdjuestType", SqlDbType.NVarChar, 255),
                     new SqlParameter("@ChangeContent", SqlDbType.NVarChar, 255),
                     new SqlParameter("@Status", SqlDbType.NVarChar, 255),
                      new SqlParameter("@DeliveryPrice", SqlDbType.Decimal),
                      new SqlParameter("@BasePrice", SqlDbType.Decimal),
                     new SqlParameter("@CategoryCommodityName", SqlDbType.NVarChar, 255),
                     new SqlParameter("@CategorySystemName", SqlDbType.NVarChar, 255),
                     new SqlParameter("@CategoryCommName", SqlDbType.NVarChar, 255),
                     new SqlParameter("@CategorySpec", SqlDbType.NVarChar, 255),
                     new SqlParameter("@Formulation", SqlDbType.NVarChar, 255),
                     new SqlParameter("@BusinessModel", SqlDbType.NVarChar, 255),
                            };
            parameters[0].Value = model.AYA_Code;
            parameters[1].Value = model.AYHA_Code;
            parameters[2].Value = model.Ctg_ID;
            parameters[3].Value = model.HospitalCode;
            parameters[4].Value = model.HospitalName;
            parameters[5].Value = model.HospitalGrad;
            parameters[6].Value = model.HospitalRegionID;
            parameters[7].Value = model.DevelopmentLimitTime;
            parameters[8].Value = model.EffectiveTime;
            parameters[9].Value = model.MarketingManagementFee;
            parameters[10].Value = model.BidPrice;
            parameters[11].Value = model.DeliveryCode;
            parameters[12].Value = model.DeliveryName;
            parameters[13].Value = model.AgreeAdjuestType;
            parameters[14].Value = model.ChangeContent;
            parameters[15].Value = model.Status;
            parameters[16].Value = model.DeliveryPrice;
            parameters[17].Value = model.BasePrice;
            parameters[18].Value = model.CategoryCommodityName;
            parameters[19].Value = model.CategorySystemName;
            parameters[20].Value = model.CategoryCommName;
            parameters[21].Value = model.CategorySpec;
            parameters[22].Value = model.Formulation;
            parameters[23].Value = model.BusinessModel;

            using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionString))
            {
                conn.Open();
                using (SqlTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
                        int i = SqlHelper.ExecuteNonQuery(trans, CommandType.Text, strSql, parameters);
                        if (i > 0)
                        {
                            trans.Commit();
                            return i > 0;
                        }
                        else
                        {
                            trans.Rollback();
                            return false;
                        }
                    }
                    catch (System.Exception e)
                    {
                        return false;
                        trans.Rollback();
                        throw e;
                    }
                }
            }

        }

如此1个SL项目就确立落成,

public class HttpTool
    {
        public static string HttpGet(string url, string referer, string encoding, out string msg)
        {
            msg = string.Empty;
            string result = string.Empty;
            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

                //request.ContentType = "application/x-www-form-urlencoded";
                request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
                request.Referer = referer;
                request.Method = "GET";
                request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.122 Safari/537.36";
                //request.Headers.Add("Accept-Language", "zh-cn");
                //request.Headers.Add("Accept-Encoding", "gzip,deflate");

                request.Timeout = 60000;//一分钟

                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                Stream responseStream = response.GetResponseStream();
                if (responseStream != null)
                {
                    StreamReader reader = new StreamReader(responseStream, System.Text.Encoding.GetEncoding(encoding));
                    result = reader.ReadToEnd();
                    reader.Close();
                    responseStream.Close();
                    request.Abort();
                    response.Close();
                    return result.Trim();
                }
            }
            catch (Exception ex)
            {
                msg = ex.Message + ex.StackTrace;
            }

            return result;
        }

        public static void DownFile(string uRLAddress, string localPath, string filename)
        {
            WebClient client = new WebClient();
            Stream str = client.OpenRead(uRLAddress);
            StreamReader reader = new StreamReader(str);
            byte[] mbyte = new byte[1000000];
            int allmybyte = (int)mbyte.Length;
            int startmbyte = 0;

            while (allmybyte > 0)
            {
                int m = str.Read(mbyte, startmbyte, allmybyte);
                if (m == 0)
                {
                    break;
                }
                startmbyte += m;
                allmybyte -= m;
            }

            reader.Dispose();
            str.Dispose();

            string path = Path.Combine(localPath, filename);
            FileStream fstr = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write);
            fstr.Write(mbyte, 0, startmbyte);
            fstr.Flush();
            fstr.Close();
        }
    }

二、设计数据库

平时大家在新增多少的时候,就以Agreement_YNSHigh_Authorize为例,一般都以这么超做的,加上业务,参数化传过来的参数,那样写起来也相当辛苦。大家那边了也对INSEENVISIONT
做一下封装。

接下去要求的正是赤手空拳地点存款和储蓄类,为了便利明白自个儿就取名SLCookie.cs

伍.网址克隆主类

 

    #region 生成插入Insert方法

            #region 生成插入sql语句

            StringBuilder strTmp = new StringBuilder();
            try
            {
                for (int i = 0; i < dr.Table.Columns.Count; i++)//生成insert 
                {
                    if (i == 0)
                    {
                        strTmp.AppendLine("               INSERT " + Table + "(");
                    }
                    if (i == dr.Table.Columns.Count - 1)
                    {
                        strTmp.AppendLine("                 " + dr.Table.Columns[i].ToString() + ")");
                    }
                    else
                    {
                        strTmp.AppendLine("                 " + dr.Table.Columns[i].ToString() + ",");
                    }
                }

                for (int i = 0; i < dr.Table.Columns.Count; i++)
                {
                    if (i == 0)
                    {
                        strTmp.AppendLine("                 VALUES " + "(");
                    }
                    if (i == dr.Table.Columns.Count - 1)
                    {
                        strTmp.AppendLine("                   @" + dr.Table.Columns[i].ToString() + ")");
                    }
                    else
                    {
                        strTmp.AppendLine("                    @" + dr.Table.Columns[i].ToString() + ",");
                    }

                }
            }
            catch (System.Exception ex)
            {

                throw ex;
            }

            #endregion





            strBuilder.AppendLine("   public bool Insert" + Table + "(Model model)");
            strBuilder.AppendLine(@"    {   
           ");
            strBuilder.AppendLine("                    string strSql = @\"");
            strBuilder.AppendLine(strTmp.ToString());
            strBuilder.AppendLine("                     \";");

            strBuilder.AppendLine(@"                 SqlParameter[] parameters = new SqlParameter[]
                                                  {");
            //参数类型
            for (int i = 0; i < dr.Table.Columns.Count; i++)
            {
                string Type = dr.Table.Columns[i].DataType.ToString();
                switch (Type)
                {
                    case "System.String":
                        strBuilder.AppendLine("                     new SqlParameter(\"" + "@" + dr.Table.Columns[i] + "\", SqlDbType.NVarChar, 255),");
                        break;
                    case "System.Int":
                        strBuilder.AppendLine("                     new SqlParameter(\"" + "@" + dr.Table.Columns[i] + "\", SqlDbType.Int),");
                        break;
                    case "System.Int32":
                        strBuilder.AppendLine("                     new SqlParameter(\"" + "@" + dr.Table.Columns[i] + "\", SqlDbType.Int),");
                        break;
                    case "System.DateTime":
                        strBuilder.AppendLine("                     new SqlParameter(\"" + "@" + dr.Table.Columns[i] + "\", SqlDbType.DateTime),");
                        break;
                    case "System.Decimal":
                        strBuilder.AppendLine("                      new SqlParameter(\"" + "@" + dr.Table.Columns[i] + "\", SqlDbType.Decimal),");
                        break;
                    default:
                        strBuilder.AppendLine("                      new SqlParameter(\"" + "@" + dr.Table.Columns[i] + "\", SqlDbType.NVarChar, 255),");
                        break;
                }
            }
            strBuilder.AppendLine(@"                            };");

            for (int i = 0; i < dr.Table.Columns.Count; i++)
            {
                strBuilder.AppendLine("                        parameters[" + i + "].Value =" + "model." + dr.Table.Columns[i] + ";");
            }

            strBuilder.AppendLine(@"
            using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionString))
            {
                conn.Open();
                using (SqlTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
                        int i = SqlHelper.ExecuteNonQuery(trans, CommandType.Text, strSql, parameters);
                          if (i > 0)
                        {
                            trans.Commit();
                            return i > 0;
                        }
                        else
                        {
                            trans.Rollback();
                            return false;
                        }
                    }
                    catch (System.Exception e)
                    {
                         return false;
                        trans.Rollback();
                        throw e;
                    }
                  }
               }
               ");
            strBuilder.AppendLine("}");

            #endregion

金沙注册送58 15

接口:

1、打开PowerDesigner ,建表News。

第3是依照sql生成字段和参数字段。那都以很麻烦的做事,而且不能够出错。也是对DataRow
table的循环和包裹处理。须求留意一下转义字符处理,注意对业务的拍卖。其余update,select,delete的处理方式与insert类似,不在累述,放上代码。

金沙注册送58 16

interface IWebCloneWorker
    {
        void Start();
        void Cancel();
    }

 

            if ((bool)inputSql[4])
            {
                returnstr.AppendLine(strBuilder.ToString());
            }
            strBuilder = new StringBuilder();
            #region 生成更新Update 方法

            #region 生成更新Update sql语句

            strTmp = new StringBuilder(); //sql 
            try
            {
                for (int i = 0; i < dr.Table.Columns.Count; i++)//生成Update 
                {
                    if (i == 0)
                    {
                        strTmp.AppendLine("               Update " + Table + "  SET ");
                    }
                    if (i == dr.Table.Columns.Count - 1)
                    {


                        strTmp.AppendLine("                 " + dr.Table.Columns[i].ToString() + "=" + "@" + dr.Table.Columns[i].ToString() + " where " + Id + "=" + "@" + Id + "  ");
                    }
                    else
                    {
                        strTmp.AppendLine("                  " + dr.Table.Columns[i].ToString() + "=" + "@" + dr.Table.Columns[i].ToString() + ",");
                    }
                }
            }
            catch (System.Exception ex)
            {

                throw ex;
            }

            #endregion




            strBuilder.AppendLine("   public bool Update" + Table + "ById(Model model)");
            strBuilder.AppendLine(@"    {   
           ");
            strBuilder.AppendLine("                    string strSql = @\"");
            strBuilder.AppendLine(strTmp.ToString());
            strBuilder.AppendLine("                     \";");

            strBuilder.AppendLine(@"                 SqlParameter[] parameters = new SqlParameter[]
                                                  {");
            //参数类型
            for (int i = 0; i < dr.Table.Columns.Count; i++)
            {
                string Type = dr.Table.Columns[i].DataType.ToString();
                switch (Type)
                {
                    case "System.String":
                        strBuilder.AppendLine("                     new SqlParameter(\"" + "@" + dr.Table.Columns[i] + "\", SqlDbType.NVarChar, 255),");
                        break;
                    case "System.Int":
                        strBuilder.AppendLine("                     new SqlParameter(\"" + "@" + dr.Table.Columns[i] + "\", SqlDbType.Int),");
                        break;
                    case "System.DateTime":
                        strBuilder.AppendLine("                     new SqlParameter(\"" + "@" + dr.Table.Columns[i] + "\", SqlDbType.DateTime),");
                        break;
                    case "System.Decimal":
                        strBuilder.AppendLine("                      new SqlParameter(\"" + "@" + dr.Table.Columns[i] + "\", SqlDbType.Decimal),");
                        break;
                    default:
                        strBuilder.AppendLine("                      new SqlParameter(\"" + "@" + dr.Table.Columns[i] + "\", SqlDbType.NVarChar, 255),");
                        break;
                }
            }
            strBuilder.AppendLine(@"                            };");

            for (int i = 0; i < dr.Table.Columns.Count; i++)
            {
                strBuilder.AppendLine("                        parameters[" + i + "].Value =" + "model." + dr.Table.Columns[i] + ";");
            }

            strBuilder.AppendLine(@"
            using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionString))
            {
                conn.Open();
                using (SqlTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
                        int i = SqlHelper.ExecuteNonQuery(trans, CommandType.Text, strSql, parameters);
                          if (i > 0)
                        {
                            trans.Commit();
                            return i > 0;
                        }
                        else
                        {
                            trans.Rollback();
                            return false;
                        }
                    }
                    catch (System.Exception e)
                    {
                        return false;
                        trans.Rollback();
                        throw e;
                    }
                  }
               }
               ");
            strBuilder.AppendLine("}");

            #endregion

            if ((bool)inputSql[5])
            {
                returnstr.AppendLine(strBuilder.ToString());
            }
            strBuilder = new StringBuilder();
            #region 生成查询方法

            strBuilder.AppendLine("   public DataTable GetDataBy" + Table + "(Model model , int pageNo, int pageSize, ref int iRecordCount)");
            strBuilder.AppendLine(@"    {    ");
            strTmp = new StringBuilder();
            strTmp.AppendLine("WITH temp AS ( SELECT rn =  ROW_NUMBER() OVER (ORDER BY " + Id + "  desc), *FROM  " + Table + " WHERE 1=1 {0} )");
            strTmp.AppendLine("SELECT *,rc=(select count(1) from temp) FROM temp WHERE rn BETWEEN {1} AND {2}");

            strBuilder.AppendLine("        List<SqlParameter> parameters = new List<SqlParameter>();");
            strBuilder.AppendLine("        StringBuilder sqlWhere = new StringBuilder();");
            for (int i = 0; i < dr.Table.Columns.Count; i++)
            {
                strBuilder.AppendLine("       if (!string.IsNullOrEmpty(model." + dr.Table.Columns[i].ToString() + ".ToString())) ");
                strBuilder.AppendLine("       {");
                strBuilder.AppendLine("          sqlWhere.Append(\" AND " + dr.Table.Columns[i].ToString() + "=@" + dr.Table.Columns[i].ToString() + "\");");
                strBuilder.AppendLine("          parameters.Add(new SqlParameter(\"@" + dr.Table.Columns[i].ToString() + "\", SqlDbType.NVarChar, 255) { SqlValue = model." + dr.Table.Columns[i].ToString() + " });");
                strBuilder.AppendLine("       } ");
            }
            strBuilder.AppendLine("                    string strSql = string.Format(@\"");
            strBuilder.AppendLine(strTmp.ToString());
            strBuilder.AppendLine("                     \" ,sqlWhere.ToString(), (pageNo - 1) * pageSize + 1, pageNo * pageSize);");

            strBuilder.AppendLine(@"    

                   DataTable dt = SqlHelper.Query(strSql, parameters.ToArray()).Tables[0];
                  if (dt!=null)
                   {");
            strBuilder.AppendLine("        iRecordCount = int.Parse(dt.Rows[0][\"" + "rc" + "\"].ToString());");
            strBuilder.AppendLine(@"      return dt;
                            }
                           else
                          {
                              iRecordCount = 0;
                            return null;
                        }
                }    ");

            #endregion

            if ((bool)inputSql[6])
            {
                returnstr.AppendLine(strBuilder.ToString());
            }
            strBuilder = new StringBuilder();
            #region 生成删除的方法

            strBuilder.AppendLine("    public bool Delete" + Table + "(string " + Id + ")");
            strBuilder.AppendLine("   {");
            strBuilder.AppendLine("        List<SqlParameter> parameters = new List<SqlParameter>();");
            strTmp = new StringBuilder();
            strTmp.AppendLine("DELETE " + Table + " WHERE " + Id + "=" + Id + "");
            strBuilder.AppendLine("                    string strSql = string.Format(@\"");
            strBuilder.AppendLine(strTmp.ToString());
            strBuilder.AppendLine("                     \";");
            strBuilder.AppendLine("     int rowAffect =SqlHelper.Query(strSql, parameters.ToArray()).ToInt();;");
            strBuilder.AppendLine("      return rowAffect > 0 ? true : false;");
            strBuilder.AppendLine("      }");

            #endregion

            if ((bool)inputSql[7])
            {
                returnstr.AppendLine(strBuilder.ToString());
            }
            strBuilder = new StringBuilder();
  1 using System;
  2 using System.Net;
  3 using System.Windows;
  4 using System.Windows.Controls;
  5 using System.Windows.Documents;
  6 using System.Windows.Ink;
  7 using System.Windows.Input;
  8 using System.Windows.Media;
  9 using System.Windows.Media.Animation;
 10 using System.Windows.Shapes;
 11 using System.IO.IsolatedStorage;
 12 using System.Text;
 13 
 14 namespace SLF5
 15 {
 16     /// <summary>
 17     /// 功能:SilverLight独立存储类
 18     /// 创建人:龚安川
 19     /// 创建时间:2012-08-18
 20     /// </summary>    
 21     public class SLCookie
 22     {
 23         /*当前系统Cookie 保存3个字段
 24         * PageAddress :记录最后一次访问的页面地址  
 25         * UserID: 用户名
 26         * ExitTime:退出时间  
 27         */
 28 
 29         #region 独立存储相关操作函数
 30 
 31         #region 设置Cookie
 32         /// <summary>
 33         /// 设置Cookie
 34         /// </summary>
 35         /// <param name="key">the cookie key</param>
 36         /// <param name="value">the cookie value</param>
 37         public static void SetCookie(string key, string value)
 38         {
 39             IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
 40             //判断该键是否存在
 41             if (settings.Contains(key))
 42             {
 43                 settings.Remove(key);
 44                 settings.Add(key, value);
 45             }
 46             else
 47             {
 48                 settings.Add(key, value);
 49             }
 50             settings.Save();
 51 
 52         }
 53         #endregion
 54 
 55         #region 读取一个已经存在的Cookie
 56         /// <summary>
 57         /// 读取一个已经存在的Cookie
 58         /// </summary>
 59         /// <param name="key">cookie key</param>
 60         /// <returns>null if the cookie does not exist, otherwise the cookie value</returns>
 61         public static string GetCookie(string key)
 62         {
 63             IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
 64             //判断该键是否存在
 65             if (settings.Contains(key))
 66             {
 67                 return settings[key] != null ? settings[key].ToString() : "";
 68             }
 69             else
 70             {
 71                 return string.Empty;
 72             }
 73         }
 74         #endregion
 75 
 76         #region   删除特定的Cookie(清空它的Value值)
 77         /// <summary>
 78         /// 删除特定的Cookie(清空它的Value值)
 79         /// </summary>
 80         /// <param name="key">the cookie key to delete</param>
 81 
 82         public static void DeleteCookie(string key)
 83         {
 84             IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
 85             //判断该键是否存在
 86             if (settings.Contains(key))
 87             {
 88                 settings.Remove(key);
 89             }
 90         }
 91         #endregion
 92 
 93         #region 判定指定的key-value对是否在cookie中存在
 94         public static bool Exists(String key, String value)
 95         {
 96             IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
 97             //判断该键是否存在
 98             if (settings.Contains(key))
 99             {
100                 return true;
101             }
102             else
103             {
104                 return false;
105             }
106         }
107         #endregion
108 
109         #region  获取当前cookie内容
110         public static string getCookieContent()
111         {
112             StringBuilder values = new StringBuilder();
113             IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
114             if (settings != null && settings.Count > 0)
115             {
116                 foreach (string item in settings.Keys)
117                 {
118                     values.Append(settings[item] != null ? settings[item].ToString() : "");
119                 }
120                 return values.ToString();
121             }
122             else
123             {
124                 return string.Empty;
125             }
126         }
127         #endregion
128 
129         #region 清空本地cookie
130         public static void ClearCookies()
131         {
132             IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
133             settings.Clear();
134         }
135         #endregion 清空本地cookie
136 
137         #endregion
138     }
139 }

 

金沙注册送58 17

if
((bool)inputSql[7])首借使对控件值得判断,是还是不是勾选上,也等于是还是不是需求生成改方法。导出的办法首要在店铺1度封装好的代码上领取重复代码的,平常大家在做功用的时候只要求写那个代码即可。

金沙注册送58 18

 

 

      #region 导出excel方法

            strBuilder.AppendLine(@"     protected void btnExcel_Click(object sender, System.EventArgs e)
        {
            int intPageNo = 1;
            int intPageSize = 65535;
            int recordCount = 0;
            DataTable dt = GetUnAuthorizeAgreePassedDT( Model model intPageNo, intPageSize, out recordCount); ");
            strBuilder.AppendLine("     string strFileName = \"" + "导出Excel" + "\" + System.DateTime.Now.ToString(\" " + "yyyyMMddHHmmss" + "\");");
            strBuilder.AppendLine(@"        ExcelUtility excelUtil = new ExcelUtility(this, strFileName);
            List<ExcelHeader> headerS = new List<ExcelHeader>() { ");

            for (int i = 0; i < dr.Table.Columns.Count; i++)
            {
                string Type = dr.Table.Columns[i].DataType.ToString();
                switch (Type)
                {
                    case "System.DateTime":
                        strBuilder.AppendLine("           new ExcelHeader() { Name = \"字段名称自行补全\", DataType = EnumColumnDataType.日期, Width = 15 },");
                        break;
                    default:
                        strBuilder.AppendLine("           new ExcelHeader() { Name = \"字段名称自行补全\", DataType = EnumColumnDataType.文本, Width = 15 },");
                        break;
                }
            }
            strBuilder.AppendLine(@"          };
            excelUtil.CreateHeader(headerS);
            if (dt != null && dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    List<string> dataVals = new List<string>() { ");


            for (int i = 0; i < dr.Table.Columns.Count; i++)
            {
                strBuilder.AppendLine("                            dr[\" " + dr.Table.Columns[i] + "\"].ToString()  ");
            }

            strBuilder.AppendLine(@"          };       
                    excelUtil.CreateItemRow(dataVals);
                }
            }
            excelUtil.Export();
            }
           "); 
            #endregion

再为这么些基类,写个协助类,方便操作调用 SLCookieHelp.cs

实现类:

 

金沙注册送58 19

金沙注册送58 20View Code

public class WebCloneWorker : IWebCloneWorker
    {
        //网站页面克隆深度(如:0-首页,1-分类页,2-详细页面)
        public static int depth = 0;

        //要克隆的网站网址
        public string Url { get; set; }

        //克隆后,保存的路径
        public string SavePath { get; set; }

        private BackgroundWorker backgroundWorker1 = null;
        public event UrlChangedEventHandler UrlChanged;
        public event FileSavedSuccessEventHandler FileSavedSuccess;
        public event FileSavedFailEventHandler FileSavedFail;
        public event DownloadCompletedEventHandler DownloadCompleted;
        public event CollectingUrlEventHandler CollectingUrl;
        public event CollectedUrlEventHandler CollectedUrl;
        public event ProgressChangedEventHandler ProgressChanged;

        //所有页面、文件资源地址集合
        private Dictionary<string, UrlModel> _Hrefs = new Dictionary<string, UrlModel>();

        /// <summary>
        /// 所有页面、文件资源地址集合
        /// </summary>
        public Dictionary<string,UrlModel> Hrefs
        {
            get { return _Hrefs; }
            set { _Hrefs = value; }
        }

        //网站页面请求编码,默认为UTF-8
        private string _Encoding = "utf-8";

        //网站页面请求编码,默认为UTF-8
        public string Encoding
        {
            get { return _Encoding; }
            set { _Encoding = value; }
        }

        public WebCloneWorker() { }

        public WebCloneWorker(string url,string path) 
        {
            //设置网站、保存路径
            this.Url = url;
            this.SavePath = path;

            if (string.IsNullOrEmpty(this.Url))
                throw new Exception("请输入网址");

            if (string.IsNullOrEmpty(this.SavePath))
                throw new Exception("请选择要保存的目录");

            backgroundWorker1 = new BackgroundWorker();

            //设置报告进度更新
            backgroundWorker1.WorkerReportsProgress = true;
            backgroundWorker1.WorkerSupportsCancellation = true;

            //注册线程主体方法
            backgroundWorker1.DoWork += backgroundWorker1_DoWork;

            //注册更新UI方法
            backgroundWorker1.ProgressChanged += backgroundWorker1_ProgressChanged;

            //处理完毕
            backgroundWorker1.RunWorkerCompleted += backgroundWorker1_RunWorkerCompleted;
        }

        void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (e.Cancelled) {
                return;
            }

            if (this.DownloadCompleted != null)
            {
                DownloadCompletedEventArgs eventArgs = new DownloadCompletedEventArgs(e.Result, e.Error, e.Cancelled);
                this.DownloadCompleted(this, eventArgs);
            }
        }

        void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            //进度回调
            if (this.ProgressChanged != null) 
                this.ProgressChanged(this, e);

            UrlModel model = (UrlModel)e.UserState;

            if (this.UrlChanged != null)
            {
                //Url改变后,回调
                UrlChangedEventArgs eventArgs = new UrlChangedEventArgs(model);
                this.UrlChanged(this, eventArgs);
            }

            try
            {
                string dir = this.SavePath;
                string url = model.AbsoluteUri;
                string AbsolutePath = url.Substring(url.IndexOf('/', 8));
                string fileName = "";

                if (url.IndexOf('?') > 0)
                {
                    string path = AbsolutePath.Substring(0, model.RelatedPath.IndexOf('?'));
                    fileName = System.IO.Path.GetFileName(path);
                }
                else
                {
                    fileName = System.IO.Path.GetFileName(AbsolutePath);
                }

                //默认首页
                if (string.IsNullOrEmpty(fileName) || fileName.IndexOf(".") < 0)
                {
                    fileName = "index.html";

                    if (!AbsolutePath.EndsWith("/"))
                        AbsolutePath = AbsolutePath + "/";
                }

                fileName = System.Web.HttpUtility.UrlDecode(fileName);

                string localPath = string.Format("{0}{1}", dir, System.IO.Path.GetDirectoryName(AbsolutePath));
                if (!System.IO.Directory.Exists(localPath))
                {
                    System.IO.Directory.CreateDirectory(localPath);
                }

                //判断文件是否存在,存在不再下载
                string path2 = Path.Combine(localPath, fileName);
                if (File.Exists(path2))
                {
                    return;
                }

                //下载网页、图片、资源文件
                HttpTool.DownFile(url, localPath, fileName);

                //保存成功后,回调
                if (this.FileSavedSuccess != null)
                {
                    FileSavedSuccessEventArgs eventArgs = new FileSavedSuccessEventArgs(model);
                    this.FileSavedSuccess(this, eventArgs);
                }
            }
            catch (Exception ex)
            {
                //保存失败后,回调
                if (this.FileSavedFail != null)
                {
                    FileSavedFailEventArgs eventArgs = new FileSavedFailEventArgs(ex);
                    this.FileSavedFail(this, eventArgs);
                }
            }
        }

        void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            //获取资源
            GetResource();

            int index = 1;
            if (this.Hrefs.Keys.Count > 0)
            {
                foreach (var k in this.Hrefs.Keys)
                {
                    //取消操作
                    if (backgroundWorker1.CancellationPending)
                    {
                        e.Cancel = true;
                        return;
                    }

                    backgroundWorker1.ReportProgress(index, this.Hrefs[k]);
                    index++;

                    //挂起当前线程200毫秒
                    Thread.Sleep(200);
                }
            }
        }

        public void Start()
        {
            if (this.backgroundWorker1.IsBusy)
                return;

            this.backgroundWorker1.RunWorkerAsync();
        }

        public void Cancel()
        {
            if (this.backgroundWorker1.CancellationPending)
                return;

            this.backgroundWorker1.CancelAsync();
        }

        private void GetResource()
        {
            string url = this.Url;
            string referer = this.Url;
            string msg = "";
            string html = HttpTool.HttpGet(url, referer, this.Encoding, out msg);

            //收集页面链接
            GetHrefs(0, url, html);

            //收集完毕
            if (null != CollectedUrl)
            {
                UrlModel urlModel = new UrlModel();
                CollectedUrlEventArgs eventArgs = new CollectedUrlEventArgs(urlModel);
                this.CollectedUrl(this, eventArgs);
            }

        }

        private void GetHrefs(int level,string url,string html)
        {
            #region 添加当前页

            UrlModel currUrl = UrlParser.Parse(url);

            try
            {
                //取消
                if (backgroundWorker1.CancellationPending)
                    return;

                this.Hrefs.Add(currUrl.RelatedPath, currUrl);

                //收集回调
                if (null != CollectingUrl)
                {
                    CollectingUrlEventArgs eventArgs = new CollectingUrlEventArgs(currUrl);
                    this.CollectingUrl(this, eventArgs);
                }
            }
            catch
            {
            }

            #endregion

            //获取相关链接(含有href属性的)
            List<UrlModel> list1 = WebPageService.GetLocalHrefs(url,html);

            //获取图片,文件等资源文件(含有src属性的)
            List<UrlModel> listSrcs = WebPageService.GetLocalSrcs(url,html);

            #region 获取当级资源文件

            if (listSrcs != null)
            {
                for (int i = 0; i < listSrcs.Count; i++)
                {
                    UrlModel urlModel = listSrcs[i];
                    try
                    {
                        //取消
                        if (backgroundWorker1.CancellationPending) 
                            return;

                        this.Hrefs.Add(urlModel.RelatedPath, urlModel);

                        //收集回调
                        if (null != CollectingUrl)
                        {
                            CollectingUrlEventArgs eventArgs = new CollectingUrlEventArgs(urlModel);
                            this.CollectingUrl(this, eventArgs);
                        }
                    }
                    catch
                    { }
                }
            }

            #endregion

            #region 获取子级页面资源

            //获取第二级
            if (list1 != null)
            {
                for (int i = 0; i < list1.Count; i++)
                {
                    UrlModel urlModel = list1[i];

                    try
                    {
                        //取消
                        if (backgroundWorker1.CancellationPending)
                            return;

                        this.Hrefs.Add(urlModel.RelatedPath, urlModel);

                        //收集回调
                        if (null != CollectingUrl)
                        {
                            CollectingUrlEventArgs eventArgs = new CollectingUrlEventArgs(urlModel);
                            this.CollectingUrl(this, eventArgs);
                        }
                    }
                    catch
                    { }

                    string msg = "";
                    html = HttpTool.HttpGet(urlModel.AbsoluteUri, urlModel.AbsoluteUri, this.Encoding, out msg);

                    #region 获取子级资源文件

                    /*
                     * 获取二级资源文件
                     * */
                    listSrcs = WebPageService.GetLocalSrcs(urlModel.AbsoluteUri, html);//资源文件

                    if (listSrcs != null)
                    {
                        for (int j = 0; j < listSrcs.Count; j++)
                        {
                            UrlModel urlModel2 = listSrcs[j];

                            try
                            {
                                //取消
                                if (backgroundWorker1.CancellationPending)
                                    return;

                                this.Hrefs.Add(urlModel2.RelatedPath, urlModel2);

                                //收集回调
                                if (null != CollectingUrl)
                                {
                                    CollectingUrlEventArgs eventArgs = new CollectingUrlEventArgs(urlModel2);
                                    this.CollectingUrl(this, eventArgs);
                                }
                            }
                            catch
                            { }

                            //挂起线程20毫秒
                            Thread.Sleep(20);
                        }
                    }
                    #endregion

                    //挂起线程20毫秒
                    Thread.Sleep(20);

                    //到达指定深度后,退出
                    if (level >= depth)
                        return;

                    //递归
                    GetHrefs(level + 1, urlModel.AbsoluteUri, html);
                }
            }

            #endregion
        }
    }

贰、打开SQL Server
二零零六,新建数据库News,新建表:News(从PowerDesigner中取建表语句)。

3.png

接下去再应用程式.XAML.CS的启航事件扩充判断,分明进入哪个界面,在剥离事件之中期维修改本地存款和储蓄登陆时间的翻新。

 

 

金沙注册送58 21

一般景色下,在运行事件之中遵照地面存款和储蓄的数量判断运行差别的用户控件即可,不过自身这么些类型刚好用到了,基框架界面加载的主意,就顺手在这边也跟大家一道享受了。

陆.片段事变、委托类:

金沙注册送58 22

4.png

现行反革命的代码如下:

public delegate void UrlChangedEventHandler(object sender, UrlChangedEventArgs e);
    public delegate void FileSavedSuccessEventHandler(object sender, FileSavedSuccessEventArgs e);
    public delegate void FileSavedFailEventHandler(object sender, FileSavedFailEventArgs e);
    public delegate void DownloadCompletedEventHandler(object sender, DownloadCompletedEventArgs e);
    public delegate void CollectingUrlEventHandler(object sender, CollectingUrlEventArgs e);
    public delegate void CollectedUrlEventHandler(object sender, CollectedUrlEventArgs e);
    public delegate void ProgressChangedEventHandler(object sender, ProgressChangedEventArgs e);

 

金沙注册送58 23

金沙注册送58 24View Code

 

 

5.png

基框架界面加载用到了以下多少个类:

public class CollectedUrlEventArgs : EventArgs
public class CollectingUrlEventArgs : EventArgs
public class DownloadCompletedEventArgs : EventArgs
public class FileSavedFailEventArgs : EventArgs
public class FileSavedSuccessEventArgs : EventArgs
public class UrlChangedEventArgs : EventArgs

3、自动生成数据库代码

别的做了多少个职能,不过不是很好用,感兴趣的爱侣能够去下载源码看一下。
github地址:https://github.com/Jimmey-Jiang/JWorkHelper

用户控件:Host.xaml 

 

 

然后看一下转变的代码展现:

XAML代码新建后不动即可,cs代码如下:

代码有点多,各位有供给的可能下载源码查看并运维吧,由于赶时间,没时间精心测试程序的逐一职能,难免有不足的地点。

1、新建App_Code,加个多个文件夹(DataBase、DBEntity、DBInterface),参与已有个别多少个文本(CDbBaseSqlServer.cs、CDbHelper、IDbBase.cs)至DataBase。

        public class Model
        {

            private Int _AYA_Code;
            public Int AYA_Code
            {
                get { return _AYA_Code; }
                set { _AYA_Code = value; }
            }
            private string _AYHA_Code;
            public string AYHA_Code
            {
                get { return _AYHA_Code; }
                set { _AYHA_Code = value; }
            }
            private string _Ctg_ID;
            public string Ctg_ID
            {
                get { return _Ctg_ID; }
                set { _Ctg_ID = value; }
            }
            private string _HospitalCode;
            public string HospitalCode
            {
                get { return _HospitalCode; }
                set { _HospitalCode = value; }
            }
            private string _HospitalName;
            public string HospitalName
            {
                get { return _HospitalName; }
                set { _HospitalName = value; }
            }
            private string _HospitalGrad;
            public string HospitalGrad
            {
                get { return _HospitalGrad; }
                set { _HospitalGrad = value; }
            }
            private string _HospitalRegionID;
            public string HospitalRegionID
            {
                get { return _HospitalRegionID; }
                set { _HospitalRegionID = value; }
            }
            private System.DateTime _DevelopmentLimitTime;
            public System.DateTime DevelopmentLimitTime
            {
                get { return _DevelopmentLimitTime; }
                set { _DevelopmentLimitTime = value; }
            }
            private System.DateTime _EffectiveTime;
            public System.DateTime EffectiveTime
            {
                get { return _EffectiveTime; }
                set { _EffectiveTime = value; }
            }
            private System.Decimal _MarketingManagementFee;
            public System.Decimal MarketingManagementFee
            {
                get { return _MarketingManagementFee; }
                set { _MarketingManagementFee = value; }
            }
            private System.Decimal _BidPrice;
            public System.Decimal BidPrice
            {
                get { return _BidPrice; }
                set { _BidPrice = value; }
            }
            private string _DeliveryCode;
            public string DeliveryCode
            {
                get { return _DeliveryCode; }
                set { _DeliveryCode = value; }
            }
            private string _DeliveryName;
            public string DeliveryName
            {
                get { return _DeliveryName; }
                set { _DeliveryName = value; }
            }
            private string _AgreeAdjuestType;
            public string AgreeAdjuestType
            {
                get { return _AgreeAdjuestType; }
                set { _AgreeAdjuestType = value; }
            }
            private string _ChangeContent;
            public string ChangeContent
            {
                get { return _ChangeContent; }
                set { _ChangeContent = value; }
            }
            private string _Status;
            public string Status
            {
                get { return _Status; }
                set { _Status = value; }
            }
            private System.Decimal _DeliveryPrice;
            public System.Decimal DeliveryPrice
            {
                get { return _DeliveryPrice; }
                set { _DeliveryPrice = value; }
            }
            private System.Decimal _BasePrice;
            public System.Decimal BasePrice
            {
                get { return _BasePrice; }
                set { _BasePrice = value; }
            }
            private string _CategoryCommodityName;
            public string CategoryCommodityName
            {
                get { return _CategoryCommodityName; }
                set { _CategoryCommodityName = value; }
            }
            private string _CategorySystemName;
            public string CategorySystemName
            {
                get { return _CategorySystemName; }
                set { _CategorySystemName = value; }
            }
            private string _CategoryCommName;
            public string CategoryCommName
            {
                get { return _CategoryCommName; }
                set { _CategoryCommName = value; }
            }
            private string _CategorySpec;
            public string CategorySpec
            {
                get { return _CategorySpec; }
                set { _CategorySpec = value; }
            }
            private string _Formulation;
            public string Formulation
            {
                get { return _Formulation; }
                set { _Formulation = value; }
            }
            private string _BusinessModel;
            public string BusinessModel
            {
                get { return _BusinessModel; }
                set { _BusinessModel = value; }
            }

        }


        public bool InsertAgreement_YNSHigh_Authorize(Model model)
        {

            string strSql = @"
               INSERT Agreement_YNSHigh_Authorize(
                 AYA_Code,
                 AYHA_Code,
                 Ctg_ID,
                 HospitalCode,
                 HospitalName,
                 HospitalGrad,
                 HospitalRegionID,
                 DevelopmentLimitTime,
                 EffectiveTime,
                 MarketingManagementFee,
                 BidPrice,
                 DeliveryCode,
                 DeliveryName,
                 AgreeAdjuestType,
                 ChangeContent,
                 Status,
                 DeliveryPrice,
                 BasePrice,
                 CategoryCommodityName,
                 CategorySystemName,
                 CategoryCommName,
                 CategorySpec,
                 Formulation,
                 BusinessModel)
                 VALUES (
                    @AYA_Code,
                    @AYHA_Code,
                    @Ctg_ID,
                    @HospitalCode,
                    @HospitalName,
                    @HospitalGrad,
                    @HospitalRegionID,
                    @DevelopmentLimitTime,
                    @EffectiveTime,
                    @MarketingManagementFee,
                    @BidPrice,
                    @DeliveryCode,
                    @DeliveryName,
                    @AgreeAdjuestType,
                    @ChangeContent,
                    @Status,
                    @DeliveryPrice,
                    @BasePrice,
                    @CategoryCommodityName,
                    @CategorySystemName,
                    @CategoryCommName,
                    @CategorySpec,
                    @Formulation,
                   @BusinessModel)

                     ";
            SqlParameter[] parameters = new SqlParameter[]
                                                  {
                     new SqlParameter("@AYA_Code", SqlDbType.Int),
                     new SqlParameter("@AYHA_Code", SqlDbType.NVarChar, 255),
                     new SqlParameter("@Ctg_ID", SqlDbType.NVarChar, 255),
                     new SqlParameter("@HospitalCode", SqlDbType.NVarChar, 255),
                     new SqlParameter("@HospitalName", SqlDbType.NVarChar, 255),
                     new SqlParameter("@HospitalGrad", SqlDbType.NVarChar, 255),
                     new SqlParameter("@HospitalRegionID", SqlDbType.NVarChar, 255),
                     new SqlParameter("@DevelopmentLimitTime", SqlDbType.DateTime),
                     new SqlParameter("@EffectiveTime", SqlDbType.DateTime),
                      new SqlParameter("@MarketingManagementFee", SqlDbType.Decimal),
                      new SqlParameter("@BidPrice", SqlDbType.Decimal),
                     new SqlParameter("@DeliveryCode", SqlDbType.NVarChar, 255),
                     new SqlParameter("@DeliveryName", SqlDbType.NVarChar, 255),
                     new SqlParameter("@AgreeAdjuestType", SqlDbType.NVarChar, 255),
                     new SqlParameter("@ChangeContent", SqlDbType.NVarChar, 255),
                     new SqlParameter("@Status", SqlDbType.NVarChar, 255),
                      new SqlParameter("@DeliveryPrice", SqlDbType.Decimal),
                      new SqlParameter("@BasePrice", SqlDbType.Decimal),
                     new SqlParameter("@CategoryCommodityName", SqlDbType.NVarChar, 255),
                     new SqlParameter("@CategorySystemName", SqlDbType.NVarChar, 255),
                     new SqlParameter("@CategoryCommName", SqlDbType.NVarChar, 255),
                     new SqlParameter("@CategorySpec", SqlDbType.NVarChar, 255),
                     new SqlParameter("@Formulation", SqlDbType.NVarChar, 255),
                     new SqlParameter("@BusinessModel", SqlDbType.NVarChar, 255),
                            };
            parameters[0].Value = model.AYA_Code;
            parameters[1].Value = model.AYHA_Code;
            parameters[2].Value = model.Ctg_ID;
            parameters[3].Value = model.HospitalCode;
            parameters[4].Value = model.HospitalName;
            parameters[5].Value = model.HospitalGrad;
            parameters[6].Value = model.HospitalRegionID;
            parameters[7].Value = model.DevelopmentLimitTime;
            parameters[8].Value = model.EffectiveTime;
            parameters[9].Value = model.MarketingManagementFee;
            parameters[10].Value = model.BidPrice;
            parameters[11].Value = model.DeliveryCode;
            parameters[12].Value = model.DeliveryName;
            parameters[13].Value = model.AgreeAdjuestType;
            parameters[14].Value = model.ChangeContent;
            parameters[15].Value = model.Status;
            parameters[16].Value = model.DeliveryPrice;
            parameters[17].Value = model.BasePrice;
            parameters[18].Value = model.CategoryCommodityName;
            parameters[19].Value = model.CategorySystemName;
            parameters[20].Value = model.CategoryCommName;
            parameters[21].Value = model.CategorySpec;
            parameters[22].Value = model.Formulation;
            parameters[23].Value = model.BusinessModel;

            using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionString))
            {
                conn.Open();
                using (SqlTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
                        int i = SqlHelper.ExecuteNonQuery(trans, CommandType.Text, strSql, parameters);
                        if (i > 0)
                        {
                            trans.Commit();
                            return i > 0;
                        }
                        else
                        {
                            trans.Rollback();
                            return false;
                        }
                    }
                    catch (System.Exception e)
                    {
                        return false;
                        trans.Rollback();
                        throw e;
                    }
                }
            }

        }

        public bool UpdateAgreement_YNSHigh_AuthorizeById(Model model)
        {

            string strSql = @"
               Update Agreement_YNSHigh_Authorize  SET 
                  AYA_Code=@AYA_Code,
                  AYHA_Code=@AYHA_Code,
                  Ctg_ID=@Ctg_ID,
                  HospitalCode=@HospitalCode,
                  HospitalName=@HospitalName,
                  HospitalGrad=@HospitalGrad,
                  HospitalRegionID=@HospitalRegionID,
                  DevelopmentLimitTime=@DevelopmentLimitTime,
                  EffectiveTime=@EffectiveTime,
                  MarketingManagementFee=@MarketingManagementFee,
                  BidPrice=@BidPrice,
                  DeliveryCode=@DeliveryCode,
                  DeliveryName=@DeliveryName,
                  AgreeAdjuestType=@AgreeAdjuestType,
                  ChangeContent=@ChangeContent,
                  Status=@Status,
                  DeliveryPrice=@DeliveryPrice,
                  BasePrice=@BasePrice,
                  CategoryCommodityName=@CategoryCommodityName,
                  CategorySystemName=@CategorySystemName,
                  CategoryCommName=@CategoryCommName,
                  CategorySpec=@CategorySpec,
                  Formulation=@Formulation,
                 BusinessModel=@BusinessModel where AYA_Code=@AYA_Code  

                     ";
            SqlParameter[] parameters = new SqlParameter[]
                                                  {
                      new SqlParameter("@AYA_Code", SqlDbType.NVarChar, 255),
                     new SqlParameter("@AYHA_Code", SqlDbType.NVarChar, 255),
                     new SqlParameter("@Ctg_ID", SqlDbType.NVarChar, 255),
                     new SqlParameter("@HospitalCode", SqlDbType.NVarChar, 255),
                     new SqlParameter("@HospitalName", SqlDbType.NVarChar, 255),
                     new SqlParameter("@HospitalGrad", SqlDbType.NVarChar, 255),
                     new SqlParameter("@HospitalRegionID", SqlDbType.NVarChar, 255),
                     new SqlParameter("@DevelopmentLimitTime", SqlDbType.DateTime),
                     new SqlParameter("@EffectiveTime", SqlDbType.DateTime),
                      new SqlParameter("@MarketingManagementFee", SqlDbType.Decimal),
                      new SqlParameter("@BidPrice", SqlDbType.Decimal),
                     new SqlParameter("@DeliveryCode", SqlDbType.NVarChar, 255),
                     new SqlParameter("@DeliveryName", SqlDbType.NVarChar, 255),
                     new SqlParameter("@AgreeAdjuestType", SqlDbType.NVarChar, 255),
                     new SqlParameter("@ChangeContent", SqlDbType.NVarChar, 255),
                     new SqlParameter("@Status", SqlDbType.NVarChar, 255),
                      new SqlParameter("@DeliveryPrice", SqlDbType.Decimal),
                      new SqlParameter("@BasePrice", SqlDbType.Decimal),
                     new SqlParameter("@CategoryCommodityName", SqlDbType.NVarChar, 255),
                     new SqlParameter("@CategorySystemName", SqlDbType.NVarChar, 255),
                     new SqlParameter("@CategoryCommName", SqlDbType.NVarChar, 255),
                     new SqlParameter("@CategorySpec", SqlDbType.NVarChar, 255),
                     new SqlParameter("@Formulation", SqlDbType.NVarChar, 255),
                     new SqlParameter("@BusinessModel", SqlDbType.NVarChar, 255),
                            };
            parameters[0].Value = model.AYA_Code;
            parameters[1].Value = model.AYHA_Code;
            parameters[2].Value = model.Ctg_ID;
            parameters[3].Value = model.HospitalCode;
            parameters[4].Value = model.HospitalName;
            parameters[5].Value = model.HospitalGrad;
            parameters[6].Value = model.HospitalRegionID;
            parameters[7].Value = model.DevelopmentLimitTime;
            parameters[8].Value = model.EffectiveTime;
            parameters[9].Value = model.MarketingManagementFee;
            parameters[10].Value = model.BidPrice;
            parameters[11].Value = model.DeliveryCode;
            parameters[12].Value = model.DeliveryName;
            parameters[13].Value = model.AgreeAdjuestType;
            parameters[14].Value = model.ChangeContent;
            parameters[15].Value = model.Status;
            parameters[16].Value = model.DeliveryPrice;
            parameters[17].Value = model.BasePrice;
            parameters[18].Value = model.CategoryCommodityName;
            parameters[19].Value = model.CategorySystemName;
            parameters[20].Value = model.CategoryCommName;
            parameters[21].Value = model.CategorySpec;
            parameters[22].Value = model.Formulation;
            parameters[23].Value = model.BusinessModel;

            using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionString))
            {
                conn.Open();
                using (SqlTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
                        int i = SqlHelper.ExecuteNonQuery(trans, CommandType.Text, strSql, parameters);
                        if (i > 0)
                        {
                            trans.Commit();
                            return i > 0;
                        }
                        else
                        {
                            trans.Rollback();
                            return false;
                        }
                    }
                    catch (System.Exception e)
                    {
                        return false;
                        trans.Rollback();
                        throw e;
                    }
                }
            }

        }

        public DataTable GetDataByAgreement_YNSHigh_Authorize(Model model, int pageNo, int pageSize, ref int iRecordCount)
        {
            List<SqlParameter> parameters = new List<SqlParameter>();
            StringBuilder sqlWhere = new StringBuilder();
            if (!string.IsNullOrEmpty(model.AYA_Code.ToString()))
            {
                sqlWhere.Append(" AND AYA_Code=@AYA_Code");
                parameters.Add(new SqlParameter("@AYA_Code", SqlDbType.NVarChar, 255) { SqlValue = model.AYA_Code });
            }
            if (!string.IsNullOrEmpty(model.AYHA_Code.ToString()))
            {
                sqlWhere.Append(" AND AYHA_Code=@AYHA_Code");
                parameters.Add(new SqlParameter("@AYHA_Code", SqlDbType.NVarChar, 255) { SqlValue = model.AYHA_Code });
            }
            if (!string.IsNullOrEmpty(model.Ctg_ID.ToString()))
            {
                sqlWhere.Append(" AND Ctg_ID=@Ctg_ID");
                parameters.Add(new SqlParameter("@Ctg_ID", SqlDbType.NVarChar, 255) { SqlValue = model.Ctg_ID });
            }
            if (!string.IsNullOrEmpty(model.HospitalCode.ToString()))
            {
                sqlWhere.Append(" AND HospitalCode=@HospitalCode");
                parameters.Add(new SqlParameter("@HospitalCode", SqlDbType.NVarChar, 255) { SqlValue = model.HospitalCode });
            }
            if (!string.IsNullOrEmpty(model.HospitalName.ToString()))
            {
                sqlWhere.Append(" AND HospitalName=@HospitalName");
                parameters.Add(new SqlParameter("@HospitalName", SqlDbType.NVarChar, 255) { SqlValue = model.HospitalName });
            }
            if (!string.IsNullOrEmpty(model.HospitalGrad.ToString()))
            {
                sqlWhere.Append(" AND HospitalGrad=@HospitalGrad");
                parameters.Add(new SqlParameter("@HospitalGrad", SqlDbType.NVarChar, 255) { SqlValue = model.HospitalGrad });
            }
            if (!string.IsNullOrEmpty(model.HospitalRegionID.ToString()))
            {
                sqlWhere.Append(" AND HospitalRegionID=@HospitalRegionID");
                parameters.Add(new SqlParameter("@HospitalRegionID", SqlDbType.NVarChar, 255) { SqlValue = model.HospitalRegionID });
            }
            if (!string.IsNullOrEmpty(model.DevelopmentLimitTime.ToString()))
            {
                sqlWhere.Append(" AND DevelopmentLimitTime=@DevelopmentLimitTime");
                parameters.Add(new SqlParameter("@DevelopmentLimitTime", SqlDbType.NVarChar, 255) { SqlValue = model.DevelopmentLimitTime });
            }
            if (!string.IsNullOrEmpty(model.EffectiveTime.ToString()))
            {
                sqlWhere.Append(" AND EffectiveTime=@EffectiveTime");
                parameters.Add(new SqlParameter("@EffectiveTime", SqlDbType.NVarChar, 255) { SqlValue = model.EffectiveTime });
            }
            if (!string.IsNullOrEmpty(model.MarketingManagementFee.ToString()))
            {
                sqlWhere.Append(" AND MarketingManagementFee=@MarketingManagementFee");
                parameters.Add(new SqlParameter("@MarketingManagementFee", SqlDbType.NVarChar, 255) { SqlValue = model.MarketingManagementFee });
            }
            if (!string.IsNullOrEmpty(model.BidPrice.ToString()))
            {
                sqlWhere.Append(" AND BidPrice=@BidPrice");
                parameters.Add(new SqlParameter("@BidPrice", SqlDbType.NVarChar, 255) { SqlValue = model.BidPrice });
            }
            if (!string.IsNullOrEmpty(model.DeliveryCode.ToString()))
            {
                sqlWhere.Append(" AND DeliveryCode=@DeliveryCode");
                parameters.Add(new SqlParameter("@DeliveryCode", SqlDbType.NVarChar, 255) { SqlValue = model.DeliveryCode });
            }
            if (!string.IsNullOrEmpty(model.DeliveryName.ToString()))
            {
                sqlWhere.Append(" AND DeliveryName=@DeliveryName");
                parameters.Add(new SqlParameter("@DeliveryName", SqlDbType.NVarChar, 255) { SqlValue = model.DeliveryName });
            }
            if (!string.IsNullOrEmpty(model.AgreeAdjuestType.ToString()))
            {
                sqlWhere.Append(" AND AgreeAdjuestType=@AgreeAdjuestType");
                parameters.Add(new SqlParameter("@AgreeAdjuestType", SqlDbType.NVarChar, 255) { SqlValue = model.AgreeAdjuestType });
            }
            if (!string.IsNullOrEmpty(model.ChangeContent.ToString()))
            {
                sqlWhere.Append(" AND ChangeContent=@ChangeContent");
                parameters.Add(new SqlParameter("@ChangeContent", SqlDbType.NVarChar, 255) { SqlValue = model.ChangeContent });
            }
            if (!string.IsNullOrEmpty(model.Status.ToString()))
            {
                sqlWhere.Append(" AND Status=@Status");
                parameters.Add(new SqlParameter("@Status", SqlDbType.NVarChar, 255) { SqlValue = model.Status });
            }
            if (!string.IsNullOrEmpty(model.DeliveryPrice.ToString()))
            {
                sqlWhere.Append(" AND DeliveryPrice=@DeliveryPrice");
                parameters.Add(new SqlParameter("@DeliveryPrice", SqlDbType.NVarChar, 255) { SqlValue = model.DeliveryPrice });
            }
            if (!string.IsNullOrEmpty(model.BasePrice.ToString()))
            {
                sqlWhere.Append(" AND BasePrice=@BasePrice");
                parameters.Add(new SqlParameter("@BasePrice", SqlDbType.NVarChar, 255) { SqlValue = model.BasePrice });
            }
            if (!string.IsNullOrEmpty(model.CategoryCommodityName.ToString()))
            {
                sqlWhere.Append(" AND CategoryCommodityName=@CategoryCommodityName");
                parameters.Add(new SqlParameter("@CategoryCommodityName", SqlDbType.NVarChar, 255) { SqlValue = model.CategoryCommodityName });
            }
            if (!string.IsNullOrEmpty(model.CategorySystemName.ToString()))
            {
                sqlWhere.Append(" AND CategorySystemName=@CategorySystemName");
                parameters.Add(new SqlParameter("@CategorySystemName", SqlDbType.NVarChar, 255) { SqlValue = model.CategorySystemName });
            }
            if (!string.IsNullOrEmpty(model.CategoryCommName.ToString()))
            {
                sqlWhere.Append(" AND CategoryCommName=@CategoryCommName");
                parameters.Add(new SqlParameter("@CategoryCommName", SqlDbType.NVarChar, 255) { SqlValue = model.CategoryCommName });
            }
            if (!string.IsNullOrEmpty(model.CategorySpec.ToString()))
            {
                sqlWhere.Append(" AND CategorySpec=@CategorySpec");
                parameters.Add(new SqlParameter("@CategorySpec", SqlDbType.NVarChar, 255) { SqlValue = model.CategorySpec });
            }
            if (!string.IsNullOrEmpty(model.Formulation.ToString()))
            {
                sqlWhere.Append(" AND Formulation=@Formulation");
                parameters.Add(new SqlParameter("@Formulation", SqlDbType.NVarChar, 255) { SqlValue = model.Formulation });
            }
            if (!string.IsNullOrEmpty(model.BusinessModel.ToString()))
            {
                sqlWhere.Append(" AND BusinessModel=@BusinessModel");
                parameters.Add(new SqlParameter("@BusinessModel", SqlDbType.NVarChar, 255) { SqlValue = model.BusinessModel });
            }
            string strSql = string.Format(@"
WITH temp AS ( SELECT rn =  ROW_NUMBER() OVER (ORDER BY AYA_Code  desc), *FROM  Agreement_YNSHigh_Authorize WHERE 1=1 {0} )
SELECT *,rc=(select count(1) from temp) FROM temp WHERE rn BETWEEN {1} AND {2}

                     ", sqlWhere.ToString(), (pageNo - 1) * pageSize + 1, pageNo * pageSize);


            DataTable dt = SqlHelper.Query(strSql, parameters.ToArray()).Tables[0];
            if (dt != null)
            {
                iRecordCount = int.Parse(dt.Rows[0]["rc"].ToString());
                return dt;
            }
            else
            {
                iRecordCount = 0;
                return null;
            }
        }

        public bool DeleteAgreement_YNSHigh_Authorize(string AYA_Code)
   {
        List<SqlParameter> parameters = new List<SqlParameter>();
                    string strSql = string.Format(@"
DELETE Agreement_YNSHigh_Authorize WHERE AYA_Code=AYA_Code

                     ";
     int rowAffect =SqlHelper.Query(strSql, parameters.ToArray()).ToInt();;
      return rowAffect > 0 ? true : false;
      }

        protected void btnExcel_Click(object sender, System.EventArgs e)
        {
            int intPageNo = 1;
            int intPageSize = 65535;
            int recordCount = 0;
            DataTable dt = GetUnAuthorizeAgreePassedDT( Model model intPageNo, intPageSize, out recordCount); 
     string strFileName = "导出Excel" + System.DateTime.Now.ToString(" yyyyMMddHHmmss");
        ExcelUtility excelUtil = new ExcelUtility(this, strFileName);
            List<ExcelHeader> headerS = new List<ExcelHeader>() { 
           new ExcelHeader() { Name = "字段名称自行补全", DataType = EnumColumnDataType.文本, Width = 15 },
           new ExcelHeader() { Name = "字段名称自行补全", DataType = EnumColumnDataType.文本, Width = 15 },
           new ExcelHeader() { Name = "字段名称自行补全", DataType = EnumColumnDataType.文本, Width = 15 },
           new ExcelHeader() { Name = "字段名称自行补全", DataType = EnumColumnDataType.文本, Width = 15 },
           new ExcelHeader() { Name = "字段名称自行补全", DataType = EnumColumnDataType.文本, Width = 15 },
           new ExcelHeader() { Name = "字段名称自行补全", DataType = EnumColumnDataType.文本, Width = 15 },
           new ExcelHeader() { Name = "字段名称自行补全", DataType = EnumColumnDataType.文本, Width = 15 },
           new ExcelHeader() { Name = "字段名称自行补全", DataType = EnumColumnDataType.日期, Width = 15 },
           new ExcelHeader() { Name = "字段名称自行补全", DataType = EnumColumnDataType.日期, Width = 15 },
           new ExcelHeader() { Name = "字段名称自行补全", DataType = EnumColumnDataType.文本, Width = 15 },
           new ExcelHeader() { Name = "字段名称自行补全", DataType = EnumColumnDataType.文本, Width = 15 },
           new ExcelHeader() { Name = "字段名称自行补全", DataType = EnumColumnDataType.文本, Width = 15 },
           new ExcelHeader() { Name = "字段名称自行补全", DataType = EnumColumnDataType.文本, Width = 15 },
           new ExcelHeader() { Name = "字段名称自行补全", DataType = EnumColumnDataType.文本, Width = 15 },
           new ExcelHeader() { Name = "字段名称自行补全", DataType = EnumColumnDataType.文本, Width = 15 },
           new ExcelHeader() { Name = "字段名称自行补全", DataType = EnumColumnDataType.文本, Width = 15 },
           new ExcelHeader() { Name = "字段名称自行补全", DataType = EnumColumnDataType.文本, Width = 15 },
           new ExcelHeader() { Name = "字段名称自行补全", DataType = EnumColumnDataType.文本, Width = 15 },
           new ExcelHeader() { Name = "字段名称自行补全", DataType = EnumColumnDataType.文本, Width = 15 },
           new ExcelHeader() { Name = "字段名称自行补全", DataType = EnumColumnDataType.文本, Width = 15 },
           new ExcelHeader() { Name = "字段名称自行补全", DataType = EnumColumnDataType.文本, Width = 15 },
           new ExcelHeader() { Name = "字段名称自行补全", DataType = EnumColumnDataType.文本, Width = 15 },
           new ExcelHeader() { Name = "字段名称自行补全", DataType = EnumColumnDataType.文本, Width = 15 },
           new ExcelHeader() { Name = "字段名称自行补全", DataType = EnumColumnDataType.文本, Width = 15 },
          };
            excelUtil.CreateHeader(headerS);
            if (dt != null && dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    List<string> dataVals = new List<string>() { 
                            dr[" AYA_Code"].ToString()  
                            dr[" AYHA_Code"].ToString()  
                            dr[" Ctg_ID"].ToString()  
                            dr[" HospitalCode"].ToString()  
                            dr[" HospitalName"].ToString()  
                            dr[" HospitalGrad"].ToString()  
                            dr[" HospitalRegionID"].ToString()  
                            dr[" DevelopmentLimitTime"].ToString()  
                            dr[" EffectiveTime"].ToString()  
                            dr[" MarketingManagementFee"].ToString()  
                            dr[" BidPrice"].ToString()  
                            dr[" DeliveryCode"].ToString()  
                            dr[" DeliveryName"].ToString()  
                            dr[" AgreeAdjuestType"].ToString()  
                            dr[" ChangeContent"].ToString()  
                            dr[" Status"].ToString()  
                            dr[" DeliveryPrice"].ToString()  
                            dr[" BasePrice"].ToString()  
                            dr[" CategoryCommodityName"].ToString()  
                            dr[" CategorySystemName"].ToString()  
                            dr[" CategoryCommName"].ToString()  
                            dr[" CategorySpec"].ToString()  
                            dr[" Formulation"].ToString()  
                            dr[" BusinessModel"].ToString()  
          };       
                    excelUtil.CreateItemRow(dataVals);
                }
            }
            excelUtil.Export();
            }

金沙注册送58 25View Code

百度网盘:链接:
密码:7s6r

 

接口类:IHost.cs

 

金沙注册送58 26

金沙注册送58 27View Code

 

仓库储存全局变量类:Context.cs 以及 AppContext.cs

 

金沙注册送58 28View Code

 

金沙注册送58 29View Code

二、打开自动生成工具(自身本人用C++写的)。

金沙注册送58 ,接下去我们建立多少个测试的页面:A.XAML,B.XAML.Default.XAML
以便多页面包车型大巴切换,每一种界面写一些融洽标记的新闻即可

 

登6界面:Login.XAML

金沙注册送58 30

就是界面放3个LABEL和3个文本框,默许账号和密码都是:admin
,具体的类别本来要去查询数据库了。

 

根本来说MainPage界面包车型大巴结构:

 

添加程序集:System.Windows.Controls.Navigation
的引用,在档次中添加引用,.NET下边就能够找到该程序集

三、从PowerDesigner中取出News表的字段音讯。

主界面小编使用G奥迪Q3ID的贰列,

 

左边列放三个LISTBOX 来展现档次切换的页面地址新闻(类似与菜单呢),

金沙注册送58 31

左侧列放置贰个navigation 控件,利用此控件的IFRAM指向区别的界面音信。

 

XAML的源码如下:

 

金沙注册送58 32View Code

四、填入DBBuildCode工具,点击“生成”按钮,在工具目录生成一个文本(CNewsInfo.cs、CNews.cs)。注:表结构中剧情可以借助于ultraedit来拍卖。

好了那般项目所急需的准备干活就曾经做完,项目如下:

 

金沙注册送58 33

金沙注册送58 34

接下去起始我们的工作了,

 

在MainPage.Xaml.cs

 

概念本地存储援助类

伍、把转变的1个文件(CNewsInfo.cs、CNews.cs)分别新添加至DBEntity、DBInterface文件夹,发现数据库操作的代码都曾经变更。

//本地cookie 类
SLCookieHelp slcookie = new SLCookieHelp();

 

日增界面加载事件  Loaded += new Routed伊芙ntHandler(MainPage_Loaded);

金沙注册送58 35

金沙注册送58 36

 

1  string url = @"/Default.xaml";
2             if (!string.IsNullOrWhiteSpace(slcookie.PageAddress))
3             {
4                 url = slcookie.PageAddress;
5             }
6             Contnetframe.Navigate(new Uri(url, UriKind.Relative));

 

透过上边来加载彰显的页面地址

陆、设置Web.config中数据库连接串等音讯。

然后在LISTBOX的取舍事件,对本地存款和储蓄的地方进行更新

 

金沙注册送58 37View Code

<?xml version="1.0"?>
<!--
  有关如何配置 ASP.NET 应用程序的详细信息,请访问
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
    <system.web>
        <compilation debug="true" targetFramework="4.0"/>
    </system.web>
    <appSettings>
        <add key="DatabasePre" value=""/>
        <add key="mssql" value="1"/>
    </appSettings>
    <connectionStrings>
        <add name="Conn" connectionString="server=local;database=news;User Id=sa;pwd=sa;"/>
    </connectionStrings>
</configuration>

如此主界面包车型地铁工作就成功了,

 

聊起底再登陆界面包车型地铁加载事件扩展本地存款和储蓄的判断以及登陆事件的本土存款和储蓄账户消息的赋值即可

4、完毕前台C#操作代码。

方法如下:

 

金沙注册送58 38

在NewsList.aspx.cs、NewsEdit.aspx.cs达成对应的控件响应操作代码。

金沙注册送58 39

首要代码如下:

 1   //加载事件
 2         void Login_Loaded(object sender, RoutedEventArgs e)
 3         {
 4             //如果本地COOKIE有值 直接进入界面
 5             if (slcookie != null && !string.IsNullOrWhiteSpace(slcookie.UserID)  && !string.IsNullOrWhiteSpace(slcookie.ExitTime))
 6             {             
 7                 //判断退出时间和登陆时差是否大于5秒
 8                 DateTime now = DateTime.Now;
 9                 DateTime exit = Convert.ToDateTime(slcookie.ExitTime);
10                 TimeSpan ts = now - exit;
11                 //当操作时间小于5秒默认为刷新
12                 if (ts.TotalSeconds < 5 && ts.TotalSeconds > 0)
13                 {
14                     MainPage mainpage = new MainPage();
15                     Context.Host.SetRootVisual(mainpage);
16                 }
17                 else
18                 {
19                     //清空本地COOKIE
20                     slcookie.ClearCookie();
21                 }
22             }
23         }

 

金沙注册送58 40

 private void InitDataGrid()
    {
        DataTable dt = new DataTable();
        if (this.txtSearch.Text != "")
        {
            dt = oNews.GetInfoForSearch(this.txtSearch.Text.Trim());
        }
        else
            dt = oNews.GetInfo();

        for (int i = 0; i < dt.Rows.Count; i++)
        {
            string sFlagRecomTemp = "";
            //推荐标记
            string sFlagRecom = dt.Rows[i]["FlagRecom"].ToString();
            {
                if (sFlagRecom == "0")
                {
                    sFlagRecomTemp = "否";
                }
                if (sFlagRecom == "1")
                {
                    sFlagRecomTemp = "是";
                }
            }
            dt.Rows[i]["FlagRecom"] = sFlagRecomTemp;
        }
        int cup = Convert.ToInt32(this.lbCurrentPage.Text);
        PagedDataSource ps = new PagedDataSource();
        ps.DataSource = dt.DefaultView;
        ps.AllowPaging = true;
        ps.PageSize = 24;
        ps.CurrentPageIndex = cup - 1;
        this.lbPage.Text = ps.PageCount.ToString();

        this.ddlPage.Items.Clear();
        for (int i = 1; i < ps.PageCount + 1; i++)
        {
            ListItem li = new ListItem(i.ToString(), i.ToString());
            this.ddlPage.Items.Add(i.ToString());
        }
        this.LinkUp.Enabled = true;
        this.LinkDown.Enabled = true;
        this.ddlPage.SelectedValue = cup.ToString();
        if (Convert.ToInt16(this.lbCurrentPage.Text) < 2)
        {
            this.LinkFirst.Enabled = false;
            this.LinkUp.Enabled = false;
        }
        else
        {
            this.LinkFirst.Enabled = true;
            this.LinkUp.Enabled = true;
        }
        if (Convert.ToInt16(this.lbCurrentPage.Text) >= Convert.ToInt16(this.lbPage.Text))
        {
            this.LinkDown.Enabled = false;
            this.LinkLast.Enabled = false;
        }
        else
        {
            this.LinkDown.Enabled = true;
            this.LinkLast.Enabled = true;
        }

        this.dgList.DataSource = ps;
        this.dgList.DataBind();

        if (dt.Rows.Count < 1)
        {
            this.currentPage.Style.Add("display", "none");
            this.currentPageError.Style.Add("display", "");
        }
        else
        {
            this.currentPage.Style.Add("display", "");
            this.currentPageError.Style.Add("display", "none");
        }
    }

 private void InitNewsEdit()
    {
        int iId = 0;
        string sEdit = "";
        if (Request.Params["edit"] != null)
        {
            sEdit = Request.Params["edit"].ToString().ToLower();
            ViewState["flagedit"] = sEdit;
        }
        if (Request.Params["id"] != null)
        {
            iId = Convert.ToInt32(Request.Params["id"].ToString());
            ViewState["id"] = iId;
        }
        switch (sEdit)
        {
            case "add":
                {
                    this.lbTitle.Text = "添加新闻";
                    sFlagMsg = "fail";
                }
                break;
            case "edit":
                {
                    this.lbTitle.Text = "修改新闻";
                    sFlagMsg = "ok";

                    CNewsInfo oNewsInfo = new CNewsInfo();
                    oNewsInfo = oNews.GetInfo(iId);

                    int iSid = 0;
                    iSid = oNewsInfo.Nid;

                    this.txtTitle.Text = oNewsInfo.Title;
                    this.txtCreator.Text = oNewsInfo.Creator;
                    this.ddlFlagRecom.SelectedValue = oNewsInfo.FlagRecom;
                    this.txtContent.Text = oNewsInfo.Content;
                }
                break;
            default:
                break;
        }
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        int iId = 0;
        iId = CTypeConverter.StrToInt(ViewState["id"].ToString());

        string sTitle = "";
        string sCreator = "";
        string sContent = "";
        int iHits = 0;
        string sFlagRecom = "";

        sTitle = this.txtTitle.Text.Trim();
        sCreator = this.txtCreator.Text.Trim();
        sContent = this.txtContent.Text.Trim();
        sFlagRecom = this.ddlFlagRecom.SelectedValue;

        string sFlagEdit = ViewState["flagedit"].ToString();
        switch (sFlagEdit)
        {
            case "add":
                {
                    CNewsInfo oNewsInfo = new CNewsInfo();
                    oNewsInfo.Title = sTitle;
                    oNewsInfo.Creator = sCreator;
                    oNewsInfo.Content = sContent;
                    oNewsInfo.Hits = iHits;
                    oNewsInfo.FlagRecom = sFlagRecom;

                    oNews.Insert(oNewsInfo);
                    Response.Redirect("SystemInfo.aspx?msgname=" + Server.UrlEncode("新闻添加成功!") + "&backpage=NewsEdit.aspx?edit=add&backname=" + Server.UrlEncode("继续添加新闻"));
                }
                break;
            case "edit":
                {
                    CNewsInfo oNewsInfo = new CNewsInfo();
                    oNewsInfo = oNews.GetInfo(iId);

                    oNewsInfo.Title = sTitle;
                    oNewsInfo.Creator = sCreator;
                    oNewsInfo.Content = sContent;
                    oNewsInfo.FlagRecom = sFlagRecom;

                    oNews.Update(iId, oNewsInfo);
                    Response.Redirect("SystemInfo.aspx?msgname=" + Server.UrlEncode("新闻修改成功!") + "&backpage=NewsList.aspx&backname=" + Server.UrlEncode("返回新闻列表"));
                }
                break;
            default:
                break;
        }
    }

金沙注册送58 41

 

金沙注册送58 42

五、运行NewsList.aspx效果图。

 1  //登陆 
 2         private void btnLogin_Click(object sender, RoutedEventArgs e)
 3         {
 4             if (string.IsNullOrWhiteSpace(txtuid.Text) || string.IsNullOrWhiteSpace(txtpwd.Text))
 5             {
 6                 MessageBox.Show("用户名和密码不可为空");
 7                 return;
 8             }
 9 
10             if (txtuid.Text == "admin" && txtpwd.Text == "admin")
11             {
12                 slcookie.UserID = "admin";
13                 MainPage mainpage = new MainPage();
14                 Context.Host.SetRootVisual(mainpage);
15             }
16             else
17             {
18                 MessageBox.Show("用户名和密码输入不正确");
19             }
20         }

  有展现、查询、添加、修改、删除、分页功用。

金沙注册送58 43

金沙注册送58 44

OK!完工,那样贰个大旨的SL程序的刷新效能就完了了,因为也是第二遍做SL项目,当然肯定有牵记不周或许有更加好的办法消除此难点,还自作者梦想论坛的硬汉们给予指点,假若写的非平时的地点还望大家给予拍砖,虚心接受大家的评论。

 PS:原型是如此,能够根据各个网址的作风去定制效果。源码。

 

相关文章

网站地图xml地图