接口练习

前台代码:

<form id="form1" runat="server">
    <div>
        见面时间:<asp:TextBox ID="MeetTime" runat="server"></asp:TextBox><br />
        见面地点:<asp:TextBox ID="MeetAddress" runat="server"></asp:TextBox><br />
        当天天气:<asp:TextBox ID="MeetWeather" runat="server"></asp:TextBox><br />
        就餐地点:<asp:TextBox ID="EatAddress" runat="server"></asp:TextBox><br />
        <asp:Button ID="btnSave" runat="server" Text="保存" οnclick="btnSave_Click" /><br />
        查找键的值: <asp:TextBox ID="FindKey" runat="server"></asp:TextBox>
        <asp:Button ID="btnFindKey" runat="server" Text="查找键值"
            οnclick="btnFindKey_Click" /><br />
        <asp:Button ID="btnShowKey" runat="server" Text="显示所有的键"
            οnclick="btnShowKey_Click" /><br />
        <asp:Button ID="btnIsExist" runat="server" Text="判断某个要素是否存在"
            οnclick="btnIsExist_Click" />
    </div>
    </form>

 

后台:

protected void btnSave_Click(object sender, EventArgs e)
        {
            ClassLibrary1.IMeetYou meet = GetType();
            meet.SetInfo("MeetTime", MeetTime.Text);
            meet.SetInfo("MeetAddress", MeetAddress.Text);
            meet.SetInfo("MeetWeather", MeetWeather.Text);
            meet.SetInfo("EatAddress", EatAddress.Text);
            ViewState["meet"] = meet;
        }

        protected void btnFindKey_Click(object sender, EventArgs e)
        {
            if (ViewState["meet"] != null)
            {
                IMeetYou meet = ViewState["meet"] as IMeetYou;
                string meetValue = meet.GetInfo(FindKey.Text);
                Response.Write(meetValue);
            }
        }

        protected void btnShowKey_Click(object sender, EventArgs e)
        {
            if (ViewState["meet"] != null)
            {
                IMeetYou meet = ViewState["meet"] as IMeetYou;
                string[] infos = meet.name;
                foreach (string item in infos)
                {
                    Response.Write(item + "    ");
                }
            }
        }

        protected void btnIsExist_Click(object sender, EventArgs e)
        {
            if (ViewState["meet"] != null)
            {
                IMeetYou meet = ViewState["meet"] as IMeetYou;
                Response.Write(meet.isExist("1111"));
            }
        }

        private IMeetYou GetType()
        {
            ClassLibrary1.IMeetYou meet = null;
            string conType = ConfigurationManager.AppSettings["conType"];
            if (conType.ToUpper() == "MEMORY")
            { meet = new MemorySetting(); }
            else if (conType.ToUpper() == "ENVIRONMENT")
            { meet = new EnvironmentSettings(); }
            else if (conType.ToUpper() == "SQLSERVER")
            { meet = new SqlServerSettings(); }
            return meet;
        }

---------------------------EnvironmentSettings.cs--------------------------

namespace ClassLibrary1
{
    [Serializable]
     public class EnvironmentSettings:IMeetYou
    {
        
        public void SetInfo(string name, string value)
        {
            Environment.SetEnvironmentVariable(name, value,EnvironmentVariableTarget.User);
        }

        public string GetInfo(string name)
        {
           return  Environment.GetEnvironmentVariable(name, EnvironmentVariableTarget.User);
        }

        public string[] name
        {
            get {
                IDictionary dic = Environment.GetEnvironmentVariables(EnvironmentVariableTarget.User);
                List<string> list = new List<string>();
                foreach (object item in dic.Keys)
                {
                    list.Add(item.ToString());
                }
                return list.ToArray();
            }
        }

        public bool isExist(string name)
        {
            IDictionary dic = Environment.GetEnvironmentVariables(EnvironmentVariableTarget.User);
            return dic.Contains(name);
        }
    }
}

 

----------------------------------IMeetYou.cs---------------------------

     public interface IMeetYou
    {
         void SetInfo(string name, string value);//用来保存数据
         string GetInfo(string name);//根据某项的键,查找值
         string[] name { get; }//获得所有项的值
         bool isExist(string name);//判断某项的值是否存在
    }

----------------------------------MemorySetting.cs-------------------------------

namespace ClassLibrary1
{
    [Serializable]
     public class MemorySetting:IMeetYou
    {
        
         Dictionary<string, string> dic = new Dictionary<string, string>();
        public void SetInfo(string name, string value)
        {
            dic.Add(name, value);
        }

        public string GetInfo(string name)
        {
            return dic[name];
        }

        public string[] name
        {
            get { return dic.Keys.ToArray(); }
        }

        public bool isExist(string name)
        {
            return dic.ContainsKey(name);
        }
    }
}

-------------------------------SqlServerSettings.cs----------------------------

