StokerDataManage.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. /// StokerDataManage 的摘要说明。
  11. /// </summary>
  12. public class StokerDataManage : 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.GroupBox groupBox1;
  19. private System.Windows.Forms.Label label1;
  20. private System.Windows.Forms.TextBox txt_WareWord;
  21. private System.Windows.Forms.Button btn_Search;
  22. private System.Windows.Forms.ToolBar toolBar1;
  23. private System.Windows.Forms.ToolBarButton tbarBtnSave;
  24. private System.Windows.Forms.ImageList imageList1;
  25. private System.Windows.Forms.ToolBarButton tbarBtnDelete;
  26. private System.Windows.Forms.DataGrid dgrd_StockerData;
  27. private System.ComponentModel.IContainer components;
  28. public StokerDataManage()
  29. {
  30. //
  31. // Windows 窗体设计器支持所必需的
  32. //
  33. InitializeComponent();
  34. //
  35. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  36. //
  37. }
  38. //---------------重载构造函数-------------
  39. public StokerDataManage(bool blShowToolBar)
  40. {
  41. //
  42. // Windows 窗体设计器支持所必需的
  43. //
  44. InitializeComponent();
  45. //
  46. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  47. //
  48. this.ds = this.link.SelectDataBase(sendStrSQL,sendTableName);
  49. this.dgrd_StockerData.DataSource = ds;
  50. this.dgrd_StockerData.DataMember = sendTableName;
  51. //如果blToolBarShow为false,则表示该窗体使由销售单和进货单双击时生成
  52. this.DataGridStateControl(blShowToolBar); 
  53. this.toolBar1.Enabled = blShowToolBar;
  54. }
  55. /// <summary>
  56. /// 清理所有正在使用的资源。
  57. /// </summary>
  58. protected override void Dispose( bool disposing )
  59. {
  60. if( disposing )
  61. {
  62. if(components != null)
  63. {
  64. components.Dispose();
  65. }
  66. }
  67. base.Dispose( disposing );
  68. }
  69. #region Windows 窗体设计器生成的代码
  70. /// <summary>
  71. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  72. /// 此方法的内容。
  73. /// </summary>
  74. private void InitializeComponent()
  75. {
  76. this.components = new System.ComponentModel.Container();
  77. System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(StokerDataManage));
  78. this.dgrd_StockerData = new System.Windows.Forms.DataGrid();
  79. this.groupBox1 = new System.Windows.Forms.GroupBox();
  80. this.label1 = new System.Windows.Forms.Label();
  81. this.txt_WareWord = new System.Windows.Forms.TextBox();
  82. this.btn_Search = new System.Windows.Forms.Button();
  83. this.toolBar1 = new System.Windows.Forms.ToolBar();
  84. this.tbarBtnSave = new System.Windows.Forms.ToolBarButton();
  85. this.tbarBtnDelete = new System.Windows.Forms.ToolBarButton();
  86. this.imageList1 = new System.Windows.Forms.ImageList(this.components);
  87. ((System.ComponentModel.ISupportInitialize)(this.dgrd_StockerData)).BeginInit();
  88. this.groupBox1.SuspendLayout();
  89. this.SuspendLayout();
  90. // 
  91. // dgrd_StockerData
  92. // 
  93. this.dgrd_StockerData.AllowSorting = false;
  94. this.dgrd_StockerData.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
  95. | System.Windows.Forms.AnchorStyles.Left) 
  96. | System.Windows.Forms.AnchorStyles.Right)));
  97. this.dgrd_StockerData.CaptionVisible = false;
  98. this.dgrd_StockerData.DataMember = "";
  99. this.dgrd_StockerData.HeaderForeColor = System.Drawing.SystemColors.ControlText;
  100. this.dgrd_StockerData.Location = new System.Drawing.Point(0, 75);
  101. this.dgrd_StockerData.Name = "dgrd_StockerData";
  102. this.dgrd_StockerData.Size = new System.Drawing.Size(720, 349);
  103. this.dgrd_StockerData.TabIndex = 3;
  104. this.dgrd_StockerData.DoubleClick += new System.EventHandler(this.dgrd_StockerData_DoubleClick);
  105. // 
  106. // groupBox1
  107. // 
  108. this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
  109. | System.Windows.Forms.AnchorStyles.Right)));
  110. this.groupBox1.Controls.Add(this.label1);
  111. this.groupBox1.Controls.Add(this.txt_WareWord);
  112. this.groupBox1.Controls.Add(this.btn_Search);
  113. this.groupBox1.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
  114. this.groupBox1.Location = new System.Drawing.Point(1, 23);
  115. this.groupBox1.Name = "groupBox1";
  116. this.groupBox1.Size = new System.Drawing.Size(718, 50);
  117. this.groupBox1.TabIndex = 8;
  118. this.groupBox1.TabStop = false;
  119. // 
  120. // label1
  121. // 
  122. this.label1.Location = new System.Drawing.Point(154, 18);
  123. this.label1.Name = "label1";
  124. this.label1.Size = new System.Drawing.Size(72, 16);
  125. this.label1.TabIndex = 9;
  126. this.label1.Text = "供货商拼音:";
  127. // 
  128. // txt_WareWord
  129. // 
  130. this.txt_WareWord.Anchor = System.Windows.Forms.AnchorStyles.Top;
  131. this.txt_WareWord.Location = new System.Drawing.Point(245, 14);
  132. this.txt_WareWord.Name = "txt_WareWord";
  133. this.txt_WareWord.Size = new System.Drawing.Size(248, 21);
  134. this.txt_WareWord.TabIndex = 1;
  135. this.txt_WareWord.Text = "";
  136. // 
  137. // btn_Search
  138. // 
  139. this.btn_Search.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  140. this.btn_Search.Location = new System.Drawing.Point(517, 13);
  141. this.btn_Search.Name = "btn_Search";
  142. this.btn_Search.Size = new System.Drawing.Size(48, 24);
  143. this.btn_Search.TabIndex = 2;
  144. this.btn_Search.Text = "查询";
  145. this.btn_Search.Click += new System.EventHandler(this.btn_Search_Click);
  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 = 9;
  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. // StokerDataManage
  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_StockerData);
  186. this.Name = "StokerDataManage";
  187. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  188. this.Text = "【供货商信息维护】";
  189. ((System.ComponentModel.ISupportInitialize)(this.dgrd_StockerData)).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_StockerData.CurrentCell.RowNumber;
  209. //将当前所在行往下移动一行,为便于实现同步保存
  210. //(否则会出现修改的最后一行无法保存,因为它还处于编辑状态)
  211. this.dgrd_StockerData.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_StockerData.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. if ( i == 3)//设置【业务员】字段下拉列表框显示
  263. {
  264. DataTable tempTable = new DataTable();
  265. tempTable = this.link.SelectDataBase("select 姓名 from 业务员清单");
  266. DataGridComboBoxColumn aComboBoxColumn = new DataGridComboBoxColumn(tempTable,0,0);
  267. aComboBoxColumn.MappingName = this.ds.Tables[0].Columns[i].ColumnName;
  268. aComboBoxColumn.HeaderText = this.ds.Tables[0].Columns[i].ColumnName;
  269. aComboBoxColumn.NullText = "";
  270. ts.GridColumnStyles.Add(aComboBoxColumn);
  271. }
  272. else
  273. {
  274. DataGridTextBoxColumn aColumnTextColumn = new DataGridTextBoxColumn();
  275. aColumnTextColumn.MappingName = this.ds.Tables[0].Columns[i].ColumnName;
  276. aColumnTextColumn.HeaderText = this.ds.Tables[0].Columns[i].ColumnName;
  277. aColumnTextColumn.NullText = "";
  278. aColumnTextColumn.Format = "F";
  279. ts.GridColumnStyles.Add(aColumnTextColumn);
  280. }
  281. }
  282. else
  283. {
  284. DataGridNoActiveCellColumn aColumnTextColumn = new DataGridNoActiveCellColumn();
  285. aColumnTextColumn.MappingName = this.ds.Tables[0].Columns[i].ColumnName;
  286. aColumnTextColumn.HeaderText = this.ds.Tables[0].Columns[i].ColumnName;
  287. aColumnTextColumn.NullText = "";
  288. aColumnTextColumn.Format = "F";
  289. ts.GridColumnStyles.Add(aColumnTextColumn);
  290. }
  291. }
  292. this.dgrd_StockerData.TableStyles.Add(ts);
  293. }
  294. //----------其他窗体调用,双击选择供货商信息并回送到调用的窗体-------------
  295. private void dgrd_StockerData_DoubleClick(object sender, System.EventArgs e)
  296. {
  297. if (this.dgrd_StockerData.ReadOnly == true) //判断如果是在进货单中生成的窗体则不响应DataGrid的双击事件
  298. {
  299. int intCurrentRowNumber = this.dgrd_StockerData.CurrentCell.RowNumber;
  300. string sendStokerID,sendStokerName;
  301. sendStokerID = this.dgrd_StockerData[intCurrentRowNumber,0].ToString().Trim();
  302. sendStokerName = this.dgrd_StockerData[intCurrentRowNumber,2].ToString().Trim();
  303. string [] sendArray = new string [] {sendStokerID,sendStokerName};
  304. StockTable.inputTextDataArray[0] = sendArray[0];
  305. StockTable.inputTextDataArray[1] = sendArray[1];
  306. this.Close();
  307. }
  308. }
  309. public void setDataGridReadOnly()
  310. {
  311. this.dgrd_StockerData.ReadOnly = true;
  312. }
  313. }
  314. }