using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using UAS_MES.DataOperate; using UAS_MES.Entity; using UAS_MES.PublicMethod; namespace UAS_MES.Employee { public partial class Employee_Data : Form { //筛选条件 string condition; DataHelper dh; AutoSizeFormClass asc = new AutoSizeFormClass(); DataTable Dbfind; public Employee_Data() { InitializeComponent(); } private void 人员分组_Load(object sender, EventArgs e) { asc.controllInitializeSize(this); dh = SystemInf.dh; LoadData(); em_name11.KeyDown += ScreenEvent; or_name.KeyDown += ScreenEvent; jo_name.KeyDown += ScreenEvent; em_code11.KeyDown += ScreenEvent; //为DBFind配置Call和Form的名称 or_name.FormName = Name; or_name.TableName = "HrOrg"; or_name.SelectField = "or_code # 组织编号,or_name # 组织名称 "; or_name.SetValueField = new string[] { "or_name" }; or_name.DBTitle = "组织列表"; or_name.DbChange += em_defaultorname1_DbChange; jo_name.FormName = Name; jo_name.TableName = "Job"; jo_name.SelectField = "jo_code # 岗位编号,jo_name # 岗位名称,jo_orgname # 组织名称"; jo_name.SetValueField = new string[] { "jo_name" }; jo_name.DBTitle = "岗位列表"; jo_name.Condition = "jo_orgname like '%" + or_name.Text+"%'"; jo_name.DbChange += em_position1_DbChange; } private void em_position1_DbChange(object sender, EventArgs e) { Dbfind = jo_name.ReturnData; BaseUtil.SetFormValue(this.Controls, Dbfind); } private void em_defaultorname1_DbChange(object sender, EventArgs e) { Dbfind = or_name.ReturnData; BaseUtil.SetFormValue(this.Controls, Dbfind); } private void Screen_Click(object sender, EventArgs e) { LoadData(); } private void LoadData() { string Field = BaseUtil.GetGridViewSelectContent(Employee); condition = BaseUtil.GetScreenSqlCondition(em_name11, em_code11, or_name, jo_name, em_status); pagination1.BindDataToNavigator(Employee, "employee", Field, "em_id", "", condition.Replace("where", "").ToString()); } private void 人员资料_SizeChanged(object sender, EventArgs e) { asc.controlAutoSize(this); } private void ScreenEvent(object senedr, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) Screen.PerformClick(); } private void CLEAR_Click(object sender, EventArgs e) { em_name11.Text = ""; or_name.Text = ""; jo_name.Text = ""; em_code11.Text = ""; } private void normalButton1_Click(object sender, EventArgs e) { ExportFileDialog.Description = "选择导出的路径"; DialogResult result = ExportFileDialog.ShowDialog(); if (result == DialogResult.OK) { ExcelHandler eh = new ExcelHandler(); DataTable dt = ((DataTable)Employee.DataSource).Copy(); dt.Columns.Add("Scanlogin", typeof(string)); for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i]["Scanlogin"] = "("+dt.Rows[i]["em_code"].ToString() +","+Encryption.GETMD5(dt.Rows[i]["em_password"].ToString()) +")"; } for (int i = dt.Columns.Count - 1; i >= 0; i--) { for (int j = 0; j < Employee.Columns.Count; j++) { //去除指定列 if (dt.Columns[i].ColumnName.ToLower().Contains("em_password") || dt.Columns[i].ColumnName.ToLower() == "em_mobile" || dt.Columns[i].ColumnName.ToLower() == "em_email") { dt.Columns.RemoveAt(i); break; } if (dt.Columns[i].ColumnName.ToLower() == Employee.Columns[j].DataPropertyName.ToLower()) { dt.Columns[i].ColumnName = Employee.Columns[j].HeaderText; break; } } } string filename = "人员资料导出-" + DateTime.Now.ToString("yyyyMMddHHmmss"); eh.ExportExcel(dt, ExportFileDialog.SelectedPath, filename); string close = MessageBox.Show(this.ParentForm, "导出成功,是否打开文件", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString(); if (close.ToString() == "Yes") System.Diagnostics.Process.Start(ExportFileDialog.SelectedPath + "\\"+ filename + ".xls"); } } private void normalButton2_Click(object sender, EventArgs e) { string Field = BaseUtil.GetGridViewSelectContent(Employee); condition = BaseUtil.GetScreenSqlCondition(em_name11, em_code11, or_name, jo_name, em_status); DataTable dt = (DataTable)dh.ExecuteSql("select " + Field + " from EMPLOYEE " + condition + "", "select"); ExportFileDialog.Description = "选择导出的路径"; DialogResult result = ExportFileDialog.ShowDialog(); if (result == DialogResult.OK) { ExcelHandler eh = new ExcelHandler(); dt.Columns.Add("扫码登陆数据", typeof(string)); for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i]["扫码登陆数据"] = "(" + dt.Rows[i]["em_code"].ToString() + "," + Encryption.GETMD5(dt.Rows[i]["em_password"].ToString()) + ")"; } for (int i = dt.Columns.Count - 1; i >= 0; i--) { for (int j = 0; j < Employee.Columns.Count; j++) { //去除指定列 if (dt.Columns[i].ColumnName.ToLower().Contains("em_password") || dt.Columns[i].ColumnName.ToLower() == "em_mobile" || dt.Columns[i].ColumnName.ToLower() == "em_email") { dt.Columns.RemoveAt(i); break; } if (dt.Columns[i].ColumnName.ToLower() == Employee.Columns[j].DataPropertyName.ToLower()) { dt.Columns[i].ColumnName = Employee.Columns[j].HeaderText; break; } } } string filename = "人员资料导出-" + DateTime.Now.ToString("yyyyMMddHHmmss"); eh.ExportExcel(dt, ExportFileDialog.SelectedPath, filename); string close = MessageBox.Show(this.ParentForm, "导出成功,是否打开文件", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString(); if (close.ToString() == "Yes") System.Diagnostics.Process.Start(ExportFileDialog.SelectedPath + "\\" + filename + ".xls"); } } } }