|
|
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.Frame.User.BLL; using ICSSoft.Base.Language.Tool; using ICSSoft.Base.UserControl.MessageControl; using System.Data.SqlClient; using ICSSoft.Base.Config.AppConfig; using ICSSoft.Base.Report.Filter; using ICSSoft.Base.Config.DBHelper; using ICSSoft.Base.UserControl.FormControl; using ICSSoft.Base.ReferForm.AppReferForm; using ICSSoft.Base.Lable.PrintTool; using ICSSoft.Frame.Data.Entity; using ICSSoft.Frame.Data.BLL; using System.Linq; //using ZHCSoft.AntiwearValveExpanded.DAL;
//using ZHCSoft.AntiwearValveExpanded.BLL;
//using ZHCSoft.AntiwearValveExpanded.Entity;
namespace ICSSoft.Frame.APP { public partial class FormICSOP2UserAdds : DevExpress.XtraEditors.XtraForm { private string sqltxt = ""; private string sqlconn = ""; String guid = AppConfig.GetGuid(); private DataTable dataSource = null; private DataTable dataSource1 = null; Dictionary<string, string> UserList = new Dictionary<string, string>(); Dictionary<string, string> OPList = new Dictionary<string, string>(); Dictionary<string, string> OPIDList = new Dictionary<string, string>();
#region 构造函数
public FormICSOP2UserAdds() { InitializeComponent(); this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height); this.WindowState = FormWindowState.Maximized; BlindUsersource(""); BlindOPsource("");
} #endregion
#region 退出
private void btnClose_Click(object sender, EventArgs e) { AppConfig.CloseFormShow(this.Text); this.Close(); }
private void btnExit_Click(object sender, EventArgs e) { AppConfig.CloseFormShow(this.Text); this.Close(); }
#endregion
#region 移动窗体
private const int WM_NCHITTEST = 0x84; private const int HTCLIENT = 0x1; private const int HTCAPTION = 0x2; //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
//系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
//假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
//同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
//重写窗体,使窗体可以不通过自带标题栏实现移动
protected override void WndProc(ref Message m) {
//当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
//当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
//这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
//注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
switch (m.Msg) { case WM_NCHITTEST: base.WndProc(ref m); if ((int)m.Result == HTCLIENT) m.Result = (IntPtr)HTCAPTION; return; } //拦截双击标题栏、移动窗体的系统消息
if (m.Msg != 0xA3) { base.WndProc(ref m); }
} #endregion
#region 列表
private void grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e) { if (e.Info.IsRowIndicator && e.RowHandle >= 0) e.Info.DisplayText = (e.RowHandle + 1).ToString();
} #endregion
#region 过滤
private string tempTableName = ""; private void btnFilter_Click(object sender, EventArgs e) {
DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等..."); try {
grvDetail.BestFitColumns(); rptPage.RecordNum = dataSource.Rows.Count; rptPage.PageSize = 500; rptPage.PageIndex = 1; rptPage.ReLoad(); _wait.Close();
} catch (Exception ex) { MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error); _wait.Close(); }
} #endregion
#region 分页
private void rptPage_PageIndexChanged(object Sender, EventArgs e) {
DataTable data = AppConfig.GetPageData(dataSource, rptPage.PageIndex, rptPage.PageSize).Copy(); //DataTable data = AppConfig.GetPageDataByDb(tempTableName, "pagerowindex", rptPage.PageSize, rptPage.PageIndex, dataSource.Rows.Count);
grdDetail.DataSource = data; } #endregion
#region 全选
private void btnSelectAll_Click(object sender, EventArgs e) { grvDetail.PostEditor(); this.Validate(); for (int i = 0; i < grvDetail.RowCount; i++) { grvDetail.SetRowCellValue(i, colisSelect, "Y"); } } #endregion
#region 全消
private void btnCancelAll_Click(object sender, EventArgs e) {
UserList.Clear(); OPList.Clear(); OPIDList.Clear(); BlindUsersource(""); BlindOPsource(""); usertextlist.Clear(); optextlist.Clear(); } #endregion
#region 导出
private void btnOutPut_Click(object sender, EventArgs e) { try { FormOutExcel foe = new FormOutExcel(this.Tag.ToString(), grdDetail); foe.ShowDialog(); } catch (Exception ex) { MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error); } //FormOutExcel foe = new FormOutExcel();
//if (foe.ShowDialog() == DialogResult.OK)
//{
// try
// {
// string outtype = foe._OutType;
// string exceltype = foe._ExcelType;
// string filename = foe._FileName;
// string url = foe._Url;
// string sheetname = foe._SheetName;
// if (outtype.ToLower() == "excel")
// {
// DevExpress.XtraPrinting.XlsExportOptions op = new DevExpress.XtraPrinting.XlsExportOptions();
// op.SheetName = sheetname;
// grdDetail.MainView.ExportToXls((url + "\\" + filename + (exceltype == "2003" ? ".xls" : ".xlsx")), op);
// }
// else
// {
// grdDetail.MainView.ExportToPdf(url + "\\" + filename + ".pdf");
// }
// MessageBox.Show("导出成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
// }
// catch (Exception ex)
// {
// MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
// }
//}
} #endregion
#region 刷新
private void btnRefresh_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(sqlconn)) return; DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等..."); try { //_wait.Show();
//FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name), false);
//filter.OldTempTableName = tempTableName;
////tempTableName = filter.NewTempTableName;
////DataTable data = DBHelper.ExecuteDataset(AppConfig.FrameConnectString, CommandType.Text, "select * from " + tempTableName).Tables[0];
//dataSource = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sqltxt).Tables[0];
//grdDetail.DataSource = dataSource;
//grvDetail.BestFitColumns();
rptPage.RecordNum = dataSource.Rows.Count; rptPage.PageIndex = 1; rptPage.ReLoad(); _wait.Close(); } catch (Exception ex) { MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error); _wait.Close(); } }
#endregion
#region 新增
private void btnCreate_Click(object sender, EventArgs e) { SimpleButton btntemp = (SimpleButton)sender; if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false) { ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!"); return; } //FormICSOP2UserAdd add = new FormICSOP2UserAdd();
//add.ShowDialog();
//btnRefresh_Click(null, null);
} #endregion
private void ICSItemLot_FormClosing(object sender, FormClosingEventArgs e) { AppConfig.DropTemTable(tempTableName); }
private void FormICSITEM2ROUTE_Load(object sender, EventArgs e) { btnFilter_Click(sender, e); }
private void grvDetail_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e) {
//if (e.RowHandle >= 0 && e.Column.FieldName == "isSelect" && UserList.Contains(grvDetail.GetFocusedRowCellValue(colUSERCODE).ToString()))
//{
// e.CellValue = "Y";
// e.Handled = true;
//}
}
private void btnLinkOP_Click(object sender, EventArgs e) { SimpleButton btntemp = (SimpleButton)sender; if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false) { ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!"); return; } int count = 0; for (int i = 0; i < grvDetail.RowCount; i++) { if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y") { count++; } } if (count != 1) { ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!"); return; } try { string itemCode; string routeCode; for (int i = 0; i < grvDetail.RowCount; i++) { if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y") { itemCode = grvDetail.GetRowCellValue(i, COLOPCODE).ToString(); routeCode = grvDetail.GetRowCellValue(i, colUSERCODE).ToString(); FormICSITEMROUTE2OP linkop = new FormICSITEMROUTE2OP(itemCode, routeCode); linkop.ShowDialog(); }
} btnRefresh_Click(null, null); } catch (Exception ex) { //throw ex;
ICSBaseSimpleCode.AppshowMessageBox(ex.Message); }
}
private void gridView1_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e) { //if (e.Info.IsRowIndicator && e.RowHandle >= 0)
// e.Info.DisplayText = (e.RowHandle + 1).ToString();
}
private void grvDetail_Click(object sender, EventArgs e) { if (grvDetail.FocusedRowHandle < 0) { return; } if (grvDetail.FocusedColumn == colisSelect) { if (grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colisSelect).ToString() == "") { grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "Y"); string usercode = grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colUSERCODE).ToString(); if (!UserList.Keys.Contains(usercode)) UserList.Add(usercode, grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colUSERName).ToString());
} else { grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "");
string usercode = grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colUSERCODE).ToString(); if (UserList.Keys.Contains(usercode)) UserList.Remove(usercode); } usertextlist.Clear(); foreach (string a in UserList.Keys) {
usertextlist.AppendText(a + "-" + UserList[a].ToString() + "" + "\r\n"); }
} }
private void gridView1_Click(object sender, EventArgs e) { if (gridView1.FocusedRowHandle < 0) { return; } if (gridView1.FocusedColumn == isselect) { if (gridView1.GetRowCellValue(gridView1.FocusedRowHandle, isselect).ToString() == "") { gridView1.SetRowCellValue(gridView1.FocusedRowHandle, isselect, "Y"); string opcode = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, COLOPCODE).ToString(); if (!OPList.Keys.Contains(opcode)) { OPList.Add(opcode, gridView1.GetRowCellValue(gridView1.FocusedRowHandle, COLOPDESC).ToString()); OPIDList.Add(opcode, gridView1.GetRowCellValue(gridView1.FocusedRowHandle, COLOPID).ToString()); } } else { gridView1.SetRowCellValue(gridView1.FocusedRowHandle, isselect, ""); string opcode = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, COLOPCODE).ToString(); if (OPList.Keys.Contains(opcode)) { OPList.Remove(opcode); OPIDList.Remove(opcode);
}
} optextlist.Clear(); foreach (string a in OPList.Keys) {
optextlist.AppendText(a + "-" + OPList[a].ToString() + "" + "\r\n"); }
} }
private void richTextBox1_TextChanged(object sender, EventArgs e) {
}
private void BlindUsersource(string UserName) { string sql = "select distinct '' as isSelect,USERCODE,USERNAME FROM Sys_User where STARTFLAG='1' AND 1=1"; if (!string.IsNullOrEmpty(UserName)) { sql += " and UserName like '%" + UserName + "%'"; } DataTable table = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0]; foreach (DataRow row in table.AsEnumerable().Where(a => UserList.Keys.Contains(a["USERCODE"].ToString())).ToList()) { row["isSelect"] = "Y"; } table.AcceptChanges();
grdDetail.DataSource = table; grvDetail.BestFitColumns(); dataSource = table; rptPage.RecordNum = table.Rows.Count; rptPage.PageIndex = 1; rptPage.ReLoad();
}
private void BlindOPsource(string Opname) { string sql = "select distinct '' as isSelect, OPCODE,OPDESC,ID AS OPID FROM ICSOP where 1=1"; if (!string.IsNullOrEmpty(Opname)) { sql += " and OPDESC like '%" + Opname + "%'"; } DataTable table = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0]; foreach (DataRow row in table.AsEnumerable().Where(a => OPList.Keys.Contains(a["OPCODE"].ToString())).ToList()) { row["isSelect"] = "Y"; } table.AcceptChanges();
gridControl1.DataSource = table; gridView1.BestFitColumns(); dataSource1 = table;
rptPage1.RecordNum = table.Rows.Count; rptPage1.PageIndex = 1; rptPage1.ReLoad();
}
private void simpleButton1_Click(object sender, EventArgs e) { BlindUsersource(txtuser.Text); }
private void simpleButton2_Click(object sender, EventArgs e) { BlindOPsource(textop.Text); }
private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e) { //if (e.RowHandle >= 0 && e.Column.FieldName == "isSelect" && OPList.Contains(gridView1.GetFocusedRowCellValue(COLOPCODE).ToString()))
//{
// e.CellValue = "Y";
//}
}
private void rptPage_PageIndexChanged_1(object Sender, EventArgs e) { DataTable data = AppConfig.GetPageData(dataSource, rptPage.PageIndex, rptPage.PageSize).Copy(); //DataTable data = AppConfig.GetPageDataByDb(tempTableName, "pagerowindex", rptPage.PageSize, rptPage.PageIndex, dataSource.Rows.Count);
grdDetail.DataSource = data; }
private void rptPage1_PageIndexChanged(object Sender, EventArgs e) { DataTable data = AppConfig.GetPageData(dataSource1, rptPage1.PageIndex, rptPage1.PageSize).Copy(); //DataTable data = AppConfig.GetPageDataByDb(tempTableName, "pagerowindex", rptPage.PageSize, rptPage.PageIndex, dataSource.Rows.Count);
gridControl1.DataSource = data; }
private void btnCreate_Click_1(object sender, EventArgs e) { try { if (UserList.Count <= 0 || OPList.Count <= 0) throw new Exception("请选择要绑定的人员或者工序!");
List<FormICSOP2UserUIModel> list = new List<FormICSOP2UserUIModel>();
foreach (String usercode in UserList.Keys) { foreach (string opcode in OPList.Keys) { FormICSOP2UserUIModel test = new FormICSOP2UserUIModel(); test.OPCODE = opcode; test.op = new FormICSOPUIModel(); test.op.ID =OPIDList[opcode].ToString() ; test.op.OPCODE = opcode; test.user = new FormICSUserUIModel(); test.USERCODE = usercode;; test.user.UserCode = usercode; test.user.UserName = UserList[usercode].ToString() ; test.MUSER = AppConfig.UserId; test.MUSERName = AppConfig.UserName; test.MTIME = DateTime.Now; test.WorkPoint = AppConfig.WorkPointCode; test.EATTRIBUTE1 = ""; test.Level = "";
list.Add(test); }
}
string mes=ICSOP2UserBLL.AddList(list,AppConfig.AppConnectString); if (string.IsNullOrEmpty(mes)) ICSBaseSimpleCode.AppshowMessageBox("操作成功!"); else throw new Exception(mes);
btnCancelAll_Click(null,null);
} catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.Message); //btnCancelAll_Click(null, null);
}
} }
}
|