ClientDataManage.cs
上传用户:hjieqiu
上传日期:2013-05-11
资源大小:16494k
文件大小:12k
源码类别:

企业管理

开发平台:

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. namespace 进销存管理系统
  8. {
  9. /// <summary>
  10. /// ClientDataManage 的摘要说明。
  11. /// </summary>
  12. public class ClientDataManage : System.Windows.Forms.Form
  13. {
  14. private DataSet ds = new DataSet();
  15. private LinkDataBase link = new LinkDataBase();
  16. private string sendTableName = "客户清单";
  17. private string sendStrSQL = "SELECT 客户编号, 拼音编码, 名称, 联系人, 地址, 邮编, 区号, 地区, 电话, 传真, 电报, 简称, 开户行, 开户行邮编, 银行帐号, 税号, 性质, 业务员, 业务部门, 授信额度 FROM 客户清单";
  18. private System.Windows.Forms.Label label1;
  19. private System.Windows.Forms.TextBox txt_WareWord;
  20. private System.Windows.Forms.Button btn_Search;
  21. private System.Windows.Forms.GroupBox groupBox1;
  22. private System.Windows.Forms.ToolBar toolBar1;
  23. private System.Windows.Forms.ToolBarButton tbarBtnSave;
  24. private System.Windows.Forms.ToolBarButton tbarBtnDelete;
  25. private System.Windows.Forms.ImageList imageList1;
  26. private System.Windows.Forms.DataGrid dgrd_ClientData;
  27. private System.ComponentModel.IContainer components;
  28. public ClientDataManage()
  29. {
  30. //
  31. // Windows 窗体设计器支持所必需的
  32. //
  33. InitializeComponent();
  34. //
  35. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  36. //
  37. }
  38. //------------重载构造函数,判断窗体调用原因-------------
  39. public ClientDataManage(bool blToolBarShow)
  40. {
  41. //
  42. // Windows 窗体设计器支持所必需的
  43. //
  44. InitializeComponent();
  45. //
  46. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  47. //
  48. this.ds = this.link.SelectDataBase(sendStrSQL,sendTableName);
  49. //如果blToolBarShow为false,则表示该窗体使由销售单和进货单双击时生成
  50. this.DataGridStateControl(blToolBarShow); 
  51. this.dgrd_ClientData.DataSource = ds.Tables[0];
  52. this.toolBar1.Enabled = blToolBarShow;
  53. }
  54. /// <summary>
  55. /// 清理所有正在使用的资源。
  56. /// </summary>
  57. protected override void Dispose( bool disposing )
  58. {
  59. if( disposing )
  60. {
  61. if(components != null)
  62. {
  63. components.Dispose();
  64. }
  65. }
  66. base.Dispose( disposing );
  67. }
  68. #region Windows 窗体设计器生成的代码
  69. /// <summary>
  70. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  71. /// 此方法的内容。
  72. /// </summary>
  73. private void InitializeComponent()
  74. {
  75. this.components = new System.ComponentModel.Container();
  76. System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(ClientDataManage));
  77. this.dgrd_ClientData = new System.Windows.Forms.DataGrid();
  78. this.label1 = new System.Windows.Forms.Label();
  79. this.txt_WareWord = new System.Windows.Forms.TextBox();
  80. this.btn_Search = new System.Windows.Forms.Button();
  81. this.groupBox1 = new System.Windows.Forms.GroupBox();
  82. this.toolBar1 = new System.Windows.Forms.ToolBar();
  83. this.tbarBtnSave = new System.Windows.Forms.ToolBarButton();
  84. this.tbarBtnDelete = new System.Windows.Forms.ToolBarButton();
  85. this.imageList1 = new System.Windows.Forms.ImageList(this.components);
  86. ((System.ComponentModel.ISupportInitialize)(this.dgrd_ClientData)).BeginInit();
  87. this.groupBox1.SuspendLayout();
  88. this.SuspendLayout();
  89. // 
  90. // dgrd_ClientData
  91. // 
  92. this.dgrd_ClientData.AllowSorting = false;
  93. this.dgrd_ClientData.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
  94. | System.Windows.Forms.AnchorStyles.Left) 
  95. | System.Windows.Forms.AnchorStyles.Right)));
  96. this.dgrd_ClientData.CaptionVisible = false;
  97. this.dgrd_ClientData.DataMember = "";
  98. this.dgrd_ClientData.HeaderForeColor = System.Drawing.SystemColors.ControlText;
  99. this.dgrd_ClientData.Location = new System.Drawing.Point(0, 74);
  100. this.dgrd_ClientData.Name = "dgrd_ClientData";
  101. this.dgrd_ClientData.Size = new System.Drawing.Size(720, 350);
  102. this.dgrd_ClientData.TabIndex = 3;
  103. this.dgrd_ClientData.DoubleClick += new System.EventHandler(this.dgrd_ClientData_DoubleClick);
  104. // 
  105. // label1
  106. // 
  107. this.label1.Location = new System.Drawing.Point(172, 19);
  108. this.label1.Name = "label1";
  109. this.label1.Size = new System.Drawing.Size(72, 16);
  110. this.label1.TabIndex = 14;
  111. this.label1.Text = "客户拼音:";
  112. // 
  113. // txt_WareWord
  114. // 
  115. this.txt_WareWord.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
  116. | System.Windows.Forms.AnchorStyles.Right)));
  117. this.txt_WareWord.Location = new System.Drawing.Point(259, 13);
  118. this.txt_WareWord.Name = "txt_WareWord";
  119. this.txt_WareWord.Size = new System.Drawing.Size(224, 21);
  120. this.txt_WareWord.TabIndex = 1;
  121. this.txt_WareWord.Text = "";
  122. // 
  123. // btn_Search
  124. // 
  125. this.btn_Search.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  126. this.btn_Search.Location = new System.Drawing.Point(499, 13);
  127. this.btn_Search.Name = "btn_Search";
  128. this.btn_Search.Size = new System.Drawing.Size(48, 24);
  129. this.btn_Search.TabIndex = 2;
  130. this.btn_Search.Text = "查询";
  131. this.btn_Search.Click += new System.EventHandler(this.btn_Search_Click);
  132. // 
  133. // groupBox1
  134. // 
  135. this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
  136. | System.Windows.Forms.AnchorStyles.Right)));
  137. this.groupBox1.Controls.Add(this.label1);
  138. this.groupBox1.Controls.Add(this.txt_WareWord);
  139. this.groupBox1.Controls.Add(this.btn_Search);
  140. this.groupBox1.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
  141. this.groupBox1.Location = new System.Drawing.Point(1, 23);
  142. this.groupBox1.Name = "groupBox1";
  143. this.groupBox1.Size = new System.Drawing.Size(718, 50);
  144. this.groupBox1.TabIndex = 15;
  145. this.groupBox1.TabStop = false;
  146. // 
  147. // toolBar1
  148. // 
  149. this.toolBar1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  150. this.toolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
  151. this.tbarBtnSave,
  152. this.tbarBtnDelete});
  153. this.toolBar1.DropDownArrows = true;
  154. this.toolBar1.ImageList = this.imageList1;
  155. this.toolBar1.Location = new System.Drawing.Point(0, 0);
  156. this.toolBar1.Name = "toolBar1";
  157. this.toolBar1.ShowToolTips = true;
  158. this.toolBar1.Size = new System.Drawing.Size(720, 29);
  159. this.toolBar1.TabIndex = 4;
  160. this.toolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar1_ButtonClick);
  161. // 
  162. // tbarBtnSave
  163. // 
  164. this.tbarBtnSave.ImageIndex = 0;
  165. this.tbarBtnSave.ToolTipText = "保存修改";
  166. // 
  167. // tbarBtnDelete
  168. // 
  169. this.tbarBtnDelete.ImageIndex = 1;
  170. this.tbarBtnDelete.ToolTipText = "删除数据";
  171. // 
  172. // imageList1
  173. // 
  174. this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
  175. this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
  176. this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
  177. // 
  178. // ClientDataManage
  179. // 
  180. this.AcceptButton = this.btn_Search;
  181. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  182. this.ClientSize = new System.Drawing.Size(720, 421);
  183. this.Controls.Add(this.toolBar1);
  184. this.Controls.Add(this.groupBox1);
  185. this.Controls.Add(this.dgrd_ClientData);
  186. this.Name = "ClientDataManage";
  187. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  188. this.Text = "【客户信息维护】";
  189. ((System.ComponentModel.ISupportInitialize)(this.dgrd_ClientData)).EndInit();
  190. this.groupBox1.ResumeLayout(false);
  191. this.ResumeLayout(false);
  192. }
  193. #endregion
  194. //------------根据用户的输入客户拼音编码来搜索客户信息----------
  195. private void btn_Search_Click(object sender, System.EventArgs e)
  196. {
  197. string strSpellWord = this.txt_WareWord.Text.Trim();
  198. string tempStrSQL = "select * from 客户清单 where 拼音编码 like '" + strSpellWord + "%'";
  199. this.link.SelectDataBase(tempStrSQL,sendTableName);
  200. }
  201. //--------------处理保存,删除,退出等事务---------------
  202. private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
  203. {
  204. if (e.Button.ToolTipText == "保存修改")
  205. {
  206. try
  207. {
  208. int row = this.dgrd_ClientData.CurrentCell.RowNumber;
  209. //将当前所在行往下移动一行,为便于实现同步保存
  210. //(否则会出现修改的最后一行无法保存,因为它还处于编辑状态)
  211. this.dgrd_ClientData.CurrentCell = new DataGridCell(row+1,0); 
  212. if (this.ds.HasChanges())
  213. {
  214. this.link.UpdateDataBase(this.ds.GetChanges(),sendTableName);
  215. MessageBox.Show("数据修改成功!","信息");
  216. }
  217. else
  218. {
  219. MessageBox.Show("没有修改的数据!");
  220. return;
  221. }
  222. }
  223. catch
  224. {
  225. MessageBox.Show("数据保存失败,请确认所有信息输入完整且正确!","提示");
  226. return;
  227. }
  228. }
  229. if (e.Button.ToolTipText == "删除数据")
  230. {
  231. if (MessageBox.Show("确实要删除这条记录吗?","询问",MessageBoxButtons.YesNo) == DialogResult.Yes)
  232. {
  233. int intRowNumber = this.dgrd_ClientData.CurrentCell.RowNumber;
  234. try
  235. {
  236. this.ds.Tables[0].Rows[intRowNumber].Delete();
  237. this.link.UpdateDataBase(this.ds.GetChanges(),sendTableName);
  238. MessageBox.Show("数据删除成功!","信息");
  239. }
  240. catch
  241. {
  242. MessageBox.Show("该数据不能删除!","提示");
  243. string tempStrSQL = "select * from " + sendTableName;
  244. this.link.SelectDataBase(tempStrSQL,sendTableName);
  245. return;
  246. }
  247. }
  248. }
  249. }
  250. //------------设置表格格式--------------
  251. private void DataGridStateControl(bool blReadonly)
  252. {
  253. DataGridTableStyle ts = new DataGridTableStyle();
  254. ts.AlternatingBackColor = Color.LightGray;
  255. ts.MappingName = this.ds.Tables[0].TableName;
  256. ts.AllowSorting = false;
  257. int numCols = this.ds.Tables[0].Columns.Count;
  258. for (int i = 0;i< numCols;i++)
  259. {
  260. if (blReadonly == true)
  261. {
  262. //生成下拉列表框的列
  263. if ( i == 3)
  264. {
  265. DataTable tempTable = new DataTable();
  266. tempTable = this.link.SelectDataBase("select 姓名 from 业务员清单");
  267. DataGridComboBoxColumn aComboBoxColumn = new DataGridComboBoxColumn(tempTable,0,0);
  268. aComboBoxColumn.MappingName = this.ds.Tables[0].Columns[i].ColumnName;
  269. aComboBoxColumn.HeaderText = this.ds.Tables[0].Columns[i].ColumnName;
  270. aComboBoxColumn.NullText = "";
  271. ts.GridColumnStyles.Add(aComboBoxColumn);
  272. }
  273. else
  274. {
  275. DataGridTextBoxColumn aColumnTextColumn = new DataGridTextBoxColumn();
  276. aColumnTextColumn.MappingName = this.ds.Tables[0].Columns[i].ColumnName;
  277. aColumnTextColumn.HeaderText = this.ds.Tables[0].Columns[i].ColumnName;
  278. aColumnTextColumn.NullText = "";
  279. aColumnTextColumn.Format = "F";
  280. ts.GridColumnStyles.Add(aColumnTextColumn);
  281. }
  282. }
  283. else
  284. {
  285. DataGridNoActiveCellColumn aColumnTextColumn = new DataGridNoActiveCellColumn();
  286. aColumnTextColumn.MappingName = this.ds.Tables[0].Columns[i].ColumnName;
  287. aColumnTextColumn.HeaderText = this.ds.Tables[0].Columns[i].ColumnName;
  288. aColumnTextColumn.NullText = "";
  289. aColumnTextColumn.Format = "F";
  290. ts.GridColumnStyles.Add(aColumnTextColumn);
  291. }
  292. }
  293. this.dgrd_ClientData.TableStyles.Add(ts);
  294. }
  295. //---------------其他窗体调用客户信息窗体,双击选择数据并回送--------------
  296. private void dgrd_ClientData_DoubleClick(object sender, System.EventArgs e)
  297. {
  298. if (this.dgrd_ClientData.ReadOnly == true) //判断如果是在销售单中生成的窗体则不响应DataGrid的双击事件
  299. {
  300. int intCurrentRowNumber = this.dgrd_ClientData.CurrentCell.RowNumber;
  301. string sendClientID,sendClientName;
  302. sendClientID = this.dgrd_ClientData[intCurrentRowNumber,0].ToString().Trim();
  303. sendClientName = this.dgrd_ClientData[intCurrentRowNumber,2].ToString().Trim();
  304. string [] sendArray = new string [] {sendClientID,sendClientName};
  305. SellTable.inputTextDataArray[0] = sendArray[0];
  306. SellTable.inputTextDataArray[1] = sendArray[1];
  307. this.Close();
  308. }
  309. }
  310. public void setDataGridReadOnly()
  311. {
  312. this.dgrd_ClientData.ReadOnly = true;
  313. }
  314. }
  315. }