login.cs
上传用户:toshiba_01
上传日期:2007-06-08
资源大小:306k
文件大小:8k
源码类别:

酒店行业

开发平台:

C#

  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using System.Data ;
  7. using System.Data .SqlClient ;
  8. namespace RoomManage
  9. {
  10. /// <summary>
  11. /// login 的摘要说明。
  12. /// </summary>
  13. public class login : System.Windows.Forms.Form
  14. {
  15. private System.Windows.Forms.Label label1;
  16. private System.Windows.Forms.Label label2;
  17. private System.Windows.Forms.TextBox textBox2;
  18. private System.Windows.Forms.Button button1;
  19. private System.Windows.Forms.Button button2;
  20. private System.Windows.Forms.ComboBox comboBox1;
  21. private System.Windows.Forms.Label label3;
  22. private System.Windows.Forms.Button button3;
  23. /// <summary>
  24. /// 必需的设计器变量。
  25. /// </summary>
  26. private System.ComponentModel.Container components = null;
  27. public login()
  28. {
  29. //
  30. // Windows 窗体设计器支持所必需的
  31. //
  32. InitializeComponent();
  33. //
  34. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  35. //
  36. }
  37. /// <summary>
  38. /// 清理所有正在使用的资源。
  39. /// </summary>
  40. static void Main()
  41. {
  42. login log=new login ();
  43. log.ShowDialog ();
  44. Application.Run (new main (cc,ss));
  45. }
  46. protected override void Dispose( bool disposing )
  47. {
  48. if( disposing )
  49. {
  50. if(components != null)
  51. {
  52. components.Dispose();
  53. }
  54. }
  55. base.Dispose( disposing );
  56. }
  57. #region Windows 窗体设计器生成的代码
  58. /// <summary>
  59. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  60. /// 此方法的内容。
  61. /// </summary>
  62. private void InitializeComponent()
  63. {
  64. this.label1 = new System.Windows.Forms.Label();
  65. this.label2 = new System.Windows.Forms.Label();
  66. this.textBox2 = new System.Windows.Forms.TextBox();
  67. this.button1 = new System.Windows.Forms.Button();
  68. this.button2 = new System.Windows.Forms.Button();
  69. this.comboBox1 = new System.Windows.Forms.ComboBox();
  70. this.label3 = new System.Windows.Forms.Label();
  71. this.button3 = new System.Windows.Forms.Button();
  72. this.SuspendLayout();
  73. // 
  74. // label1
  75. // 
  76. this.label1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
  77. this.label1.Location = new System.Drawing.Point(16, 23);
  78. this.label1.Name = "label1";
  79. this.label1.Size = new System.Drawing.Size(56, 23);
  80. this.label1.TabIndex = 0;
  81. this.label1.Text = "操作员:";
  82. this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  83. // 
  84. // label2
  85. // 
  86. this.label2.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
  87. this.label2.Location = new System.Drawing.Point(16, 56);
  88. this.label2.Name = "label2";
  89. this.label2.Size = new System.Drawing.Size(64, 23);
  90. this.label2.TabIndex = 1;
  91. this.label2.Text = "密  码:";
  92. this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  93. // 
  94. // textBox2
  95. // 
  96. this.textBox2.Location = new System.Drawing.Point(80, 57);
  97. this.textBox2.Name = "textBox2";
  98. this.textBox2.PasswordChar = '*';
  99. this.textBox2.Size = new System.Drawing.Size(120, 21);
  100. this.textBox2.TabIndex = 1;
  101. this.textBox2.Text = "";
  102. // 
  103. // button1
  104. // 
  105. this.button1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
  106. this.button1.Location = new System.Drawing.Point(16, 112);
  107. this.button1.Name = "button1";
  108. this.button1.Size = new System.Drawing.Size(56, 23);
  109. this.button1.TabIndex = 2;
  110. this.button1.Text = "登陆";
  111. this.button1.Click += new System.EventHandler(this.button1_Click);
  112. // 
  113. // button2
  114. // 
  115. this.button2.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
  116. this.button2.Location = new System.Drawing.Point(96, 112);
  117. this.button2.Name = "button2";
  118. this.button2.Size = new System.Drawing.Size(56, 23);
  119. this.button2.TabIndex = 3;
  120. this.button2.Text = "退出";
  121. this.button2.Click += new System.EventHandler(this.button2_Click);
  122. // 
  123. // comboBox1
  124. // 
  125. this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  126. this.comboBox1.Location = new System.Drawing.Point(80, 24);
  127. this.comboBox1.Name = "comboBox1";
  128. this.comboBox1.Size = new System.Drawing.Size(121, 20);
  129. this.comboBox1.TabIndex = 8;
  130. this.comboBox1.DropDown += new System.EventHandler(this.comboBox1_DropDown);
  131. this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
  132. // 
  133. // label3
  134. // 
  135. this.label3.ForeColor = System.Drawing.Color.Red;
  136. this.label3.Location = new System.Drawing.Point(16, 88);
  137. this.label3.Name = "label3";
  138. this.label3.Size = new System.Drawing.Size(128, 23);
  139. this.label3.TabIndex = 7;
  140. this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  141. // 
  142. // button3
  143. // 
  144. this.button3.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
  145. this.button3.Location = new System.Drawing.Point(176, 112);
  146. this.button3.Name = "button3";
  147. this.button3.Size = new System.Drawing.Size(56, 23);
  148. this.button3.TabIndex = 4;
  149. this.button3.Text = "取消";
  150. this.button3.Click += new System.EventHandler(this.button3_Click);
  151. // 
  152. // login
  153. // 
  154. this.AutoScale = false;
  155. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  156. this.ClientSize = new System.Drawing.Size(240, 141);
  157. this.ControlBox = false;
  158. this.Controls.Add(this.button3);
  159. this.Controls.Add(this.label3);
  160. this.Controls.Add(this.comboBox1);
  161. this.Controls.Add(this.button2);
  162. this.Controls.Add(this.button1);
  163. this.Controls.Add(this.textBox2);
  164. this.Controls.Add(this.label2);
  165. this.Controls.Add(this.label1);
  166. this.MaximizeBox = false;
  167. this.MaximumSize = new System.Drawing.Size(248, 168);
  168. this.MinimizeBox = false;
  169. this.MinimumSize = new System.Drawing.Size(248, 168);
  170. this.Name = "login";
  171. this.ShowInTaskbar = false;
  172. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  173. this.Text = "系统登陆";
  174. this.TopMost = true;
  175. this.Load += new System.EventHandler(this.login_Load);
  176. this.ResumeLayout(false);
  177. }
  178. #endregion
  179. DataConn dc=new DataConn();
  180. public static char cc='0';//传递权限级别
  181. public static string ss="";//传递操作员姓名
  182. private void login_Load(object sender, System.EventArgs e)
  183. {
  184. this.AcceptButton=this.button1 ;//使每次按下回车键时总是激发button1
  185. this.textBox2 .Text ="";
  186. }
  187. private void button2_Click(object sender, System.EventArgs e)
  188. {
  189. this.label3 .Text ="";
  190. dc.exit();
  191. }
  192. private void button1_Click(object sender, System.EventArgs e)
  193. {
  194. this.label3 .Text ="";
  195. string str=dc.connstr ;
  196. SqlConnection conn=new SqlConnection (str);
  197. string sql="select 权限级别 from tabpurview where 操作员姓名='"+this.comboBox1 .Text +"' and  密码='"+this.textBox2 .Text+"'";
  198. SqlCommand cmd=new SqlCommand(sql,conn);
  199. conn.Open ();
  200. SqlDataReader dr= cmd.ExecuteReader();
  201. try
  202. {
  203. if(dr.Read())
  204. {
  205. cc=Convert.ToChar(dr["权限级别"]);
  206. ss=this.comboBox1 .Text ;
  207. this.Close ();
  208. }
  209. else
  210. {
  211. this.label3 .Text ="密码有误!";
  212. }
  213. }
  214. catch(SqlException ee)
  215. {
  216. MessageBox.Show (ee.Message,"错误!");
  217. }
  218. finally
  219. {
  220. dr.Close ();
  221. conn.Close ();
  222. cmd.Dispose ();
  223. }
  224. }
  225. private void button3_Click(object sender, System.EventArgs e)
  226. {
  227. this.Close ();
  228. }
  229. private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
  230. {
  231. this.textBox2 .Text ="";
  232. }
  233. private void comboBox1_DropDown(object sender, System.EventArgs e)
  234. {
  235. string str=dc.connstr ;
  236. SqlConnection conn=new SqlConnection (str);
  237. string sql="select * from tabpurview";
  238. SqlDataAdapter adapter=new SqlDataAdapter (sql,conn);
  239. DataSet dataset=new DataSet ();
  240. try
  241. {
  242. adapter.Fill (dataset,"tabpurview");
  243. this.comboBox1 .DisplayMember="操作员姓名";
  244. this.comboBox1 .DataSource =dataset.Tables ["tabpurview"];
  245. }
  246. catch(SqlException ee)
  247. {
  248. MessageBox.Show (ee.Message,"错误!");
  249. }
  250. finally
  251. {
  252. conn.Dispose ();
  253. adapter.Dispose ();
  254. dataset.Dispose ();
  255. }
  256. }
  257. }
  258. }