版博士V2.0程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

78 строки
2.2 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. namespace ProductionControl
  11. {
  12. public partial class FrmRoleInfo : Form
  13. {
  14. Service.RoleService service = new Service.RoleService();
  15. Models.Role model = new Models.Role();
  16. public FrmRoleInfo(Models.Role m = null)
  17. {
  18. InitializeComponent();
  19. if (m != null)
  20. {
  21. model = m;
  22. this.txtCode.Enabled = false;
  23. }
  24. }
  25. private void initDataView()
  26. {
  27. this.txtCode.Text = model.Code;
  28. this.txtName.Text = model.Name;
  29. }
  30. private void FrmRoleInfo_Load(object sender, EventArgs e)
  31. {
  32. initDataView();
  33. }
  34. private void btnSave_Click(object sender, EventArgs e)
  35. {
  36. try
  37. {
  38. string szCode = this.txtCode.Text.Trim();
  39. string szName = this.txtName.Text.Trim();
  40. if (szCode == "" || szName == "")
  41. throw new Exception("请填写编号和名称!");
  42. model.Code = szCode;
  43. model.Name = szName;
  44. model.ModifyUserCode = Config.loginUser.Code;
  45. bool result;
  46. if (model.Id == 0)
  47. {
  48. model.CreateUserCode = Config.loginUser.Code;
  49. result = service.Insert(model);
  50. }
  51. else
  52. result = service.Update(model);
  53. if (!result)
  54. throw new Exception("保存失败!");
  55. MessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  56. this.DialogResult = DialogResult.OK;
  57. this.Close();
  58. }
  59. catch (Exception ex)
  60. {
  61. MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  62. }
  63. }
  64. private void btnCancel_Click(object sender, EventArgs e)
  65. {
  66. this.Close();
  67. }
  68. }
  69. }