namespace ClassLibrary1
{
    [Serializable]
    public class SqlServerSettings:IMeetYou
    {
       
        //public IDbConnection conn = new SqlConnection(@"Data Source=.;Initial Catalog=News;Persist Security Info=True;User ID=sa;Password=111111");
        public void SetInfo(string name, string value)
        {
            IDbConnection conn = new SqlConnection(@"Data Source=.;Initial Catalog=News;Persist Security Info=True;User ID=sa;Password=111111");

            conn.Open();
            IDbCommand cmd = conn.CreateCommand();
            cmd.CommandText = "insert into T_Meet(T_MeetKey,T_MeetValue) values(@meetkey,@meetvalue)";
            cmd.Parameters.Add(new SqlParameter("@meetkey",name));
            cmd.Parameters.Add(new SqlParameter("@meetvalue",value));
            cmd.ExecuteNonQuery();
            cmd.Dispose();
            conn.Dispose();
        }

        public string GetInfo(string name)
        {
            IDbConnection conn = new SqlConnection(@"Data Source=.;Initial Catalog=News;Persist Security Info=True;User ID=sa;Password=111111");

            conn.Open();
            IDbCommand cmd = conn.CreateCommand();
            cmd.CommandText = "select T_MeetValue from T_Meet where T_MeetKey=@meetkey";
            cmd.Parameters.Add(new SqlParameter("@meetkey",name));
            object obj = cmd.ExecuteScalar();
            cmd.Dispose();
            conn.Dispose();
            return obj.ToString();
        }

        public string[] name
        {
            get {
                IDbConnection conn = new SqlConnection(@"Data Source=.;Initial Catalog=News;Persist Security Info=True;User ID=sa;Password=111111");

                List<string> list = new List<string>();
                conn.Open();
                IDbCommand cmd = conn.CreateCommand();
                cmd.CommandText = "select T_MeetKey from T_Meet";
                IDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                         list.Add(reader["T_MeetKey"].ToString());
                }
                return list.ToArray();
            }
        }

        public bool isExist(string name)
        {
           IDbConnection conn = new SqlConnection(@"Data Source=.;Initial Catalog=News;Persist Security Info=True;User ID=sa;Password=111111");

            conn.Open();
            IDbCommand cmd = conn.CreateCommand();
            cmd.CommandText = "select T_MeetValue from T_Meet where T_MeetKey=@meetkey";
            cmd.Parameters.Add(new SqlParameter("@meetkey", name));
            IDataReader read = cmd.ExecuteReader();
            bool b=false;
            if (read.Read())
            { b = true; }
            cmd.Dispose();
            conn.Dispose();
            return b;
        }
    }
}

转载于:https://www.cnblogs.com/qiqiBoKe/archive/2013/06/13/3134724.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/274209.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

写saas创业的书_我在SaaS创业公司担任UX设计师的第一个月中学到的三件事

写saas创业的书I recently transitioned from being a copywriter at an ad agency to a UX Designer at a SaaS startup. To add more multidisciplinary skills into the mix, I graduated with a Bachelor in Accountancy.我最近从一名广告代理商的撰稿人过渡到了SaaS初创公…

ui项目答辩中学到了什么_我在UI设计9年中学到的12件事

ui项目答辩中学到了什么重点 (Top highlight)I know these can seem a bit clich but I will try to explain everything from my own experience.我知道这些内容似乎有些陈词滥调&#xff0c;但我会尝试根据自己的经验来解释所有内容。 第一名 (No.1 Never assume) The first…

linux下命令行的使用:使用sed命令操作文件

用该命令sed删除文件test.txt中包含某个字符串abc的行: sed /adc/d test.txt >result.txt 在文件test.txt中删除从开头到含有某个字符串abc的行 sed 1,/abc/d test.txt >result.txt 获取文件test.txt中包含字符串abc的行 cat test.txt |grep "abc" > resul…

ux的重要性_UX中清晰的重要性

ux的重要性重点 (Top highlight)Times, since the very first occurrences of web design in the 90’s, have changed a lot design-wise. The particular technology and its applications got more stable. Human-computer interaction (HCI) was deeply researched, design…

工欲善其事,必先利其器

vs2010中一些常用的快捷键、组合键&#xff1a; 1、快速格式化 CtrlED 2、注释选中部分 CtrlEC 3、停止调试 ShiftF5 4、取消注释选中部分 CtrlEU 5、显示解决方案资源管理器 CtrlWS 6、快速折叠 CtrlMO 7、封装一个字段 CtrlRE 8、查看属性 CtrlWP 9…

可靠消息最终一致性设计_如何最终启动您的设计产品组合

可靠消息最终一致性设计It’s not a secret that most designers procrastinate on their portfolios whether it is to update them or to create them in the first place.大多数设计师在更新产品组合时还是拖延产品组合并不是秘密。 首先创建它们 。 Hopefully, by the e…

