|
|
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.DAL; using ICSSoft.Frame.Data.BLL; using ICSSoft.Frame.Data.Entity; using System.Text.RegularExpressions; using System.Runtime.InteropServices;
namespace ICSSoft.Frame.APP { public partial class FormICSPallet : DevExpress.XtraEditors.XtraForm { string OPID; private string PalletCode; [DllImport("user32.dll", EntryPoint = "GetWindowLong", CharSet = CharSet.Auto)] public static extern int GetWindowLong(HandleRef hWnd, int nIndex);
[DllImport("user32.dll", EntryPoint = "SetWindowLong", CharSet = CharSet.Auto)] public static extern IntPtr SetWindowLong(HandleRef hWnd, int nIndex, int dwNewLong);
DataSet ds = new DataSet(); private DataTable BodySource = null; private string whereStr = ""; private string sqltxt = ""; private string sqlconn = ""; String guid = AppConfig.GetGuid(); private DataTable dataSource = null; private DataTable dttwo;
private DataTable dtthree; private DataSet dstwo;
protected override CreateParams CreateParams { get { const int WS_MINIMIZEBOX = 0x00020000; // Winuser.h中定义
CreateParams cp = base.CreateParams; cp.Style = cp.Style | WS_MINIMIZEBOX; // 允许最小化操作
return cp; } }
#region 构造函数
public FormICSPallet() { InitializeComponent(); this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height); this.WindowState = FormWindowState.Maximized; } #endregion
#region 子表
public DataTable ThreeTable() { string sql = @"select '' as selecttwo,
a.ID as ID, a.PalletCode as PalletCode, a.LotNO as LotNO, c.INVCODE as INVCODE, c.INVNAME as INVNAME, b.LOTQTY as LOTQTY, b.TYPE as TYPE, a.WorkPoint as WorkPoint, a.MuserCode as MuserCode, a.MuserName as MuserName, a.Mtime as Mtime, a.Free1 as Free1 from ICSPalletLotNO a left join ICSITEMLot b on a.LotNO = b.LotNO AND a.WorkPoint=b.WorkPoint left join ICSINVENTORY c on b.ItemCode = c.INVCODE and b.WorkPoint=c.WorkPoint ";
if (whereStr != "") { sql = sql + " WHERE 1=1 " + whereStr; }
sql = string.Format(sql); DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0]; return data; } #endregion
#region 操作权限
public DataTable RightOfExute() { DataTable rData = new DataTable(); rData.Columns.Add("BtnName"); rData.Columns.Add("ActionName"); //查看权限(必须有)
DataRow seeRow = rData.NewRow(); seeRow["BtnName"] = "see"; seeRow["ActionName"] = "查看"; rData.Rows.Add(seeRow); foreach (Control ctr in panelControl3.Controls) { if (ctr.Name == btnFilter.Name || ctr.Name == btnConfig.Name || ctr.Name == btnSelectAll.Name || ctr.Name == btnCancelAll.Name || ctr.Name == btnRefresh.Name || ctr.Name == btnExit.Name || ctr.Name == lblTitle.Name || ctr.Name == btnClose.Name) continue; DataRow dr = rData.NewRow(); dr["BtnName"] = ctr.Name; dr["ActionName"] = ctr.Text; rData.Rows.Add(dr); } //List<Control> ControlList = new List<Control>();
//ControlList.Add(btnCreate);
//ControlList.Add(btnModify);
//ControlList.Add(btnDel);
//ControlList.Add(btnOutPut);
//foreach (Control ctr in ControlList)
//{
// if (ctr.GetType() == typeof(SimpleButton))
// {
// DataRow dr = rData.NewRow();
// dr["BtnName"] = ctr.Name;
// dr["ActionName"] = ctr.Text;
// rData.Rows.Add(dr);
// }
//}
rData.AcceptChanges(); return rData; } public DataTable RightOfData()// 数据权限
{ DataTable rData = new DataTable(); rData.Columns.Add("BodyName"); rData.Columns.Add("ControlName"); rData.Columns.Add("ControlCaption");
rData.AcceptChanges(); return rData; } #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) { FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name)); filter.OldTempTableName = tempTableName; if (filter.ShowDialog() == DialogResult.OK) { DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等..."); try { _wait.Show(); dataSource = null; BodySource = null; ds.Reset(); tempTableName = filter.NewTempTableName; sqltxt = filter.SqlText; string[] wheres = Regex.Split(sqltxt, "1=1", RegexOptions.IgnoreCase); if (wheres.Length >= 2 && wheres[1] != "\r\n") { whereStr = wheres[1]; int index = whereStr.IndexOf("GROUP BY"); if (index > 0) whereStr = whereStr.Substring(0, index); if (whereStr == "\r\n") whereStr = ""; } else { whereStr = ""; } sqlconn = filter.FilterConnectString; dataSource = filter.FilterData.Tables[0].Copy(); BodySource = ThreeTable().Copy(); dataSource.TableName = "Hand"; BodySource.TableName = "Body"; if (ds != null) { ds.Tables.Add(dataSource); ds.Tables.Add(BodySource); } DataRelation dr = new DataRelation("详情", new DataColumn[] { ds.Tables["Hand"].Columns["PalletCode"] }, new DataColumn[] { ds.Tables["Body"].Columns["PalletCode"] }, false); ds.Relations.Add(dr); grdDetail.DataSource = dataSource; grvDetail.BestFitColumns(); gridView1.BestFitColumns(); rptPage.RecordNum = dataSource.Rows.Count;
rptPage.PageSize = 100; rptPage.PageIndex = 1;
//rptPage.ReLoad();
_wait.Close();
} catch (Exception ex) { MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error); _wait.Close(); }
} } #endregion
#region 绑定数据源
private void btnConfig_Click(object sender, EventArgs e) { if (AppConfig.UserCode.ToLower() != "demo") { ICSBaseSimpleCode.AppshowMessageBox("您没有权限设置数据源,请联系软件提供商!"); return; } FormDataSource fdata = new FormDataSource(AppConfig.GetMenuId(this.Tag.ToString()), btnConfig.Name); fdata.ShowDialog(); } #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 FormContainerManager_FormClosing(object sender, FormClosingEventArgs e) { AppConfig.DropTemTable(tempTableName); } #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, colselectone, "Y"); } } #endregion
#region 全消
private void btnCancelAll_Click(object sender, EventArgs e) { grvDetail.PostEditor(); this.Validate(); for (int i = 0; i < grvDetail.RowCount; i++) { grvDetail.SetRowCellValue(i, colselectone, ""); } } #endregion
#region 双击
private void grvDetail_DoubleClick(object sender, EventArgs e) { if (grvDetail.FocusedRowHandle < 0) { return; } if (grvDetail.FocusedColumn == colselectone) { if (grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colselectone).ToString() == "") { grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colselectone, "Y"); } else { grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colselectone, ""); }
} } #endregion
#region 双击子表
private void gridView1_DoubleClick(object sender, EventArgs e) { if (gridView1.FocusedRowHandle < 0) { return; } if (gridView1.FocusedColumn.Name == colselecttwo.Name) { if (gridView1.GetRowCellValue(gridView1.FocusedRowHandle, colselecttwo).ToString() == "") { gridView1.SetRowCellValue(gridView1.FocusedRowHandle, colselecttwo, "Y"); } else { gridView1.SetRowCellValue(gridView1.FocusedRowHandle, colselecttwo, ""); }
} } #endregion
#region 删除
private void btnDel_Click(object sender, EventArgs e) { SimpleButton btntemp = (SimpleButton)sender; if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false) { ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!"); return; }
List<ICSPallet> item2routeList = new List<ICSPallet>(); List<string> routecodeList = new List<string>(); for (int i = 0; i < grvDetail.RowCount; i++) { if (grvDetail.GetRowCellValue(i, colselectone).ToString() == "Y") { ICSPallet item2route = new ICSPallet(); item2route.PalletCode = grvDetail.GetRowCellValue(i, colPalletCode).ToString(); item2routeList.Add(item2route); } } if (item2routeList.Count == 0) {
ICSBaseSimpleCode.AppshowMessageBox("请选择数据"); return;
} if (ICSBaseSimpleCode.AppshowMessageBoxRepose("确定删除吗?删除后无法恢复,确定吗?") != DialogResult.OK) { btnCancelAll_Click(sender, e); return; } ICSPalletBLL.deleteInfo(item2routeList, AppConfig.AppConnectString); ICSBaseSimpleCode.AppshowMessageBox("删除成功");
btnRefresh_Click(null, null); }
#endregion
#region 刷新
private void btnRefresh_Click(object sender, EventArgs e) { if (sqlconn == null || sqlconn == "") { return; }
DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等..."); try { _wait.Show(); dataSource = null; BodySource = null; ds.Reset(); 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(sqlconn, CommandType.Text, sqltxt).Tables[0].Copy(); BodySource = ThreeTable().Copy(); dataSource.TableName = "Hand"; BodySource.TableName = "Body"; if (ds != null) { ds.Tables.Add(dataSource); ds.Tables.Add(BodySource); } DataRelation dr = new DataRelation("详情", new DataColumn[] { ds.Tables["Hand"].Columns["PalletCode"] }, new DataColumn[] { ds.Tables["Body"].Columns["PalletCode"] }); ds.Relations.Add(dr); grdDetail.DataSource = dataSource; grvDetail.BestFitColumns(); gridView1.BestFitColumns(); rptPage.RecordNum = dataSource.Rows.Count; rptPage.PageSize = 100; rptPage.PageIndex = 1; //rptPage.ReLoad();
_wait.Close(); } catch (Exception ex) { MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error); _wait.Close(); } }
#endregion
private void ICSItemLot_FormClosing(object sender, FormClosingEventArgs e) { AppConfig.DropTemTable(tempTableName); }
private void FormICSPallet_Load(object sender, EventArgs e) { //无标题窗体右键菜单
int WS_SYSMENU = 0x00080000; // 系统菜单
int WS_MINIMIZEBOX = 0x20000; // 最大最小化按钮
int windowLong = (GetWindowLong(new HandleRef(this, this.Handle), -16)); SetWindowLong(new HandleRef(this, this.Handle), -16, windowLong | WS_SYSMENU | WS_MINIMIZEBOX); //dstwo.Reset();
//dttwo = null;
//dtthree = null;
btnFilter_Click(sender, e); }
private void grvDetail_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e) {
if (e.RowHandle >= 0 && e.Column.FieldName == "DCTCODE") { //e.DisplayText = FormatHelper.
e.CellValue = "cccc"; } }
private void grvDetail_MasterRowExpanded(object sender, DevExpress.XtraGrid.Views.Grid.CustomMasterRowEventArgs e) { gridView1 = grvDetail.GetDetailView(e.RowHandle, e.RelationIndex) as DevExpress.XtraGrid.Views.Grid.GridView; gridView1.BestFitColumns(); }
#region 打印
private void btnPrint_Click(object sender, EventArgs e) { SimpleButton btntemp = (SimpleButton)sender; if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false) { ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!"); return; }
if (grvDetail.FocusedRowHandle < 0) { return; }
try { List<PrintPara> barCodeList = new List<PrintPara>(); for (int i = 0; i < grvDetail.RowCount; i++) { if (grvDetail.GetRowCellValue(i, colselectone).ToString() == "Y") {
string barCode = grvDetail.GetRowCellValue(i, colPalletCode).ToString(); PrintPara printInfo = new PrintPara(); printInfo.PrintKey = "PalletCode"; printInfo.PrintValues = new object[] { barCode }; barCodeList.Add(printInfo); } }
if (barCodeList.Count == 0) { ICSBaseSimpleCode.AppshowMessageBox("没有选择数据"); return; }
FormPrintDialog printDialog = new FormPrintDialog("013", "ICSProduct", barCodeList, false, null); printDialog.ShowDialog(); } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.Message); } } #endregion
#region 查询
private void FormDCT_Load(object sender, EventArgs e) {
string sql = @"select ''as [Select],
ID as ID, PalletCode as PalletCode, LotNO as LotNO, WorkPoint as WorkPoint, MuserCode as MuserCode, MuserName as MuserName, Mtime as Mtime from ICSPalletLotNO where PalletCode='{0}' ";
sql = string.Format(sql, PalletCode); DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0]; grdDetail.DataSource = dt; grvDetail.BestFitColumns(); } #endregion
#region 关联批次
private void btnTBLOP2RES_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; string PalletCode = ""; for (int i = 0; i < grvDetail.RowCount; i++) { if (grvDetail.GetRowCellValue(i, colselectone).ToString() == "Y") { PalletCode = grvDetail.GetRowCellValue(i, colPalletCode).ToString(); count++; } } if (count != 1) { ICSBaseSimpleCode.AppshowMessageBox("请选择要关联的数据, 且只能选择一条进行操作!"); return; } string sql = @"SELECT
a.[LotNO] AS '产品批次' ,b.INVCODE as '物料编号' ,a.[MuserName] AS '维护人' FROM ICSITEMLot a LEFT JOIN ICSINVENTORY b ON a.ItemCode=b.INVCODE AND a.WorkPoint=b.WorkPoint WHERE a.LotNO NOT IN (SELECT LotNO from dbo.ICSPalletLotNO) and 1=1 GROUP BY a.LotNO,a.[MuserName],b.INVCODE";
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 = true; reForm.RowIndexWidth = 35; reForm.HideCols.Add("ID"); reForm.FormWidth = 500; reForm.FormHeight = 500; reForm.FilterKey = ""; if (reForm.ShowDialog() == DialogResult.OK) { DataTable retData = reForm.ReturnData; if (retData.Rows.Count == 0) { ICSBaseSimpleCode.AppshowMessageBox("请选择数据!"); return; } string invcode = ""; foreach (DataRow dr in retData.Rows) { if (invcode == "") { invcode = dr["存货编码"].ToString(); } else if (invcode != dr["存货编码"].ToString()) { ICSBaseSimpleCode.AppshowMessageBox("请选择数据!"); return; }
} DataRow[] drs = BodySource.Select("PalletCode='" + PalletCode + "'"); if (drs.Length > 0) { if (invcode != drs[0]["INVCODE"].ToString()) { ICSBaseSimpleCode.AppshowMessageBox("请选择物料编号相同的批次入箱!"); return; } } ICSPalletBLL.AddandEdit(retData,PalletCode, AppConfig.AppConnectString); ICSBaseSimpleCode.AppshowMessageBox(0, "保存成功"); FormDCT_Load(null, null); btnRefresh_Click(null, null); } } #endregion
#region 新增
private void btnADD_Click(object sender, EventArgs e) { SimpleButton btntemp = (SimpleButton)sender; if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false) { ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!"); return; } FormICSPalletAdd add = new FormICSPalletAdd(); add.ShowDialog(); btnRefresh_Click(null, null); } #endregion
#region 删除批次
private void btnLotNo_Click(object sender, EventArgs e) { int Count = 0; gridView1.PostEditor(); this.Validate(); if (gridView1.RowCount == 0) return; SimpleButton btntemp = (SimpleButton)sender; if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false) { ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!"); return; } for (int i = 0; i < gridView1.RowCount; i++) { if (gridView1.GetRowCellValue(i, colselecttwo).ToString() == "Y") { Count++; } } if (Count == 0) { ICSBaseSimpleCode.AppshowMessageBox("请选择数据!"); return; } if (ICSBaseSimpleCode.AppshowMessageBoxRepose("确定删除该批次吗?批次删除后无法恢复,确定吗?") != DialogResult.OK) { return; } else { try { for (int i = 0; i < gridView1.RowCount; i++) { if (gridView1.GetRowCellValue(i, colselecttwo).ToString() == "Y") { FormICSPalletAdd add = new FormICSPalletAdd(gridView1.GetRowCellValue(i, colPallet2Code).ToString(), gridView1.GetRowCellValue(i, colLotNO).ToString(), gridView1.GetRowCellValue(i, MuserCode).ToString());
} } ICSBaseSimpleCode.AppshowMessageBox(0, "删除成功"); btnRefresh_Click(null, null); } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.Message); return; } } } #endregion
}
}
|