using Org.BouncyCastle.Asn1; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Text.Json; using System.Threading.Tasks; using System.Windows.Forms; using static ddq.DataAccess; using static ddq.Utility; namespace ddq { public partial class PersonnelQ : Form { private string personnelId; private string companyId; private int userId; public PersonnelQ(string personnelId, string companyId, int userId) { InitializeComponent(); this.personnelId = personnelId; this.companyId = companyId; this.userId = userId; InitializeData(); } private void InitializeData() { //int role_type; BindingSource bs = new BindingSource(); Dictionary d = new Dictionary(Utility.RoleType); bs.DataSource = d; this.cmbRole.DataSource = bs; this.cmbRole.DisplayMember = "Value"; this.cmbRole.ValueMember = "Key"; this.cmbRole.SelectedValue = 1; if (personnelId != null) { DataTable dt = DataAccess.Get_dd_personnel_info(personnelId, companyId); if (dt != null && dt.Rows.Count > 0) { this.txtName.Text = dt.Rows[0]["name"].ToString(); this.txtTitle.Text = Null2Text(dt.Rows[0]["title"]); this.txtIndustryStartYear.Text = Null2Text(dt.Rows[0]["industry_start_year"]); this.txtCompanyStartYear.Text = Null2Text(dt.Rows[0]["company_start_year"]); this.txtBio.Text = Null2Text(dt.Rows[0]["bio"]); this.tspManagerInfo.Text = DateTime.Parse(dt.Rows[0]["updatetime"].ToString()).ToString("yyyy-MM-dd HH:mm:ss"); this.tspManagerInfo.ForeColor = IsChangedRecently(this.tspManagerInfo.Text) ? COLOR_MODIFIED : COLOR_NORMAL; string strRole = dt.Rows[0]["role"].ToString(); int.TryParse(strRole, out int role); this.cmbRole.SelectedValue = role; } } } private string Null2Text(object o) { if (o == null) return ""; return o.ToString(); } private void btnSavePersonnel_Click(object sender, EventArgs e) { int? companyStartYear = null; int? industryStartYear = null; if (int.TryParse(this.txtCompanyStartYear.Text, out int newYear)) { companyStartYear = newYear; } if (int.TryParse(this.txtIndustryStartYear.Text, out int newYear2)) { industryStartYear = newYear2; } DataAccess.Set_dd_personnel_info(personnelId, DateTime.Today, companyId, this.txtName.Text.Trim(), int.Parse(this.cmbRole.SelectedValue.ToString()), this.txtTitle.Text.Trim(), companyStartYear, industryStartYear, this.txtBio.Text.Trim(), 1, 1, userId, out string personnel_id); this.DialogResult = DialogResult.OK; } } }