接口練習

前臺代碼:

<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.pswp.cn/news/274209.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/274209.shtml
英文地址,請注明出處:http://en.pswp.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版發布之前推出。…