CreateProjectDialog.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. using PaintDotNet.Base.CommTool;
  2. using PaintDotNet.Base.Functionodel;
  3. using PaintDotNet.Base.SettingModel;
  4. using PaintDotNet.CustomControl;
  5. using PaintDotNet.DbOpreate.DbBll;
  6. using PaintDotNet.DbOpreate.DbModel;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.ComponentModel;
  10. using System.Data;
  11. using System.Drawing;
  12. using System.IO;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Threading.Tasks;
  16. using System.Windows.Forms;
  17. using static PaintDotNet.Base.Functionodel.AnalyzeSettingModel;
  18. namespace PaintDotNet.Instrument
  19. {
  20. public partial class CreateProjectDialog : PdnBaseForm
  21. {
  22. #region 控件
  23. private GroupBox groupBox1;
  24. private Button button2;
  25. private Button button1;
  26. private GroupBox groupBox6;
  27. private DataGridView dataGridView1;
  28. private TextBox textBox9;
  29. private Label label14;
  30. private TextBox textBox8;
  31. private Label label13;
  32. private Button button4;
  33. private GroupBox groupBox5;
  34. private DateTimePicker dateTimePicker2;
  35. private Label label12;
  36. private TextBox textBox6;
  37. private Label label11;
  38. private TextBox textBox5;
  39. private Label label10;
  40. private TextBox textBox4;
  41. private Label label9;
  42. private GroupBox groupBox4;
  43. private DateTimePicker dateTimePicker1;
  44. private TextBox textBox2;
  45. private Label label8;
  46. private Label label7;
  47. #endregion
  48. /// <summary>
  49. /// 数据
  50. /// </summary>
  51. public AnalyzeSettingModel model;
  52. /// <summary>
  53. /// 父窗口
  54. /// </summary>
  55. public PdnBaseForm pdnBaseForm;
  56. /// <summary>
  57. /// 上级id
  58. /// </summary>
  59. public int parentId;
  60. public CreateProjectDialog(PdnBaseForm pdnBaseForm)
  61. {
  62. this.pdnBaseForm = pdnBaseForm;
  63. this.model = new AnalyzeSettingModel();
  64. InitializeComponent();
  65. InitializeLanguageText();
  66. InitGridHeader();
  67. InitializeModelData();
  68. }
  69. private void InitializeLanguageText()
  70. {
  71. this.groupBox1.Text = PdnResources.GetString("Menu.operation.text");
  72. this.button2.Text = PdnResources.GetString("Menu.File.Save.Text");
  73. this.button1.Text = PdnResources.GetString("Menu.File.Close.Text");
  74. this.groupBox6.Text = PdnResources.GetString("Menu.other.text");
  75. this.label14.Text = PdnResources.GetString("Menu.name.text") + ":";
  76. this.label13.Text = PdnResources.GetString("Menu.content.text") + ":";
  77. this.button4.Text = PdnResources.GetString("Menu.Addto.text");
  78. this.groupBox5.Text = PdnResources.GetString("Menu.Inspectioninformation.text");
  79. this.label12.Text = PdnResources.GetString("Menu.Inspectiondate.text") + ":";
  80. this.label11.Text = PdnResources.GetString("Menu.Contactperson.text") + ":";
  81. this.label10.Text = PdnResources.GetString("Menu.inspectiondepartment.text") + ":";
  82. this.label9.Text = PdnResources.GetString("Menu.Sender.text") + ":";
  83. this.groupBox4.Text = PdnResources.GetString("Menu.thebasicinformationofproject.text");
  84. this.label8.Text = PdnResources.GetString("Menu.projectnumber.text") + ":";
  85. this.label7.Text = PdnResources.GetString("Menu.Ratingdate.text") + ":";
  86. }
  87. private void InitializeComponent()
  88. {
  89. this.groupBox1 = new System.Windows.Forms.GroupBox();
  90. this.button2 = new System.Windows.Forms.Button();
  91. this.button1 = new System.Windows.Forms.Button();
  92. this.groupBox6 = new System.Windows.Forms.GroupBox();
  93. this.dataGridView1 = new System.Windows.Forms.DataGridView();
  94. this.textBox9 = new System.Windows.Forms.TextBox();
  95. this.label14 = new System.Windows.Forms.Label();
  96. this.textBox8 = new System.Windows.Forms.TextBox();
  97. this.label13 = new System.Windows.Forms.Label();
  98. this.button4 = new System.Windows.Forms.Button();
  99. this.groupBox5 = new System.Windows.Forms.GroupBox();
  100. this.dateTimePicker2 = new System.Windows.Forms.DateTimePicker();
  101. this.label12 = new System.Windows.Forms.Label();
  102. this.textBox6 = new System.Windows.Forms.TextBox();
  103. this.label11 = new System.Windows.Forms.Label();
  104. this.textBox5 = new System.Windows.Forms.TextBox();
  105. this.label10 = new System.Windows.Forms.Label();
  106. this.textBox4 = new System.Windows.Forms.TextBox();
  107. this.label9 = new System.Windows.Forms.Label();
  108. this.groupBox4 = new System.Windows.Forms.GroupBox();
  109. this.dateTimePicker1 = new System.Windows.Forms.DateTimePicker();
  110. this.textBox2 = new System.Windows.Forms.TextBox();
  111. this.label8 = new System.Windows.Forms.Label();
  112. this.label7 = new System.Windows.Forms.Label();
  113. this.groupBox1.SuspendLayout();
  114. this.groupBox6.SuspendLayout();
  115. ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
  116. this.groupBox5.SuspendLayout();
  117. this.groupBox4.SuspendLayout();
  118. this.SuspendLayout();
  119. //
  120. // groupBox1
  121. //
  122. this.groupBox1.Controls.Add(this.button2);
  123. this.groupBox1.Controls.Add(this.button1);
  124. this.groupBox1.Location = new System.Drawing.Point(12, 12);
  125. this.groupBox1.Name = "groupBox1";
  126. this.groupBox1.Size = new System.Drawing.Size(542, 49);
  127. this.groupBox1.TabIndex = 1;
  128. this.groupBox1.TabStop = false;
  129. this.groupBox1.Text = "操作";
  130. //
  131. // button2
  132. //
  133. this.button2.BackColor = System.Drawing.SystemColors.Control;
  134. this.button2.Location = new System.Drawing.Point(460, 12);
  135. this.button2.Name = "button2";
  136. this.button2.Size = new System.Drawing.Size(76, 30);
  137. this.button2.TabIndex = 1;
  138. this.button2.Text = "保存";
  139. this.button2.UseVisualStyleBackColor = false;
  140. this.button2.Click += new System.EventHandler(this.button2_Click);
  141. //
  142. // button1
  143. //
  144. this.button1.BackColor = System.Drawing.SystemColors.Control;
  145. this.button1.Location = new System.Drawing.Point(378, 13);
  146. this.button1.Name = "button1";
  147. this.button1.Size = new System.Drawing.Size(76, 30);
  148. this.button1.TabIndex = 0;
  149. this.button1.Text = "关闭";
  150. this.button1.UseVisualStyleBackColor = false;
  151. this.button1.Click += new System.EventHandler(this.button1_Click);
  152. //
  153. // groupBox6
  154. //
  155. this.groupBox6.Controls.Add(this.dataGridView1);
  156. this.groupBox6.Controls.Add(this.textBox9);
  157. this.groupBox6.Controls.Add(this.label14);
  158. this.groupBox6.Controls.Add(this.textBox8);
  159. this.groupBox6.Controls.Add(this.label13);
  160. this.groupBox6.Controls.Add(this.button4);
  161. this.groupBox6.Location = new System.Drawing.Point(12, 220);
  162. this.groupBox6.Name = "groupBox6";
  163. this.groupBox6.Size = new System.Drawing.Size(542, 226);
  164. this.groupBox6.TabIndex = 2;
  165. this.groupBox6.TabStop = false;
  166. this.groupBox6.Text = "其他";
  167. //
  168. // dataGridView1
  169. //
  170. this.dataGridView1.AllowUserToAddRows = false;
  171. this.dataGridView1.AllowUserToDeleteRows = false;
  172. this.dataGridView1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
  173. | System.Windows.Forms.AnchorStyles.Right)));
  174. this.dataGridView1.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
  175. this.dataGridView1.BackgroundColor = System.Drawing.Color.White;
  176. this.dataGridView1.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.None;
  177. this.dataGridView1.Location = new System.Drawing.Point(16, 68);
  178. this.dataGridView1.MultiSelect = false;
  179. this.dataGridView1.Name = "dataGridView1";
  180. this.dataGridView1.RowHeadersVisible = false;
  181. this.dataGridView1.RowTemplate.Height = 23;
  182. this.dataGridView1.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
  183. this.dataGridView1.Size = new System.Drawing.Size(511, 148);
  184. this.dataGridView1.TabIndex = 19;
  185. this.dataGridView1.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellContentClick);
  186. //
  187. // textBox9
  188. //
  189. this.textBox9.Location = new System.Drawing.Point(55, 30);
  190. this.textBox9.Name = "textBox9";
  191. this.textBox9.Size = new System.Drawing.Size(165, 21);
  192. this.textBox9.TabIndex = 18;
  193. //
  194. // label14
  195. //
  196. this.label14.AutoSize = true;
  197. this.label14.ForeColor = System.Drawing.SystemColors.ControlText;
  198. this.label14.Location = new System.Drawing.Point(14, 34);
  199. this.label14.Name = "label14";
  200. this.label14.Size = new System.Drawing.Size(41, 12);
  201. this.label14.TabIndex = 17;
  202. this.label14.Text = "名称:";
  203. //
  204. // textBox8
  205. //
  206. this.textBox8.Location = new System.Drawing.Point(268, 30);
  207. this.textBox8.Name = "textBox8";
  208. this.textBox8.Size = new System.Drawing.Size(165, 21);
  209. this.textBox8.TabIndex = 16;
  210. //
  211. // label13
  212. //
  213. this.label13.AutoSize = true;
  214. this.label13.ForeColor = System.Drawing.SystemColors.ControlText;
  215. this.label13.Location = new System.Drawing.Point(228, 34);
  216. this.label13.Name = "label13";
  217. this.label13.Size = new System.Drawing.Size(41, 12);
  218. this.label13.TabIndex = 15;
  219. this.label13.Text = "内容:";
  220. //
  221. // button4
  222. //
  223. this.button4.BackColor = System.Drawing.SystemColors.Control;
  224. this.button4.Location = new System.Drawing.Point(451, 25);
  225. this.button4.Name = "button4";
  226. this.button4.Size = new System.Drawing.Size(76, 30);
  227. this.button4.TabIndex = 2;
  228. this.button4.Text = "添加";
  229. this.button4.UseVisualStyleBackColor = false;
  230. this.button4.Click += new System.EventHandler(this.button4_Click);
  231. //
  232. // groupBox5
  233. //
  234. this.groupBox5.Controls.Add(this.dateTimePicker2);
  235. this.groupBox5.Controls.Add(this.label12);
  236. this.groupBox5.Controls.Add(this.textBox6);
  237. this.groupBox5.Controls.Add(this.label11);
  238. this.groupBox5.Controls.Add(this.textBox5);
  239. this.groupBox5.Controls.Add(this.label10);
  240. this.groupBox5.Controls.Add(this.textBox4);
  241. this.groupBox5.Controls.Add(this.label9);
  242. this.groupBox5.Location = new System.Drawing.Point(12, 128);
  243. this.groupBox5.Name = "groupBox5";
  244. this.groupBox5.Size = new System.Drawing.Size(542, 90);
  245. this.groupBox5.TabIndex = 3;
  246. this.groupBox5.TabStop = false;
  247. this.groupBox5.Text = "送检信息";
  248. //
  249. // dateTimePicker2
  250. //
  251. this.dateTimePicker2.Location = new System.Drawing.Point(346, 58);
  252. this.dateTimePicker2.Name = "dateTimePicker2";
  253. this.dateTimePicker2.Size = new System.Drawing.Size(165, 21);
  254. this.dateTimePicker2.TabIndex = 14;
  255. //
  256. // label12
  257. //
  258. this.label12.AutoSize = true;
  259. this.label12.ForeColor = System.Drawing.SystemColors.ControlText;
  260. this.label12.Location = new System.Drawing.Point(283, 62);
  261. this.label12.Name = "label12";
  262. this.label12.Size = new System.Drawing.Size(65, 12);
  263. this.label12.TabIndex = 13;
  264. this.label12.Text = "送检日期:";
  265. //
  266. // textBox6
  267. //
  268. this.textBox6.Location = new System.Drawing.Point(346, 23);
  269. this.textBox6.Name = "textBox6";
  270. this.textBox6.Size = new System.Drawing.Size(165, 21);
  271. this.textBox6.TabIndex = 12;
  272. //
  273. // label11
  274. //
  275. this.label11.AutoSize = true;
  276. this.label11.ForeColor = System.Drawing.SystemColors.ControlText;
  277. this.label11.Location = new System.Drawing.Point(283, 28);
  278. this.label11.Name = "label11";
  279. this.label11.Size = new System.Drawing.Size(53, 12);
  280. this.label11.TabIndex = 11;
  281. this.label11.Text = "联系人:";
  282. //
  283. // textBox5
  284. //
  285. this.textBox5.Location = new System.Drawing.Point(92, 58);
  286. this.textBox5.Name = "textBox5";
  287. this.textBox5.Size = new System.Drawing.Size(165, 21);
  288. this.textBox5.TabIndex = 10;
  289. //
  290. // label10
  291. //
  292. this.label10.AutoSize = true;
  293. this.label10.ForeColor = System.Drawing.SystemColors.ControlText;
  294. this.label10.Location = new System.Drawing.Point(30, 62);
  295. this.label10.Name = "label10";
  296. this.label10.Size = new System.Drawing.Size(65, 12);
  297. this.label10.TabIndex = 9;
  298. this.label10.Text = "送检单位:";
  299. //
  300. // textBox4
  301. //
  302. this.textBox4.Location = new System.Drawing.Point(92, 23);
  303. this.textBox4.Name = "textBox4";
  304. this.textBox4.Size = new System.Drawing.Size(165, 21);
  305. this.textBox4.TabIndex = 8;
  306. //
  307. // label9
  308. //
  309. this.label9.AutoSize = true;
  310. this.label9.ForeColor = System.Drawing.SystemColors.ControlText;
  311. this.label9.Location = new System.Drawing.Point(30, 28);
  312. this.label9.Name = "label9";
  313. this.label9.Size = new System.Drawing.Size(53, 12);
  314. this.label9.TabIndex = 7;
  315. this.label9.Text = "送检人:";
  316. //
  317. // groupBox4
  318. //
  319. this.groupBox4.Controls.Add(this.dateTimePicker1);
  320. this.groupBox4.Controls.Add(this.textBox2);
  321. this.groupBox4.Controls.Add(this.label8);
  322. this.groupBox4.Controls.Add(this.label7);
  323. this.groupBox4.Location = new System.Drawing.Point(12, 67);
  324. this.groupBox4.Name = "groupBox4";
  325. this.groupBox4.Size = new System.Drawing.Size(542, 60);
  326. this.groupBox4.TabIndex = 4;
  327. this.groupBox4.TabStop = false;
  328. this.groupBox4.Text = "项目基本信息";
  329. //
  330. // dateTimePicker1
  331. //
  332. this.dateTimePicker1.Location = new System.Drawing.Point(346, 24);
  333. this.dateTimePicker1.Name = "dateTimePicker1";
  334. this.dateTimePicker1.Size = new System.Drawing.Size(165, 21);
  335. this.dateTimePicker1.TabIndex = 6;
  336. //
  337. // textBox2
  338. //
  339. this.textBox2.Location = new System.Drawing.Point(92, 24);
  340. this.textBox2.Name = "textBox2";
  341. this.textBox2.Size = new System.Drawing.Size(165, 21);
  342. this.textBox2.TabIndex = 5;
  343. //
  344. // label8
  345. //
  346. this.label8.AutoSize = true;
  347. this.label8.ForeColor = System.Drawing.SystemColors.ControlText;
  348. this.label8.Location = new System.Drawing.Point(30, 28);
  349. this.label8.Name = "label8";
  350. this.label8.Size = new System.Drawing.Size(65, 12);
  351. this.label8.TabIndex = 4;
  352. this.label8.Text = "项目编号:";
  353. //
  354. // label7
  355. //
  356. this.label7.AutoSize = true;
  357. this.label7.ForeColor = System.Drawing.SystemColors.ControlText;
  358. this.label7.Location = new System.Drawing.Point(283, 28);
  359. this.label7.Name = "label7";
  360. this.label7.Size = new System.Drawing.Size(65, 12);
  361. this.label7.TabIndex = 3;
  362. this.label7.Text = "评级日期:";
  363. //
  364. // CreateProjectDialog
  365. //
  366. this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
  367. this.ClientSize = new System.Drawing.Size(567, 458);
  368. this.Controls.Add(this.groupBox6);
  369. this.Controls.Add(this.groupBox5);
  370. this.Controls.Add(this.groupBox4);
  371. this.Controls.Add(this.groupBox1);
  372. this.Name = "CreateProjectDialog";
  373. this.Text = "新建项目";
  374. this.Controls.SetChildIndex(this.groupBox1, 0);
  375. this.Controls.SetChildIndex(this.groupBox4, 0);
  376. this.Controls.SetChildIndex(this.groupBox5, 0);
  377. this.Controls.SetChildIndex(this.groupBox6, 0);
  378. this.groupBox1.ResumeLayout(false);
  379. this.groupBox6.ResumeLayout(false);
  380. this.groupBox6.PerformLayout();
  381. ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
  382. this.groupBox5.ResumeLayout(false);
  383. this.groupBox5.PerformLayout();
  384. this.groupBox4.ResumeLayout(false);
  385. this.groupBox4.PerformLayout();
  386. this.ResumeLayout(false);
  387. }
  388. /// <summary>
  389. /// 初始化数据,主要是初始化项目编号
  390. /// </summary>
  391. private void InitializeModelData()
  392. {
  393. int num = Startup.instance.configModel.ProjectCodeNum;
  394. int addNum = 1000000 + num;
  395. String code = "P" + addNum;
  396. this.textBox2.Text = code;
  397. }
  398. private void button1_Click(object sender, EventArgs e)
  399. {
  400. this.Close();
  401. }
  402. private void button2_Click(object sender, EventArgs e)
  403. {
  404. //先给主model赋值
  405. model.itemNumber = this.textBox2.Text;
  406. model.ratingDate = this.dateTimePicker1.Value;
  407. model.inspectionPerson = this.textBox4.Text;
  408. model.contact = this.textBox6.Text;
  409. model.inspectionDepartment = this.textBox5.Text;
  410. model.inspectionDate = this.dateTimePicker2.Value;
  411. //进行各种判断
  412. if (string.IsNullOrEmpty(model.itemNumber))
  413. {
  414. MessageBox.Show(PdnResources.GetString("Menu.leaseentertheprojectnumb.Text"));
  415. return;
  416. }
  417. //给下方list赋值
  418. if (this.dataGridView1.Rows.Count > 0)
  419. {
  420. model.otherList = new List<AnalyzeSettingModel.OthersInfo>();
  421. foreach (DataGridViewRow rowData in this.dataGridView1.Rows)
  422. {
  423. OthersInfo othersInfo = new OthersInfo();
  424. othersInfo.name = rowData.Cells[0].Value.ToString();
  425. othersInfo.content = rowData.Cells[1].Value.ToString();
  426. model.otherList.Add(othersInfo);
  427. }
  428. }
  429. //写入到数据库,判断编号是否重复
  430. mic_project temp = mic_project_BLL.FindItenByNameAndParentId(model.itemNumber, this.parentId);
  431. if(temp!=null)
  432. {
  433. MessageBox.Show("已经存在同名项目或文件夹");
  434. return;
  435. }
  436. //添加到数据库
  437. mic_project project = new mic_project();
  438. project.parent_id = this.parentId;
  439. project.project_name = model.itemNumber;
  440. //project.project_path = newPath;
  441. project.project_type = 4;
  442. mic_project_BLL.Add(project);
  443. mic_project_info info = new mic_project_info();
  444. info.project_code = model.itemNumber;
  445. info.project_company = model.inspectionDepartment;
  446. info.project_contact = model.contact;
  447. info.project_date = model.inspectionDate;
  448. info.project_id = project.id;
  449. info.project_rating = model.ratingDate;
  450. info.project_sender = model.inspectionPerson;
  451. mic_project_info_BLL.Add(info);
  452. if (model.otherList!=null && model.otherList.Count>0)
  453. {
  454. foreach (OthersInfo child in model.otherList)
  455. {
  456. mic_project_info_item item = new mic_project_info_item();
  457. item.info_id = info.id;
  458. item.item_key = child.name;
  459. item.item_value = child.content;
  460. mic_project_info_item_BLL.Add(item);
  461. }
  462. }
  463. //增加项目编号,到配置文件
  464. Startup.instance.configModel.ProjectCodeNum += 1;
  465. string configXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(Startup.instance.configModel);
  466. string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml";
  467. FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create);
  468. //调用父窗口方法,进行文件夹创建
  469. this.pdnBaseForm.CreateProjectName(model, project.id);
  470. }
  471. /// <summary>
  472. /// 添加按钮-其他
  473. /// </summary>
  474. /// <param name="sender"></param>
  475. /// <param name="e"></param>
  476. private void button4_Click(object sender, EventArgs e)
  477. {
  478. if (string.IsNullOrEmpty(this.textBox9.Text))
  479. {
  480. MessageBox.Show(PdnResources.GetString("Menu.Pleaseenteranameofthephase.text"));
  481. return;
  482. }
  483. if (string.IsNullOrEmpty(this.textBox8.Text))
  484. {
  485. MessageBox.Show(PdnResources.GetString("Menu.Pleaseentercontent.text"));
  486. return;
  487. }
  488. DataGridViewRow row = new DataGridViewRow();
  489. row.Cells.Add(CreateTextBoxCell(this.textBox9.Text, "name"));
  490. row.Cells.Add(CreateTextBoxCell(this.textBox8.Text, "content"));
  491. row.Cells.Add(CreateButtonCell(PdnResources.GetString("Menu.Edit.Delete.Text"), "delete"));
  492. this.dataGridView1.Rows.Add(row);
  493. //选中最新添加的那一条
  494. this.dataGridView1.ClearSelection();
  495. this.dataGridView1.Rows[this.dataGridView1.Rows.Count - 1].Selected = true;
  496. //清空输入框
  497. this.textBox9.Text = "";
  498. this.textBox8.Text = "";
  499. }
  500. /// <summary>
  501. /// 添加内容单元格
  502. /// </summary>
  503. /// <param name="text"></param>
  504. /// <param name="tag"></param>
  505. /// <returns></returns>
  506. private DataGridViewTextBoxCell CreateTextBoxCell(string text, object tag)
  507. {
  508. DataGridViewTextBoxCell textboxcell = new DataGridViewTextBoxCell();
  509. textboxcell.Value = text;
  510. textboxcell.Tag = tag;
  511. return textboxcell;
  512. }
  513. /// <summary>
  514. /// 添加按钮单元格
  515. /// </summary>
  516. /// <param name="text"></param>
  517. /// <param name="tag"></param>
  518. /// <returns></returns>
  519. public DataGridViewButtonCell CreateButtonCell(string text, object tag)
  520. {
  521. DataGridViewButtonCell buttonCell = new DataGridViewButtonCell();
  522. buttonCell.Value = text;
  523. buttonCell.Tag = tag;
  524. return buttonCell;
  525. }
  526. /// <summary>
  527. /// 点击datagridview的删除按钮
  528. /// </summary>
  529. /// <param name="sender"></param>
  530. /// <param name="e"></param>
  531. private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
  532. {
  533. var senderGrid = (DataGridView)sender;
  534. if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn &&
  535. e.RowIndex >= 0)
  536. this.dataGridView1.Rows.Remove(this.dataGridView1.Rows[e.RowIndex]);
  537. }
  538. /// <summary>
  539. /// 初始化表头
  540. /// </summary>
  541. private void InitGridHeader()
  542. {
  543. this.dataGridView1.ColumnHeadersHeight = 25;
  544. DataGridViewTextBoxColumn h1 = new DataGridViewTextBoxColumn();
  545. h1.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
  546. h1.Width = 200;
  547. DataGridViewTextBoxColumn h2 = new DataGridViewTextBoxColumn();
  548. h2.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
  549. h2.Width = 200;
  550. DataGridViewButtonColumn h3 = new DataGridViewButtonColumn();
  551. h3.Width = 90;
  552. this.dataGridView1.Columns.Add(h1);
  553. this.dataGridView1.Columns.Add(h2);
  554. this.dataGridView1.Columns.Add(h3);
  555. DataGridViewHelper helper = new DataGridViewHelper(this.dataGridView1);
  556. helper.Headers.Add(new DataGridViewHelper.TopHeader(0, 1, PdnResources.GetString("Menu.name.text")));
  557. helper.Headers.Add(new DataGridViewHelper.TopHeader(1, 1, PdnResources.GetString("Menu.content.text")));
  558. helper.Headers.Add(new DataGridViewHelper.TopHeader(2, 1, PdnResources.GetString("Menu.operation.text")));
  559. this.dataGridView1.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
  560. this.dataGridView1.Columns[0].ReadOnly = true;
  561. this.dataGridView1.Columns[1].SortMode = DataGridViewColumnSortMode.NotSortable;
  562. this.dataGridView1.Columns[1].ReadOnly = true;
  563. this.dataGridView1.AllowUserToResizeRows = false;
  564. this.dataGridView1.AllowUserToResizeColumns = false;
  565. }
  566. }
  567. }