CustomManage.xaml.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Data;
  8. using System.Windows.Documents;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Imaging;
  12. using System.Windows.Shapes;
  13. using System.Data;
  14. using System.Data.SqlClient;
  15. namespace AGV_WPF
  16. {
  17. /// <summary>
  18. /// CustomManage.xaml 的交互逻辑
  19. /// CustomType: 1-地标功能 2-运行状态(不超过0x40;因为0x40:运行 0x41:暂停 0x42:结束地标停止)
  20. /// </summary>
  21. public partial class CustomManage : Window
  22. {
  23. public DAL.ZSql sql1 = new DAL.ZSql();
  24. public int iCustomType = 1;
  25. /// <summary>
  26. /// 自定义页面构造函数,加载表格数据
  27. /// </summary>
  28. public CustomManage()
  29. {
  30. InitializeComponent();
  31. LoadDataGrid();
  32. }
  33. /// <summary>
  34. /// 加载表格设置
  35. /// </summary>
  36. private void LoadDataGrid()
  37. {
  38. DAL.ZSql sql2 = new DAL.ZSql();
  39. sql2.Open("select * from T_Custom where CustomType=" + iCustomType.ToString() + " and CmdNum>0 order by CmdNum");
  40. dataGrid1.ItemsSource = sql2.m_table.DefaultView;
  41. sql2.Close();
  42. }
  43. /// <summary>
  44. /// 表格选择不同行消息触发
  45. /// </summary>
  46. /// <param name="sender"></param>
  47. /// <param name="e"></param>
  48. private void dataGrid1_SelectionChanged(object sender, SelectionChangedEventArgs e)
  49. {
  50. DataRowView selectItem = dataGrid1.SelectedItem as DataRowView;
  51. if (selectItem != null)
  52. {
  53. tbCmdNum.Text = selectItem["CmdNum"].ToString().Trim();
  54. tbCmdFunction.Text = selectItem["CmdFunction"].ToString().Trim();
  55. }
  56. else
  57. {
  58. tbCmdNum.Text = "";
  59. tbCmdFunction.Text = "";
  60. }
  61. }
  62. /// <summary>
  63. /// 添加按钮消息响应
  64. /// </summary>
  65. /// <param name="sender"></param>
  66. /// <param name="e"></param>
  67. private void btnAdd_Click(object sender, RoutedEventArgs e)
  68. {
  69. string strcmdnum = tbCmdNum.Text.ToString().Trim();
  70. string strcmdfunction = tbCmdFunction.Text.ToString().Trim();
  71. if (string.IsNullOrEmpty(strcmdnum) || string.IsNullOrEmpty(strcmdfunction))
  72. {
  73. MessageBox.Show("对不起,请同时输入指令和指令功能!");
  74. return;
  75. }
  76. if (Convert.ToInt16(strcmdnum) <= 0 || Convert.ToInt16(strcmdnum) >= 64)
  77. {
  78. MessageBox.Show("对不起,请输入指令必须大于0小于64!");
  79. return;
  80. }
  81. sql1.Open("select * from T_Custom where CmdFunction='" + strcmdfunction + "' and CustomType=" + iCustomType.ToString());
  82. if (sql1.Rows.Count > 0)
  83. {
  84. MessageBox.Show("此功能已经存在!");
  85. return;
  86. }
  87. else
  88. {
  89. sql1.Open("SELECT MAX(CmdNum) AS MaxNum FROM T_Custom where CustomType=" + iCustomType.ToString());
  90. if (sql1.Rows.Count > 0)
  91. {
  92. if (!string.IsNullOrEmpty(sql1.Rows[0]["MaxNum"].ToString()))
  93. {
  94. if ((Convert.ToInt32(sql1.Rows[0]["MaxNum"]) + 1) < Convert.ToInt32(strcmdnum))
  95. {
  96. MessageBox.Show("对不起,请按顺序输入指令!");
  97. return;
  98. }
  99. }
  100. }
  101. sql1.Open("update T_Custom set CmdNum=CmdNum+1 from T_Custom where CustomType=" + iCustomType.ToString() +" and CmdNum>=" +strcmdnum);
  102. sql1.Open("insert into T_Custom (CmdFunction,CmdNum,CustomType) Values ('" + strcmdfunction + "'," + strcmdnum +","+ iCustomType.ToString() +")" );
  103. MessageBox.Show("添加指令成功!");
  104. }
  105. sql1.Close();
  106. LoadDataGrid();
  107. tbCmdNum.Text = (Convert.ToInt32(strcmdnum) + 1).ToString();
  108. }
  109. /// <summary>
  110. /// 修改按钮消息响应
  111. /// </summary>
  112. /// <param name="sender"></param>
  113. /// <param name="e"></param>
  114. private void btnModify_Click(object sender, RoutedEventArgs e)
  115. {
  116. string strcmdnum = tbCmdNum.Text.ToString().Trim();
  117. string strcmdfunction = tbCmdFunction.Text.ToString().Trim();
  118. if (string.IsNullOrEmpty(strcmdnum) || string.IsNullOrEmpty(strcmdfunction))
  119. {
  120. MessageBox.Show("对不起,请同时输入指令和指令功能!");
  121. return;
  122. }
  123. sql1.Open("select * from T_Custom where CmdNum=" + strcmdnum + " and CustomType=" + iCustomType.ToString());
  124. if (sql1.Rows.Count == 0)
  125. {
  126. MessageBox.Show("此指令不存在!");
  127. return;
  128. }
  129. sql1.Open("select * from T_Custom where CmdFunction='" + strcmdfunction + "' and CustomType=" + iCustomType.ToString());
  130. if (sql1.Rows.Count > 0)
  131. {
  132. MessageBox.Show("此功能已经存在!");
  133. return;
  134. }
  135. sql1.Open("update T_Custom set CmdFunction='" + strcmdfunction + "' where CmdNum=" + strcmdnum + " and CustomType=" + iCustomType.ToString());
  136. MessageBox.Show("修改指令成功!");
  137. sql1.Close();
  138. LoadDataGrid();
  139. }
  140. /// <summary>
  141. /// 删除按钮消息响应
  142. /// </summary>
  143. /// <param name="sender"></param>
  144. /// <param name="e"></param>
  145. private void btnDelete_Click(object sender, RoutedEventArgs e)
  146. {
  147. string strcmdnum = tbCmdNum.Text.ToString().Trim();
  148. if (string.IsNullOrEmpty(strcmdnum))
  149. {
  150. MessageBox.Show("对不起,请选择删除指令!");
  151. return;
  152. }
  153. sql1.Open("select * from T_Custom where CmdNum=" + strcmdnum + " and CustomType=" + iCustomType.ToString());
  154. if (sql1.Rows.Count == 0)
  155. {
  156. MessageBox.Show("此指令不存在!");
  157. return;
  158. }
  159. else
  160. {
  161. sql1.Open("delete from T_Custom" + " where CmdNum=" + strcmdnum + " and CustomType=" + iCustomType.ToString());
  162. sql1.Open("update T_Custom set CmdNum=CmdNum-1 from T_Custom where CustomType=" + iCustomType.ToString() + " and CmdNum>" + strcmdnum);
  163. MessageBox.Show("删除指令成功!");
  164. }
  165. sql1.Close();
  166. LoadDataGrid();
  167. }
  168. /// <summary>
  169. /// 自定义类型检测
  170. /// </summary>
  171. /// <param name="sender"></param>
  172. /// <param name="e"></param>
  173. private void Custom_Checked(object sender, RoutedEventArgs e)
  174. {
  175. if (MarkRadioBtn.IsChecked.HasValue)//是否为null
  176. {
  177. if ((bool)MarkRadioBtn.IsChecked)
  178. {
  179. iCustomType = 1;//地标功能
  180. LoadDataGrid();
  181. }
  182. else
  183. {
  184. iCustomType = 2;//运行状态
  185. LoadDataGrid();
  186. }
  187. }
  188. else
  189. {
  190. iCustomType = 0;
  191. }
  192. }
  193. /// <summary>
  194. /// 窗口关闭
  195. /// </summary>
  196. /// <param name="sender"></param>
  197. /// <param name="e"></param>
  198. private void Window_Closed(object sender, EventArgs e)
  199. {
  200. MessageBox.Show("修改成功重启软件后生效!","温馨提示");
  201. }
  202. }
  203. }