PersonnelQ.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using Org.BouncyCastle.Asn1;
  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.Text.Json;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using static ddq.DataAccess;
  13. using static ddq.Utility;
  14. namespace ddq
  15. {
  16. public partial class PersonnelQ : Form
  17. {
  18. private string personnelId;
  19. private string companyId;
  20. private int userId;
  21. public PersonnelQ(string personnelId, string companyId, int userId)
  22. {
  23. InitializeComponent();
  24. this.personnelId = personnelId;
  25. this.companyId = companyId;
  26. this.userId = userId;
  27. InitializeData();
  28. }
  29. private void InitializeData()
  30. {
  31. //int role_type;
  32. BindingSource bs = new BindingSource();
  33. Dictionary<int, string> d = new Dictionary<int, string>(Utility.RoleType);
  34. bs.DataSource = d;
  35. this.cmbRole.DataSource = bs;
  36. this.cmbRole.DisplayMember = "Value";
  37. this.cmbRole.ValueMember = "Key";
  38. this.cmbRole.SelectedValue = 1;
  39. if (personnelId != null)
  40. {
  41. DataTable dt = DataAccess.Get_dd_personnel_info(personnelId, companyId);
  42. if (dt != null && dt.Rows.Count > 0)
  43. {
  44. this.txtName.Text = dt.Rows[0]["name"].ToString();
  45. this.txtTitle.Text = Null2Text(dt.Rows[0]["title"]);
  46. this.txtIndustryStartYear.Text = Null2Text(dt.Rows[0]["industry_start_year"]);
  47. this.txtCompanyStartYear.Text = Null2Text(dt.Rows[0]["company_start_year"]);
  48. this.txtBio.Text = Null2Text(dt.Rows[0]["bio"]);
  49. this.tspManagerInfo.Text = DateTime.Parse(dt.Rows[0]["updatetime"].ToString()).ToString("yyyy-MM-dd HH:mm:ss");
  50. this.tspManagerInfo.ForeColor = IsChangedRecently(this.tspManagerInfo.Text) ? COLOR_MODIFIED : COLOR_NORMAL;
  51. string strRole = dt.Rows[0]["role"].ToString();
  52. int.TryParse(strRole, out int role);
  53. this.cmbRole.SelectedValue = role;
  54. }
  55. }
  56. }
  57. private string Null2Text(object o)
  58. {
  59. if (o == null) return "";
  60. return o.ToString();
  61. }
  62. private void btnSavePersonnel_Click(object sender, EventArgs e)
  63. {
  64. int? companyStartYear = null;
  65. int? industryStartYear = null;
  66. if (int.TryParse(this.txtCompanyStartYear.Text, out int newYear)) { companyStartYear = newYear; }
  67. if (int.TryParse(this.txtIndustryStartYear.Text, out int newYear2)) { industryStartYear = newYear2; }
  68. DataAccess.Set_dd_personnel_info(personnelId, DateTime.Today, companyId,
  69. this.txtName.Text.Trim(),
  70. int.Parse(this.cmbRole.SelectedValue.ToString()),
  71. this.txtTitle.Text.Trim(),
  72. companyStartYear,
  73. industryStartYear,
  74. this.txtBio.Text.Trim(),
  75. 1, 1, userId, out string personnel_id);
  76. this.DialogResult = DialogResult.OK;
  77. }
  78. }
  79. }