using ComponentFactory.Krypton.Toolkit; using NXWMS.Client.Code.Extends; using NXWMS.Client.Model.AppModels.Condition.Base; using NXWMS.Client.Model.AppModels.Result; using NXWMS.Client.Model.AppModels.Result.Base; using NXWMS.Client.Model.CoreModels; using NXWMS.Client.String.Enums; using NXWMS.Commons; using NXWMS.Forms.Base.ChildFrm; using NXWMS.Services; 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; namespace NXWMS.Forms.Base { public partial class frmPallet : KryptonForm { /// 界面最后执行操作 /// private EnumOperation _LastOperation; /// /// 客户端字段排序列表 /// private List _clientFieldOrderList; /// /// 托盘类型列表 /// private List _palletTypeList; /// /// 模板地址 /// private string _reportFolder = Application.StartupPath + "\\ReportMd\\"; private int _selectIndex; private int _selectId; public frmPallet() { InitializeComponent(); InitData(); InitControl(); } protected override CreateParams CreateParams { get { CreateParams cp = base.CreateParams; cp.ExStyle |= 0x02000000; return cp; } } /// /// 数据初始化 /// private void InitData() { _clientFieldOrderList = new List(); _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "PALLET_CODE", FieldDesc = "托盘编码" }); _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "PALLET_NAME", FieldDesc = "托盘名称" }); _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "PalletTypeName", FieldDesc = "托盘类型" }); _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "UsedFlagName", FieldDesc = "使用标识" }); _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "DESCRIBE", FieldDesc = "描述" }); _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "CreateName", FieldDesc = "创建人" }); _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "CREATE_TIME", FieldDesc = "创建时间" }); _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "UpdateName", FieldDesc = "更新人" }); _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "UPDATE_TIME", FieldDesc = "更新时间" }); //获取数据源配置 var result = BaseServices.palletTypeService.GetList(new PalletTypeSearchCondition { IsUsed = true, ItemSQL = "PALLET_TYPE_CODE,PALLET_TYPE_NAME" }); if (result.Status == OperateStatus.Success) { _palletTypeList = result.Data.RowData.ToList(); } } /// /// 控件初始化 /// private void InitControl() { CheckForIllegalCrossThreadCalls = false; //groupOperation.GotFocus += new EventHandler(groupOperation_GostFocus); dataGridView.CellClick += new DataGridViewCellEventHandler(dataGridView_CellClick); dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList), false); //cmbPalletType.DataSource = _palletTypeList; //cmbPalletType.DisplayMember = "PALLET_TYPE_NAME"; //cmbPalletType.ValueMember = "PALLET_TYPE_CODE"; //cmbPalletType.SelectedIndex = -1; _pageIndex = 1; _pageSize = 20; } private void groupOperation_GostFocus(object sender, EventArgs e) { //groupOperation.Values.Heading = _LastOperation.Display(); ////groupOperation.Values.Image = Image.FromFile(_LastOperation.ImagePath()); //groupOperation.Text = $"{ _LastOperation.Display()}数据"; //lbStatusMessage.Visible = true; } private void btnSearch_Click(object sender, EventArgs e) { _pageIndex = 1; var loadfrm = new frmLoading(); loadfrm.Show(); var message = loadfrm.EventCalExec(LoadSearch, this.pageTool.PageIndex, this.pageTool.PageSize); pageTool.DataCount = _totalCount; if (!string.IsNullOrWhiteSpace(message)) { KryptonMessageBox.Show($"查询失败!\r\n{message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); } } private int _pageSize; private int _pageIndex; private int _totalCount; private string LoadSearch(int pageIndex, int pageSize) { var result = BaseServices.palletService.GetList(new PalletSearchCondition { OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId, PalletInfo = txtSearchPalletInfo.Text, IsUsed = chkSearchUse.Checked, PageIndex = pageIndex, PageSize = pageSize }); if (result.Status == OperateStatus.Success) { _totalCount = result.Data.TotalCount; _pageIndex = pageIndex; _pageSize = pageSize; if (result.Data.RowData.Any()) { dataGridView.Columns.Clear(); dataGridView.DataSource = result.Data.RowData.ToList(); dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList)); } else { if (dataGridView.DataSource != null) { dataGridView.DataSource = new List(); } dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList), false); } return string.Empty; } else { return result.Message; } } private void btnAdd_Click(object sender, EventArgs e) { var frm = new ChildFrm.FrmPalletEdit(); frm.operation = EnumOperation.Add; frm.PalletTypeList = this._palletTypeList; frm.InitControl(); if (frm.ShowDialog() == DialogResult.OK) { this.btnSearch_Click(null, null); } //_selectId = 0; //tableLayoutPanelInput.SetGroupControlsEmpty(dataGridView); //richDescibe.Text = ""; //_LastOperation = EnumOperation.Add; //txtPalletCode.Enabled = true; //groupOperation.Visible = true; //groupOperation.Focus(); } private void SelectInit() { _selectIndex = dataGridView.SelectedRows[0].Index; if (_selectIndex >= 0) { _selectId = Convert.ToInt32(dataGridView.Rows[_selectIndex].Cells[_PrimaryKey].Value); } } private void btnEdit_Click(object sender, EventArgs e) { dataGridView_CellDoubleClick(null, null); } private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0 && e.ColumnIndex == 0) { if (this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value == null) { if (!_CheckRowIdList.Where(s => s == dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString()).Any()) { _CheckRowIdList.Add(dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString()); } this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = 1; } else if (dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() == "1") { if (_CheckRowIdList.Where(s => s == dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString()).Any()) { _CheckRowIdList.Remove(dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString()); } this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = 0; } else { if (!_CheckRowIdList.Where(s => s == dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString()).Any()) { _CheckRowIdList.Add(dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString()); } this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = 1; } } } /// /// 选择行主键列表 /// private List _CheckRowIdList = new List(); /// /// 当前页面操作的主键 /// private string _PrimaryKey = "PALLET_ID"; private void btnRemove_Click(object sender, EventArgs e) { if (_CheckRowIdList.Count == 0) { return; } if (KryptonMessageBox.Show($"确认删除选中数据?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { _LastOperation = EnumOperation.Remove; var editResult = BaseServices.palletService.Deleted(new PalletCondition { OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId, Ids = string.Join(",", _CheckRowIdList) }); if (editResult.Status == OperateStatus.Success) { KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); //groupOperation.Visible = false; btnSearch_Click(null, null); } } } //private void btnSave_Click(object sender, EventArgs e) //{ // if (string.IsNullOrWhiteSpace(txtPalletCode.Text)) // { // KryptonMessageBox.Show($"请输入托盘编码!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); // return; // } // if (string.IsNullOrWhiteSpace(txtPalletName.Text)) // { // KryptonMessageBox.Show($"请输入托盘名称!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); // return; // } // if (string.IsNullOrWhiteSpace(cmbPalletType.Text)) // { // KryptonMessageBox.Show($"请选择托盘类型!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); // return; // } // switch (_LastOperation) // { // case EnumOperation.Add: // var addResult = BaseServices.palletService.Add(new PalletCondition // { // OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId, // IsUsed = chkUse.Checked, // Describe = richDescibe.Text, // PalletCode = txtPalletCode.Text, // PalletName = txtPalletName.Text, // PalletType = cmbPalletType.SelectedValue == null ? "" : // cmbPalletType.SelectedValue.ToString(), // }); ; // if (addResult.Status == OperateStatus.Success) // { // KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); // InitControl(); // groupOperation.Visible = false; // btnSearch_Click(null, null); // dataGridView.ClearSelection(); // } // else // { // KryptonMessageBox.Show($"操作失败!\r\n{addResult.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); // } // break; // case EnumOperation.Edit: // var editResult = BaseServices.palletService.Edit(new PalletCondition // { // OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId, // IsUsed = chkUse.Checked, // Describe = richDescibe.Text, // PalletCode = txtPalletCode.Text, // PalletName = txtPalletName.Text, // PalletType = cmbPalletType.SelectedValue == null ? "" : // cmbPalletType.SelectedValue.ToString(), // Id = _selectId // }); // if (editResult.Status == OperateStatus.Success) // { // KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); // InitControl(); // groupOperation.Visible = false; // btnSearch_Click(null, null); // dataGridView.ClearSelection(); // } // else // { // KryptonMessageBox.Show($"操作失败!\r\n{editResult.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); // } // break; // } //} private void dataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { SelectInit(); if (_selectIndex >= 0) { var frm = new ChildFrm.FrmPalletEdit(); frm.operation = EnumOperation.Edit; frm.PalletTypeList = this._palletTypeList; frm.Id = this._selectId; frm.InitControl(); frm.tableLayoutPanelInput.SetGroupControls(dataGridView, dataGridView.Rows[_selectIndex]); if (frm.ShowDialog() == DialogResult.OK) { this.btnSearch_Click(null, null); } //_LastOperation = EnumOperation.Edit; //tableLayoutPanelInput.SetGroupControls(dataGridView, dataGridView.Rows[_selectIndex]); //richDescibe.Text = dataGridView.Rows[_selectIndex].Cells["DESCRIBE"].Value == null ? "" : // dataGridView.Rows[_selectIndex].Cells["DESCRIBE"].Value.ToString(); //txtPalletCode.Enabled = false; //groupOperation.Visible = true; //groupOperation.Focus(); } } private Point mouse_offset; private void groupOperation_MouseDown(object sender, MouseEventArgs e) { mouse_offset = new Point(-e.X, -e.Y); } private void groupOperation_MouseMove(object sender, MouseEventArgs e) { ((Control)sender).Cursor = Cursors.Arrow; if (e.Button == MouseButtons.Left) { Point mousePos = MousePosition; mousePos.Offset(mouse_offset.X, mouse_offset.Y); ((Control)sender).Location = ((Control)sender).Parent.PointToClient(mousePos); Application.DoEvents(); } } private void btnExit_Click(object sender, EventArgs e) { if (KryptonMessageBox.Show($"确认退出 {_LastOperation.Display()}数据操作?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { //groupOperation.Visible = false; } else { //groupOperation.Visible = true; //groupOperation.Focus(); } } private void pageTool_OnPageChange(int PageIndex, int PageSzie) { this.btnSearch_Click(null, null); } private void kryptonButton1_Click(object sender, EventArgs e) { kryptonButton1.Enabled = false; try { int ids = 0; DataTable dt = new DataTable(); DataColumn dc = new DataColumn("Ids"); dt.Columns.Add(dc); dc = new DataColumn("PalletCode"); dt.Columns.Add(dc); foreach (DataGridViewRow item in dataGridView.Rows) { DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)item.Cells[0]; object obj = checkCell.EditedFormattedValue; if (Convert.ToBoolean(obj)) { ids++; DataRow dr = dt.NewRow(); dr["Ids"] = ids; dr["PalletCode"] = item.Cells["PALLET_CODE"].Value; dt.Rows.Add(dr); } } if (ids > 0) { DataSet dts = new DataSet(); dts.Tables.Add(dt); FastReport.Report report = new FastReport.Report(); string filename = _reportFolder + "托盘条码.frx"; report.Load(filename); report.RegisterData(dts); report.Prepare(); report.PrintSettings.ShowDialog = false; report.Print(); report.Clear(); KryptonMessageBox.Show("打印成功!"); } else { KryptonMessageBox.Show("请勾选要打印的托盘数据行!"); } } catch (Exception ex) { KryptonMessageBox.Show($"打印托盘条码发生异常:{ex.Message}"); } kryptonButton1.Enabled = true; } private void kryptonButton2_Click(object sender, EventArgs e) { FrmBatchPrint frm = new FrmBatchPrint(); frm.ShowDialog(); } } }