using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using DevExpress.XtraEditors; using ICSSoft.Base.Language.Tool; using ICSSoft.Base.Config.AppConfig; using ICSSoft.Base.UserControl.MessageControl; using ICSSoft.Base.Config.DBHelper; using ICSSoft.Base.Report.Filter; using ICSSoft.Base.UserControl.FormControl; using ICSSoft.Base.Report.GridReport; using ICSSoft.Base.ReferForm.AppReferForm; using ICSSoft.Frame.Data.BLL; using Newtonsoft.Json; using System.Net; using System.Configuration; using ICSSoft.Entity.PU_AppVouch; using ICSSoft.Frame.Data.Entity.WWModel; using ICSSoft.Frame.Data.DAL; using ICSSoft.Frame.Data.Entity; namespace ICSSoft.Frame.APP { public partial class FormICSSkillMatrixAdd : DevExpress.XtraEditors.XtraForm { ICSSkillMatrix SkillMatrix; int flag; string guid; public FormICSSkillMatrixAdd() { InitializeComponent(); Init(); chargeFormState("Add"); flag = 0; guid = AppConfig.GetGuid(); // this.cobEquipmentName.Visible = false; this.txtProcessCoding.Visible = false; // this.label8.Visible = false; this.label2.Visible = false; } public FormICSSkillMatrixAdd(string id) { InitializeComponent(); Init(); chargeFormState("Edit"); SearchTypeInfo(id); flag = 1; guid = id; // this.cobEquipmentName.Visible = false; this.txtProcessCoding.Visible = false; // this.label8.Visible = false; this.label2.Visible = false; } private void chargeFormState(string state) { switch (state) { case "Add": txtMUSERName.Text = AppConfig.UserName; txtMTIME.Text = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss").ToString(); txtMUSERName.Properties.ReadOnly = true; txtMTIME.Properties.ReadOnly = true; break; case "Edit": //txtProcessRouteCoding.Properties.Buttons[0].Visible = false; //txtProcessRouteCoding.Enabled = false; txtMUSERName.Text = AppConfig.UserName; txtMTIME.Text = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss").ToString(); txtMUSERName.Properties.ReadOnly = true; txtMTIME.Properties.ReadOnly = true; break; } } //给表格中赋值 private void SearchTypeInfo(string id) { SkillMatrix = ICSSkillMatrixBLL.select(id, AppConfig.AppConnectString); guid = SkillMatrix.ID; this.txtPersonnel.Text = SkillMatrix.Personnel; this.txtSkillLevel.Text = SkillMatrix.SkillLevel; this.txtWorkNo.Text = SkillMatrix.WorkNo; this.txtEquipmentType.Text = SkillMatrix.EquipmentType; this.cobEquipmentName.Text = SkillMatrix.EATTRIBUTE1; } private string check() { string msg = ""; Decimal decValue = 0m; if (txtPersonnel.Text.Trim() == "") msg += "人员不能为空!\n"; if (txtEquipmentType.Text.Trim() == "") msg += "设备类型不能为空!\n"; return msg; } private void btnOK_Click(object sender, EventArgs e) { try { string msg = check(); if (!string.IsNullOrEmpty(msg)) { ICSBaseSimpleCode.AppshowMessageBox(msg); return; } ICSSkillMatrix eqpstp = new ICSSkillMatrix(); eqpstp.ID = guid; eqpstp.EquipmentType = txtEquipmentType.Text;//设备编号 eqpstp.Personnel = txtPersonnel.Text; eqpstp.SkillLevel = txtSkillLevel.Text; eqpstp.WorkNo = this.txtWorkNo.Text.Trim(); eqpstp.MUSER = AppConfig.UserId; eqpstp.MUSERName = AppConfig.UserName; eqpstp.MTIME = DateTime.Now; eqpstp.WorkPoint = AppConfig.WorkPointCode; eqpstp.EATTRIBUTE1 = cobEquipmentName.Text; ICSSkillMatrixBLL.Add(eqpstp, AppConfig.AppConnectString); this.Close(); //this.DialogResult = DialogResult.Yes; if (flag == 0) { ICSBaseSimpleCode.AppshowMessageBox("添加成功"); } else if (flag == 1) { ICSBaseSimpleCode.AppshowMessageBox("修改成功"); } } catch (Exception ex) { MessageBox.Show(ex.Message); // throw new Exception(ex.Message); } } #region 关闭 private void btnCancle_Click(object sender, EventArgs e) { this.Close(); //this.DialogResult = DialogResult.Cancel; } private void btnClose_Click(object sender, EventArgs e) { this.Close(); //this.DialogResult = DialogResult.Cancel; } #endregion public DataTable EquipmentTable() { string sql_ = @"SELECT ROW_NUMBER () OVER (ORDER BY EQPCode) AS Id, EQPCode, EQPName FROM ICSEquipment WHERE EQPCode='{0}'"; sql_ = string.Format(sql_, this.txtEquipmentType.Text); DataTable data_ = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql_).Tables[0]; return data_; } private void bindEquipment() { IList infoList = new List(); DataTable hfcode = EquipmentTable(); Info data = new Info(); data.Id = "0"; data.Name = "--请选择--"; infoList.Add(data); if (hfcode != null) { foreach (DataRow dr in hfcode.Rows) { data = new Info(); data.Id = dr["Id"].ToString(); data.Name = dr["EQPCode"].ToString() + dr["EQPName"].ToString(); infoList.Add(data); } } this.cobEquipmentName.DataSource = infoList; cobEquipmentName.ValueMember = "Name"; cobEquipmentName.DisplayMember = "Name"; cobEquipmentName.SelectedIndex =1; } public class Info { public string Id { get; set; } public string Name { get; set; } } #region 设备类型按钮 改成设备编码 /// /// /// private void txtEquipmentType_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { ButtonEdit btn = (ButtonEdit)sender; string sql = "select distinct EQPCode as [设备编码] ,EQPNAME as [设备名称] from dbo.ICSEquipment with(nolock) WHERE 1=1"; DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql).Tables[0]; FormDataRefer reForm = new FormDataRefer(); reForm.FormTitle = "设备编码信息"; DataTable menuData = data; reForm.DataSource = menuData; reForm.MSelectFlag = false; reForm.RowIndexWidth = 35; reForm.HideCols.Add("ID"); reForm.FormWidth = 500; reForm.FormHeight = 500; //reForm.FilterKey = btn.Text; //grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, grvDetail.FocusedColumn).ToString().Trim(); if (reForm.ShowDialog() == DialogResult.OK) { DataTable retData = reForm.ReturnData; foreach (DataRow dr in retData.Rows) { this.txtEquipmentType.Text = dr["设备编码"].ToString(); this.cobEquipmentName.Text = dr["设备名称"].ToString(); } bindEquipment(); } } #endregion #region 工序点击 private void txtProcessCoding_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { ButtonEdit btn = (ButtonEdit)sender; string sql = "select distinct OPCODE as [工序编码] from dbo.ICSROUTE2OP with(nolock) WHERE 1=1"; DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql).Tables[0]; FormDataRefer reForm = new FormDataRefer(); reForm.FormTitle = "工序编码信息"; DataTable menuData = data; reForm.DataSource = menuData; reForm.MSelectFlag = false; reForm.RowIndexWidth = 35; reForm.HideCols.Add("ID"); reForm.FormWidth = 500; reForm.FormHeight = 500; //reForm.FilterKey = btn.Text; //grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, grvDetail.FocusedColumn).ToString().Trim(); if (reForm.ShowDialog() == DialogResult.OK) { DataTable retData = reForm.ReturnData; foreach (DataRow dr in retData.Rows) { this.txtProcessCoding.Text = dr["工序编码"].ToString(); } } } #endregion #region 工号 private void txtWorkNo_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)Keys.Enter) { string WorkNo = txtWorkNo.Text.Trim(); string sql = @"SELECT DISTINCT '' as [isSelect], a.ID AS ID, a.UserCode as UserCode, a.UserName as UserName FROM Sys_User a WHERE a.UserCode = '{0}'"; sql = string.Format(sql, WorkNo); DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql).Tables[0]; if (data.Rows.Count > 0) { foreach (DataRow dr in data.Rows) { txtWorkNo.Text = dr["UserCode"].ToString(); txtWorkNo.Tag = dr["UserCode"].ToString(); txtPersonnel.Text = dr["UserName"].ToString(); } } else { txtWorkNo.Tag = ""; txtWorkNo.Text = ""; txtPersonnel.Text = ""; txtWorkNo.SelectAll(); txtWorkNo.Focus(); } } } #endregion private void txtWorkNo_KeyDown(object sender, KeyEventArgs e) { } private void Init() { #region 工号 string sql = @"SELECT DISTINCT a.UserCode as 工号, a.UserName as 用户名 FROM Sys_User a where WorkPointCode='" + AppConfig.WorkPointCode+"'"; DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql).Tables[0]; txtWorkNo.Properties.ValueMember = "工号"; txtWorkNo.Properties.DisplayMember = "工号"; txtWorkNo.Properties.DataSource = dt; txtWorkNo.Properties.NullText = "";//空时的值 txtWorkNo.Properties.ImmediatePopup = true;//输入值是否马上弹出窗体 txtWorkNo.Properties.ValidateOnEnterKey = true;//回车确认 txtWorkNo.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;//要使用户可以输入,这里须设为Standard txtWorkNo.Properties.AllowNullInput = DevExpress.Utils.DefaultBoolean.True; //可用Ctrl + Delete清空选择內容 //自适应宽度 txtWorkNo.Properties.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup; #endregion #region 设备编码 sql = @"select distinct EQPCode as [设备编码] ,EQPNAME as [设备名称] from dbo.ICSEquipment with(nolock) WHERE 1=1"; DataTable dt1 = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql).Tables[0]; txtEquipmentType.Properties.ValueMember = "设备编码"; txtEquipmentType.Properties.DisplayMember = "设备编码"; txtEquipmentType.Properties.DataSource = dt1; txtEquipmentType.Properties.NullText = "";//空时的值 txtEquipmentType.Properties.ImmediatePopup = true;//输入值是否马上弹出窗体 txtEquipmentType.Properties.ValidateOnEnterKey = true;//回车确认 txtEquipmentType.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;//要使用户可以输入,这里须设为Standard txtEquipmentType.Properties.AllowNullInput = DevExpress.Utils.DefaultBoolean.True; //可用Ctrl + Delete清空选择內容 //自适应宽度 txtEquipmentType.Properties.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup; #endregion } private void txtWorkNo_EditValueChanged(object sender, EventArgs e) { var o = txtWorkNo.Properties.GetRowByKeyValue(txtWorkNo.EditValue); if (o is DataRowView) { DataRowView RowView = o as DataRowView; txtPersonnel.Text = RowView.Row["用户名"].ToString(); } } private void txtEquipmentType_EditValueChanged(object sender, EventArgs e) { var o = txtEquipmentType.Properties.GetRowByKeyValue(txtEquipmentType.EditValue); if (o is DataRowView) { DataRowView RowView = o as DataRowView; this.cobEquipmentName.Text = RowView.Row["设备名称"].ToString(); bindEquipment(); } } } }