CMenuSettingForm.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. using CasunCommon.BaseUI;
  2. using System;
  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.Threading.Tasks;
  10. using System.Windows.Forms;
  11. namespace PMSUI
  12. {
  13. public partial class CMenuSettingForm : CasunForm
  14. {
  15. private enum MenuDGVMenu
  16. {
  17. MenuName,
  18. DisplayMenuName,
  19. ModuleName,
  20. IsShow,
  21. ChildMenuSort,
  22. ParentMenuSort
  23. }
  24. private enum MenuDGVColumn
  25. {
  26. FormName,
  27. DBColumnName,
  28. ShowColumnName,
  29. IsShow,
  30. Sort
  31. }
  32. private int selectRowIndexOfordersDataGridView; // 记录选中的行号
  33. private int selectColumnIndexOfordersDataGridView; // 记录选中的列号
  34. private int scrollingRowIndexOfordersDataGridView; // 记录垂直滚动条位置
  35. private int scrollingColumnIndexOfordersDataGridView; // 记录水平滚动条的位置
  36. private int selectRowIndexOfordersDataGridView1; // 记录选中的行号
  37. private int selectColumnIndexOfordersDataGridView1; // 记录选中的列号
  38. private int scrollingRowIndexOfordersDataGridView1; // 记录垂直滚动条位置
  39. private int scrollingColumnIndexOfordersDataGridView1; // 记录水平滚动条的位置
  40. public CMenuSettingForm()
  41. {
  42. InitializeComponent();
  43. }
  44. private void Init()
  45. {
  46. CasunUILib.DgvModel(dgvMenuSetting);
  47. CasunUILib.DgvModel(dgvFormColumnSetting);
  48. }
  49. bool checkIsNumber(string text)
  50. {
  51. int result = 0;
  52. bool re = int.TryParse(text, out result);
  53. if (re && result > 0)
  54. {
  55. return true;
  56. }
  57. return false;
  58. }
  59. private void CMenuSettingForm_Load(object sender, EventArgs e)
  60. {
  61. CasunUILib.ButtonHelps(btHelpsForm);
  62. CasunUILib.ButtonHelps(btHelpsMenu);
  63. Init();
  64. loadMenuTable();
  65. loadColumnTable();
  66. InitComboBox();
  67. }
  68. private void loadMenuTable()
  69. {
  70. if (dgvMenuSetting.CurrentCell != null && dgvMenuSetting.RowCount != 0 && dgvMenuSetting.ColumnCount != 0)
  71. {
  72. selectRowIndexOfordersDataGridView = dgvMenuSetting.CurrentCell.RowIndex;
  73. selectColumnIndexOfordersDataGridView = dgvMenuSetting.CurrentCell.ColumnIndex;
  74. scrollingRowIndexOfordersDataGridView = dgvMenuSetting.FirstDisplayedScrollingRowIndex;
  75. scrollingColumnIndexOfordersDataGridView = dgvMenuSetting.FirstDisplayedScrollingColumnIndex;
  76. }
  77. ResetMenuControl();
  78. string strwhere = "1=1 order by cast(ParentMenuSort as int),cast(ChildMenuSort as int)";
  79. DataSet ds = PmsCoreDB.DBHost.Instance.MenuSetting.GetListWithColumnName(strwhere);
  80. dgvMenuSetting.DataSource = ds.Tables[0];
  81. int n = dgvMenuSetting.RowCount;
  82. int m = dgvMenuSetting.ColumnCount;
  83. if (n != 0 && m != 0)
  84. {
  85. if (selectRowIndexOfordersDataGridView < n && selectColumnIndexOfordersDataGridView < m &&
  86. scrollingRowIndexOfordersDataGridView < n && scrollingColumnIndexOfordersDataGridView < m)
  87. {
  88. dgvMenuSetting.CurrentCell = dgvMenuSetting.Rows[selectRowIndexOfordersDataGridView].Cells[selectColumnIndexOfordersDataGridView];
  89. dgvMenuSetting.FirstDisplayedScrollingRowIndex = scrollingRowIndexOfordersDataGridView;
  90. dgvMenuSetting.FirstDisplayedScrollingColumnIndex = scrollingColumnIndexOfordersDataGridView;
  91. }
  92. }
  93. }
  94. private void loadColumnTable()
  95. {
  96. string formName = cbWhichForm.Text.ToString();
  97. if (dgvFormColumnSetting.CurrentCell != null && dgvFormColumnSetting.RowCount != 0 && dgvFormColumnSetting.ColumnCount != 0)
  98. {
  99. selectRowIndexOfordersDataGridView1 = dgvFormColumnSetting.CurrentCell.RowIndex;
  100. selectColumnIndexOfordersDataGridView1 = dgvFormColumnSetting.CurrentCell.ColumnIndex;
  101. scrollingRowIndexOfordersDataGridView1 = dgvFormColumnSetting.FirstDisplayedScrollingRowIndex;
  102. scrollingColumnIndexOfordersDataGridView1 = dgvFormColumnSetting.FirstDisplayedScrollingColumnIndex;
  103. }
  104. ResetColumnControl();
  105. string strwhere = "";
  106. if (formName == "")
  107. {
  108. strwhere = "1=1 order by FormName,cast(Sort as int)";
  109. }
  110. else
  111. {
  112. strwhere = "FormName = '" + formName + "' order by FormName,cast(Sort as int)";
  113. }
  114. DataSet ds = PmsCoreDB.DBHost.Instance.ColumnSetting.GetAllListWithColumnName(strwhere);
  115. dgvFormColumnSetting.DataSource = ds.Tables[0];
  116. int n = dgvFormColumnSetting.RowCount;
  117. int m = dgvFormColumnSetting.ColumnCount;
  118. if (n != 0 && m != 0)
  119. {
  120. if (selectRowIndexOfordersDataGridView1 < n && selectColumnIndexOfordersDataGridView1 < m &&
  121. scrollingRowIndexOfordersDataGridView1 < n && scrollingColumnIndexOfordersDataGridView1 < m)
  122. {
  123. dgvFormColumnSetting.CurrentCell = dgvFormColumnSetting.Rows[selectRowIndexOfordersDataGridView1].Cells[selectColumnIndexOfordersDataGridView1];
  124. dgvFormColumnSetting.FirstDisplayedScrollingRowIndex = scrollingRowIndexOfordersDataGridView1;
  125. dgvFormColumnSetting.FirstDisplayedScrollingColumnIndex = scrollingColumnIndexOfordersDataGridView1;
  126. }
  127. }
  128. }
  129. private void InitComboBox()
  130. {
  131. List<string> AllFormList = PmsCoreDB.DBHost.Instance.ColumnSetting.GetAllFormName();
  132. cbWhichForm.Items.Clear();
  133. cbWhichForm.Items.Add("");
  134. cbWhichForm.Items.AddRange(AllFormList.ToArray());
  135. }
  136. private void ResetMenuControl()
  137. {
  138. tbMenuName.Text = "";
  139. tbMenuModule.Text = "";
  140. ckbIsMenuShow.Checked = false;
  141. tbMenuSort.Text = "";
  142. tbModuleSort.Text = "";
  143. }
  144. private void ResetColumnControl()
  145. {
  146. tbFormName.Text = "";
  147. tbDBColumnName.Text = "";
  148. tbShowName.Text = "";
  149. ckbShowColumn.Checked = false;
  150. tbColumnSort.Text = "";
  151. //cbWhichForm.Text = "";
  152. }
  153. private void dgvMenuSetting_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
  154. {
  155. int DGVCurrentRow = e.RowIndex;
  156. if (DGVCurrentRow != -1 && dgvMenuSetting.Rows[DGVCurrentRow] != null)
  157. {
  158. if (dgvMenuSetting.Rows[DGVCurrentRow].Cells[(int)MenuDGVMenu.MenuName].Value != null)
  159. {
  160. tbMenuName.Text = dgvMenuSetting.Rows[DGVCurrentRow].Cells[(int)MenuDGVMenu.MenuName].Value.ToString();
  161. }
  162. if (dgvMenuSetting.Rows[DGVCurrentRow].Cells[(int)MenuDGVMenu.DisplayMenuName].Value != null)
  163. {
  164. tbDisplayMenuName.Text = dgvMenuSetting.Rows[DGVCurrentRow].Cells[(int)MenuDGVMenu.DisplayMenuName].Value.ToString();
  165. }
  166. if (dgvMenuSetting.Rows[DGVCurrentRow].Cells[(int)MenuDGVMenu.ModuleName].Value != null)
  167. {
  168. tbMenuModule.Text = dgvMenuSetting.Rows[DGVCurrentRow].Cells[(int)MenuDGVMenu.ModuleName].Value.ToString();
  169. }
  170. if (dgvMenuSetting.Rows[DGVCurrentRow].Cells[(int)MenuDGVMenu.IsShow].Value != null)
  171. {
  172. //cbIsMenuShow.Text = dgvMenuSetting.Rows[DGVCurrentRow].Cells[(int)MenuDGVMenu.IsShow].Value.ToString();
  173. ckbIsMenuShow.Checked = (bool)dgvMenuSetting.Rows[DGVCurrentRow].Cells[(int)MenuDGVMenu.IsShow].Value;
  174. }
  175. if (dgvMenuSetting.Rows[DGVCurrentRow].Cells[(int)MenuDGVMenu.ChildMenuSort].Value != null)
  176. {
  177. tbMenuSort.Text = dgvMenuSetting.Rows[DGVCurrentRow].Cells[(int)MenuDGVMenu.ChildMenuSort].Value.ToString();
  178. }
  179. if (dgvMenuSetting.Rows[DGVCurrentRow].Cells[(int)MenuDGVMenu.ParentMenuSort].Value != null)
  180. {
  181. tbModuleSort.Text = dgvMenuSetting.Rows[DGVCurrentRow].Cells[(int)MenuDGVMenu.ParentMenuSort].Value.ToString();
  182. }
  183. }
  184. }
  185. private void dgvFormColumnSetting_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
  186. {
  187. int DGVCurrentRow = e.RowIndex;
  188. if (DGVCurrentRow != -1 && dgvFormColumnSetting.Rows[DGVCurrentRow] != null)
  189. {
  190. if (dgvFormColumnSetting.Rows[DGVCurrentRow].Cells[(int)MenuDGVColumn.FormName].Value != null)
  191. {
  192. tbFormName.Text = dgvFormColumnSetting.Rows[DGVCurrentRow].Cells[(int)MenuDGVColumn.FormName].Value.ToString();
  193. }
  194. if (dgvFormColumnSetting.Rows[DGVCurrentRow].Cells[(int)MenuDGVColumn.DBColumnName].Value != null)
  195. {
  196. tbDBColumnName.Text = dgvFormColumnSetting.Rows[DGVCurrentRow].Cells[(int)MenuDGVColumn.DBColumnName].Value.ToString();
  197. }
  198. if (dgvFormColumnSetting.Rows[DGVCurrentRow].Cells[(int)MenuDGVColumn.ShowColumnName].Value != null)
  199. {
  200. tbShowName.Text = dgvFormColumnSetting.Rows[DGVCurrentRow].Cells[(int)MenuDGVColumn.ShowColumnName].Value.ToString();
  201. }
  202. if (dgvFormColumnSetting.Rows[DGVCurrentRow].Cells[(int)MenuDGVColumn.IsShow].Value != null)
  203. {
  204. ckbShowColumn.Checked = (bool)dgvFormColumnSetting.Rows[DGVCurrentRow].Cells[(int)MenuDGVColumn.IsShow].Value;
  205. }
  206. if (dgvFormColumnSetting.Rows[DGVCurrentRow].Cells[(int)MenuDGVColumn.Sort].Value != null)
  207. {
  208. tbColumnSort.Text = dgvFormColumnSetting.Rows[DGVCurrentRow].Cells[(int)MenuDGVColumn.Sort].Value.ToString();
  209. }
  210. }
  211. }
  212. private void btMenuAdd_Click(object sender, EventArgs e)
  213. {
  214. if (!String.IsNullOrEmpty(tbMenuName.Text.ToString()) && !String.IsNullOrEmpty(tbMenuModule.Text.ToString())
  215. && !String.IsNullOrEmpty(tbMenuModule.Text.ToString()) && checkIsNumber(tbMenuSort.Text) && checkIsNumber(tbModuleSort.Text))
  216. {
  217. PmsCoreDB.Model.PMS_sys_MenuSetting model = new PmsCoreDB.Model.PMS_sys_MenuSetting();
  218. model.MenuName = tbMenuName.Text.ToString();
  219. model.DisplayMenuName = tbDisplayMenuName.Text.ToString();
  220. model.ModuleName = tbMenuModule.Text;
  221. model.IsShow = ckbIsMenuShow.Checked;
  222. model.ChildMenuSort = Convert.ToInt32(tbMenuSort.Text);
  223. model.ParentMenuSort = Convert.ToInt32(tbModuleSort.Text);
  224. if (PmsCoreDB.DBHost.Instance.MenuSetting.Add(model))
  225. {
  226. MessageBox.Show(CLanguageManager.LanguageChange("添加成功") + "!");
  227. }
  228. else
  229. {
  230. MessageBox.Show(CLanguageManager.LanguageChange("添加失败") + "!");
  231. }
  232. loadMenuTable();
  233. }
  234. else
  235. {
  236. MessageBox.Show("请检查输入");
  237. }
  238. }
  239. private void btMenuModfiy_Click(object sender, EventArgs e)
  240. {
  241. if (!String.IsNullOrEmpty(tbMenuName.Text.ToString()) && !String.IsNullOrEmpty(tbMenuModule.Text.ToString())
  242. && !String.IsNullOrEmpty(tbMenuModule.Text.ToString()) && checkIsNumber(tbMenuSort.Text) && checkIsNumber(tbModuleSort.Text))
  243. {
  244. PmsCoreDB.Model.PMS_sys_MenuSetting model = new PmsCoreDB.Model.PMS_sys_MenuSetting();
  245. model.MenuName = tbMenuName.Text.ToString();
  246. model.DisplayMenuName = tbDisplayMenuName.Text.ToString();
  247. model.ModuleName = tbMenuModule.Text;
  248. model.IsShow = ckbIsMenuShow.Checked;
  249. model.ChildMenuSort = Convert.ToInt32(tbMenuSort.Text);
  250. model.ParentMenuSort = Convert.ToInt32(tbModuleSort.Text);
  251. if (PmsCoreDB.DBHost.Instance.MenuSetting.Update(model))
  252. {
  253. MessageBox.Show(CLanguageManager.LanguageChange("修改成功") + "!");
  254. }
  255. else
  256. {
  257. MessageBox.Show(CLanguageManager.LanguageChange("修改失败") + "!");
  258. }
  259. loadMenuTable();
  260. }
  261. else
  262. {
  263. MessageBox.Show("请检查输入");
  264. }
  265. }
  266. private void btMenuDelete_Click(object sender, EventArgs e)
  267. {
  268. if (!String.IsNullOrEmpty(tbMenuName.Text.ToString()))
  269. {
  270. string strMsg = CLanguageManager.LanguageChange("删除菜单设置") + "【" + tbMenuName.Text.ToString() + "】," + CLanguageManager.LanguageChange("是否继续") + "!";
  271. if (MessageBox.Show(strMsg, CLanguageManager.LanguageChange("删除菜单设置"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.OK)
  272. {
  273. return;
  274. }
  275. if (PmsCoreDB.DBHost.Instance.MenuSetting.Delete(tbMenuName.Text.ToString()))
  276. {
  277. MessageBox.Show(CLanguageManager.LanguageChange("删除成功") + "!");
  278. }
  279. else
  280. {
  281. MessageBox.Show(CLanguageManager.LanguageChange("删除失败") + "!");
  282. }
  283. loadMenuTable();
  284. }
  285. else
  286. {
  287. MessageBox.Show("请检查输入");
  288. }
  289. }
  290. private void btColSetAdd_Click(object sender, EventArgs e)
  291. {
  292. if (!String.IsNullOrEmpty(tbFormName.Text.ToString()) && !String.IsNullOrEmpty(tbDBColumnName.Text.ToString())
  293. && !String.IsNullOrEmpty(tbShowName.Text.ToString()) && checkIsNumber(tbColumnSort.Text))
  294. {
  295. PmsCoreDB.Model.PMS_sys_FormColumnSetting model = new PmsCoreDB.Model.PMS_sys_FormColumnSetting();
  296. model.FormName = tbFormName.Text.ToString();
  297. model.DBColumnName = tbDBColumnName.Text;
  298. model.ShowColumnName = tbShowName.Text;
  299. model.IsShow = ckbShowColumn.Checked;
  300. model.Sort = Convert.ToInt32(tbColumnSort.Text);
  301. if (PmsCoreDB.DBHost.Instance.ColumnSetting.Add(model))
  302. {
  303. MessageBox.Show(CLanguageManager.LanguageChange("添加成功") + "!");
  304. }
  305. else
  306. {
  307. MessageBox.Show(CLanguageManager.LanguageChange("添加失败") + "!");
  308. }
  309. loadColumnTable();
  310. }
  311. else
  312. {
  313. MessageBox.Show("请检查输入");
  314. }
  315. }
  316. private void btColSetModify_Click(object sender, EventArgs e)
  317. {
  318. if (!String.IsNullOrEmpty(tbFormName.Text.ToString()) && !String.IsNullOrEmpty(tbDBColumnName.Text.ToString())
  319. && !String.IsNullOrEmpty(tbShowName.Text.ToString()) && checkIsNumber(tbColumnSort.Text))
  320. {
  321. PmsCoreDB.Model.PMS_sys_FormColumnSetting model = new PmsCoreDB.Model.PMS_sys_FormColumnSetting();
  322. model.FormName = tbFormName.Text.ToString();
  323. model.DBColumnName = tbDBColumnName.Text;
  324. model.ShowColumnName = tbShowName.Text;
  325. model.IsShow = ckbShowColumn.Checked;
  326. model.Sort = Convert.ToInt32(tbColumnSort.Text);
  327. if (PmsCoreDB.DBHost.Instance.ColumnSetting.Update(model))
  328. {
  329. MessageBox.Show(CLanguageManager.LanguageChange("修改成功") + "!");
  330. }
  331. else
  332. {
  333. MessageBox.Show(CLanguageManager.LanguageChange("修改失败") + "!");
  334. }
  335. loadColumnTable();
  336. }
  337. else
  338. {
  339. MessageBox.Show("请检查输入");
  340. }
  341. }
  342. private void btColSetDel_Click(object sender, EventArgs e)
  343. {
  344. if (!String.IsNullOrEmpty(tbFormName.Text.ToString()) && !String.IsNullOrEmpty(tbDBColumnName.Text.ToString()))
  345. {
  346. string strMsg = CLanguageManager.LanguageChange("删除界面列显示设置") + "【" + tbFormName.Text.ToString() + "】," + CLanguageManager.LanguageChange("是否继续") + "!";
  347. if (MessageBox.Show(strMsg, CLanguageManager.LanguageChange("删除界面列显示设置"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.OK)
  348. {
  349. return;
  350. }
  351. if (PmsCoreDB.DBHost.Instance.ColumnSetting.Delete(tbFormName.Text.ToString(), tbDBColumnName.Text.ToString()))
  352. {
  353. MessageBox.Show(CLanguageManager.LanguageChange("删除成功") + "!");
  354. }
  355. else
  356. {
  357. MessageBox.Show(CLanguageManager.LanguageChange("删除失败") + "!");
  358. }
  359. loadColumnTable();
  360. }
  361. else
  362. {
  363. MessageBox.Show("请检查输入");
  364. }
  365. }
  366. private void cbWhichForm_SelectedValueChanged(object sender, EventArgs e)
  367. {
  368. loadColumnTable();
  369. }
  370. private void btHelpsForm_Click(object sender, EventArgs e)
  371. {
  372. MessageBox.Show(PMSUI.Config.CConfigManager.gs_FormHelpConfig.GetFormHelp(CasunUILib.EForms.FormSetting.ToString()));
  373. }
  374. private void btHelpsMenu_Click(object sender, EventArgs e)
  375. {
  376. MessageBox.Show(PMSUI.Config.CConfigManager.gs_FormHelpConfig.GetFormHelp(CasunUILib.EForms.MenuSetting.ToString()));
  377. }
  378. }
  379. }