台式机共享笔记本的无线网络(只需要一根网线)

以windowsXP系统为例 一、笔记本的设置方法&#xff1a; 1.先将笔记本的无线连接共享给有线网卡 将鼠标放到桌面的 网上邻居 上&#xff0c;按鼠标右键&#xff0c;选属性&#xff0c;再将鼠标放到无线连接上&#xff0c;又是按鼠标右键&#xff0c;选属性&#xff0c;在弹出的…

游戏用户体验指标_电子游戏如何超越游戏化的用户体验

游戏用户体验指标游戏UX (GAMES UX) During a time when the time spent on video games has reached record breaking heights, due to excessive time indoors, gamification has more of a place now than ever before.d uring的时候花在视频游戏的时间已经达到了 破纪录的高…

JAVA编程心得-JAVA实现CRC-CCITT(XMODEM)算法

CRC即循环冗余校验码&#xff08;Cyclic Redundancy Check&#xff09;&#xff1a;是数据通信领域中最常用的一种差错校验码&#xff0c;其特征是信息字段和校验字段的长度可以任意选定。 1 byte checksum CRC-16 CRC-16 (Modbus) CRC-16 (Sick) …

什么字体字母和数字大小一样_字母和字体如何适应我们的屏幕

什么字体字母和数字大小一样Writing went through many iterations before it became what is today. Times New Roman wasn’t the default script for ancient Egyptians, in fact, paper didn’t even exist when the first words were written.写作经历了许多迭代&#xff…

jenkins 通过批处理自动构建 非标准项目

之前介绍了java和vs2010的项目构建&#xff0c;这些都是比较常见的&#xff0c;所以都用专门的工具。但但难免会遇到一些不常见的项目&#xff0c;下面介绍通过批处理进行构建&#xff0c;并用jenkins调用.我们这里使用plc语言&#xff0c;没有标准环境&#xff0c;只有使用bat…

效果图底图 线框图_5分钟的线框图教程

效果图底图 线框图为什么使用线框&#xff1f; (Why wireframe?) Simply put, wireframes provide a structure and layout for content and assets.简而言之&#xff0c;线框提供了内容和资产的结构和布局。 You can wireframe just about any kind of presentation, from p…

多线程 - 你知道线程栈吗

问题 1. local 变量的压栈和出栈过程 void func1(){ int a 0; int b 0; } 系统中有一个栈顶指针&#xff0c;每次分配和回收local 变量时&#xff0c;其实就是移动栈指针。 2. static local变量的分配风险 void func2(){ static int a 0; } 这个变量a可能会被分…

怎么让qt发声_第3部分:添加网络字体-让我们的单词发声

怎么让qt发声This is a big week for the project. While it was an important step last week to establish some basic responsiveness, we couldn’t really nail down the typography until we added the typeface. Too many aspects of the feel, proportions, and overal…

mysql语句中把string类型字段转datetime类型

mysql语句中把string类型字段转datetime类型在mysql里面利用str_to_date&#xff08;&#xff09;把字符串转换为日期此处以表h_hotelcontext的Start_time和End_time字段为例&#xff0c;查询当前时间在此范围之内的数据。 www.2cto.com select * from h_hotelcontext where …

名词解释:对等知识互联网_网站设计理论:比较和对等

名词解释:对等知识互联网Equivalence and contrast, connection and distinction, categorization and non-categorization are all ways to distinguish the same or different elements. Based on the information they carry, we hope that the equivalent elements can hav…

hadoop深入研究:(五)——Archives

转载请注明来源地址&#xff1a;http://blog.csdn.net/lastsweetop/article/details/9123155 简介 我们在hadoop深入研究:(一)——hdfs介绍里已讲过&#xff0c;hdfs并不擅长存储小文件&#xff0c;因为每个文件最少一个block&#xff0c;每个block的元数据都会在namenode节点占…

人民币小写金额转大写金额

#region 人民币小写金额转大写金额/// <summary>/// 小写金额转大写金额/// </summary>/// <param name"Money">接收需要转换的小写金额</param>/// <returns>返回大写金额</returns>public static string ConvertMoney(Decimal…

饥饿的盛世读后感_满足任何设计师饥饿感的原型制作工具

饥饿的盛世读后感Tell me if this story sounds familiar to you. You just wrapped up a design in Sketch -a design that took you hours, and now you want to bring it to life. Sketch’s built-in prototyping tool doesn’t allow you to create all the interactions …

关于软件版本的说明

Trial&#xff1a;试用版&#xff0c;软件在功能或时间上有所限制&#xff0c;如果想解除限制&#xff0c;需要购买零售版。 Retail&#xff1a;零售版。Free&#xff1a;免费版。Full&#xff1a;完全版。Alpha&#xff1a;内部测试版&#xff0c;通常在Beta版发布之前推出。…