AddingRecordDialog.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Text.RegularExpressions;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. namespace PaintDotNet.Measuring
  13. {
  14. public partial class AddingRecordDialog : Form
  15. {
  16. private TextBox textBox1;
  17. private Button button1;
  18. private Label label2;
  19. private Label label1;
  20. /// <summary>
  21. /// 添加区分
  22. /// </summary>
  23. private int addComboboxitemKb;
  24. /// <summary>
  25. /// 下拉框项目
  26. /// </summary>
  27. public ArrayList dataList;
  28. public AddingRecordDialog(int addComboboxitemKb)
  29. {
  30. this.addComboboxitemKb = addComboboxitemKb;
  31. InitializeComponent();
  32. this.Text = PdnResources.GetString("Menu.addingrecord.Text");
  33. this.button1.Text = PdnResources.GetString("Menu.File.Save.Text");
  34. this.label1.Text = PdnResources.GetString("Menu.Recordname.Text") + ":";
  35. }
  36. private void InitializeComponent()
  37. {
  38. this.label1 = new System.Windows.Forms.Label();
  39. this.textBox1 = new System.Windows.Forms.TextBox();
  40. this.button1 = new System.Windows.Forms.Button();
  41. this.label2 = new System.Windows.Forms.Label();
  42. this.SuspendLayout();
  43. //
  44. // label1
  45. //
  46. this.label1.AutoSize = true;
  47. this.label1.ForeColor = System.Drawing.SystemColors.MenuText;
  48. this.label1.Location = new System.Drawing.Point(24, 22);
  49. this.label1.Name = "label1";
  50. this.label1.Size = new System.Drawing.Size(65, 12);
  51. this.label1.TabIndex = 0;
  52. this.label1.Text = "记录名称:";
  53. //
  54. // textBox1
  55. //
  56. this.textBox1.Location = new System.Drawing.Point(102, 18);
  57. this.textBox1.Name = "textBox1";
  58. this.textBox1.Size = new System.Drawing.Size(232, 21);
  59. this.textBox1.TabIndex = 1;
  60. this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox1_KeyPress);
  61. //
  62. // button1
  63. //
  64. this.button1.Location = new System.Drawing.Point(258, 80);
  65. this.button1.Name = "button1";
  66. this.button1.Size = new System.Drawing.Size(76, 25);
  67. this.button1.TabIndex = 2;
  68. this.button1.Text = "保存";
  69. this.button1.UseVisualStyleBackColor = true;
  70. this.button1.Click += new System.EventHandler(this.button1_Click);
  71. //
  72. // label2
  73. //
  74. this.label2.AutoSize = true;
  75. this.label2.ForeColor = System.Drawing.SystemColors.Window;
  76. this.label2.Location = new System.Drawing.Point(-1, 57);
  77. this.label2.Name = "label2";
  78. this.label2.Size = new System.Drawing.Size(353, 12);
  79. this.label2.TabIndex = 3;
  80. this.label2.Text = "----------------------------------------------------------";
  81. //
  82. // AddingRecordDialog
  83. //
  84. this.BackColor = System.Drawing.SystemColors.Control;
  85. this.ClientSize = new System.Drawing.Size(346, 115);
  86. this.Controls.Add(this.label2);
  87. this.Controls.Add(this.button1);
  88. this.Controls.Add(this.textBox1);
  89. this.Controls.Add(this.label1);
  90. this.MaximizeBox = false;
  91. this.MaximumSize = new System.Drawing.Size(362, 154);
  92. this.MinimizeBox = false;
  93. this.MinimumSize = new System.Drawing.Size(362, 154);
  94. this.Name = "AddingRecordDialog";
  95. this.ShowInTaskbar = false;
  96. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
  97. this.Text = "新增";
  98. this.TopMost = true;
  99. this.ResumeLayout(false);
  100. this.PerformLayout();
  101. }
  102. private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
  103. {
  104. if (((int)e.KeyChar < 48 || (int)e.KeyChar > 57) && (int)e.KeyChar != 8 && (int)e.KeyChar != 46)
  105. e.Handled = true;
  106. //小数点的处理
  107. if ((int)e.KeyChar == 46)
  108. {
  109. if (textBox1.Text.Length <= 0)
  110. e.Handled = true; //小数点不能在第一位
  111. else
  112. {
  113. float f;
  114. float oldf;
  115. bool b1 = false, b2 = false;
  116. b1 = float.TryParse(textBox1.Text, out oldf);
  117. b2 = float.TryParse(textBox1.Text + e.KeyChar.ToString(), out f);
  118. if (b2 == false)
  119. {
  120. if (b1 == true)
  121. e.Handled = true;
  122. else
  123. e.Handled = false;
  124. }
  125. }
  126. }
  127. }
  128. /// <summary>
  129. /// 添加按钮按下
  130. /// </summary>
  131. /// <param name="sender"></param>
  132. /// <param name="e"></param>
  133. private void button1_Click(object sender, EventArgs e)
  134. {
  135. if(string.IsNullOrEmpty(this.textBox1.Text))
  136. {
  137. MessageBox.Show(PdnResources.GetString("Menu.namecannotbeEmpty.text")+"!", PdnResources.GetString("Menu.alert.text"));
  138. return;
  139. }
  140. if(this.dataList != null && this.dataList.Contains(new System.Collections.DictionaryEntry(Convert.ToDecimal(this.textBox1.Text), this.textBox1.Text + "X")))
  141. {
  142. MessageBox.Show(PdnResources.GetString("Menu.Alreadyexists.Text")+"!", PdnResources.GetString("Menu.alert.text"));
  143. }
  144. else
  145. {
  146. TheoreticalScaleDialog.addComboboxitem = new System.Collections.DictionaryEntry(Convert.ToDecimal(this.textBox1.Text), this.textBox1.Text + "X");
  147. TheoreticalScaleDialog.addComboboxitemKb = this.addComboboxitemKb;
  148. TheoreticalScaleDialog theoreticalScaleDialog = (TheoreticalScaleDialog)this.Owner;
  149. theoreticalScaleDialog.RefreshListView();
  150. this.Close();
  151. }
  152. }
  153. }
  154. }