You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lj_plc/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/MaterialManage/MaterialBarcodeAction.cs

87 lines
3.2 KiB
C#

using DevExpress.XtraEditors;
using DevExpress.XtraReports.UI;
using ICSharpCode.Core;
using Mesnac.Action.Base;
using Mesnac.Action.ChemicalWeighing.Entity;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Printing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Mesnac.Action.ChemicalWeighing.MaterialManage
{
class MaterialBarcodeAction : ChemicalWeighingAction, IAction
{
#region 字段定义
private RuntimeParameter _runtime;
private DbMCControl _clientGridControl = null; //物料信息控件
private DataGridView clientGridView = null;
#endregion
public void Run(RuntimeParameter runtime)
{
base.RunIni(runtime); //必须调用
this._runtime = runtime;
DbMCControl materialDGV = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "Pmt_material").FirstOrDefault();
if (materialDGV == null)
{
ICSharpCode.Core.LoggingService<MaterialBarcodeAction>.Error("预览物料条码信息失败:未找到控件");
return;
}
this._clientGridControl = materialDGV;
this.clientGridView = _clientGridControl.BaseControl as DataGridView;
this.DoWork();
}
/// <summary>
/// 预览物料信息条码
/// </summary>
protected void DoWork()
{
this._runtime.BaseControl.MCEnabled = false;
try
{
if (clientGridView.SelectedRows.Count >= 1)
{
List<Pmt_material> list = new List<Pmt_material>();
for (int i=0; i< clientGridView.SelectedRows.Count; i++)
{
Pmt_material material = new Pmt_material();
material.Material_code = clientGridView.SelectedRows[i].Cells["Material_code"].Value as string;
material.Material_name = clientGridView.SelectedRows[i].Cells["Material_name"].Value as string;
list.Add(material);
}
BarcodeReport report = new BarcodeReport();
report.DataSource = list;
ReportPrintTool tool = new ReportPrintTool(report);
tool.ShowPreview();
}
else
{
string msg2 = "请至少选择一条要打印预览物料信息!"; //请选择至少选择一条要打印预览物料信息!
MessageBox.Show(msg2, Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService<MaterialBarcodeAction>.Error("物料信息打印预览异常:" + ex.Message, ex);
MessageBox.Show(ex.Message, Mesnac.Basic.LanguageHelper.WarnCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
finally
{
this._runtime.BaseControl.MCEnabled = true;
}
}
}
}