|
|
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 ICSSoft.Frame.Data.BLL; using System.Data.SqlClient; using ICSSoft.Base.Config.AppConfig; using ICSSoft.Frame.Data.Entity; 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 System.IO;
namespace ICSSoft.Frame.APP { public partial class FormICSItemLotPrint : DevExpress.XtraEditors.XtraForm { private string _PrintTableName = "标签复制"; private string _LableType = "008";
#region 构造函数
public FormICSItemLotPrint() { InitializeComponent(); this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height); this.WindowState = FormWindowState.Maximized; } #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 SystemOptition
/// <summary>
/// 操作权限
/// </summary>
/// <returns></returns>
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);
List<Control> ControlList = new List<Control>(); ControlList.Add(btnPrint); //ControlList.Add(btnExit);
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; } /// <summary>
/// 数据权限
/// </summary>
/// <returns></returns>
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 void simpleButton4_Click(object sender, EventArgs e) { try { SimpleButton btntemp = (SimpleButton)sender; if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false) { ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!"); return; } if (string.IsNullOrWhiteSpace(txtLOTNO.Text.Trim())) { MessageBox.Show("请输入产品条码!"); return; } if (txtTempName.EditValue == null) { MessageBox.Show("请选择打印模板!"); return; } if (txtPrint.Text.Trim() == "") { MessageBox.Show("请选择本地打印机!"); return; }
List<PrintPara> parasList = new List<PrintPara>(); PrintPara para = new PrintPara(); para.PrintKey = "LOTNO"; para.PrintValues = new object[] { txtLOTNO.Text.Trim() }; parasList.Add(para);
if (chkShowDialogFlag.Checked) { FormPrint pr = new FormPrint(txtTempName.EditValue.ToString(), txtPrint.Text, true, true, _PrintTableName, 1, "", "本地打印", parasList); pr.ShowDialog(); } else { PrintReport pr = new PrintReport(txtTempName.EditValue.ToString(), txtPrint.Text, true, false, _PrintTableName, 1, "", "本地打印", parasList); } SetDefaultLastPrinter();
List<ICSITEMLot> InfoList = new List<ICSITEMLot>(); ICSITEMLot Info = new ICSITEMLot(); Info.LotNO = txtLOTNO.Text.Trim(); Info.lastPrintUSERID = AppConfig.UserId; Info.lastPrintTime = AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss"); Info.WorkPoint = AppConfig.WorkPointCode; InfoList.Add(Info); //更新打印信息
ICSRdrecord2LOTBLL.updatePrint(InfoList, AppConfig.AppConnectString); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } #endregion
private void SetDefaultLastPrinter() { try { string PrinterPath = System.AppDomain.CurrentDomain.BaseDirectory + "\\temp\\"; string PrinterFileName = PrinterPath + _LableType + _PrintTableName + "printerName.ini";
if (!Directory.Exists(PrinterPath)) { Directory.CreateDirectory(PrinterPath); } if (!File.Exists(PrinterFileName)) { using (File.Create(PrinterFileName)) { } }
using (StreamWriter sw = new StreamWriter(PrinterFileName)) { sw.WriteLine(txtTempName.EditValue == null ? "" : txtTempName.EditValue.ToString()); sw.WriteLine(txtPrint.Text); sw.WriteLine(chkShowDialogFlag.Checked.ToString()); } } catch {
} }
private void FormICSItemLotPrint_Load(object sender, EventArgs e) { BindPrinters(); BindLables();
GetDefaultLastPrinter(); }
private void BindPrinters() { try { List<string> list = GetPrinterInfo.GetPrinters(); foreach (string s in list) { txtPrint.Properties.Items.Add(s); } } catch (Exception ex) { } } private void BindLables() { string sql = "SELECT ID as [编号],LableName as [名称] FROM dbo.Sys_Lables a WHERE (LableType='{0}' AND WorkPointCode='{1}') ";
sql = string.Format(sql, new object[] { _LableType, AppConfig.WorkPointCode });
DataTable data = DBHelper.ExecuteDataset(AppConfig.FrameConnectString, CommandType.Text, sql).Tables[0];
txtTempName.Properties.Columns.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo("编号", "编号")); txtTempName.Properties.Columns.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo("名称", "名称"));
txtTempName.Properties.ValueMember = "编号"; txtTempName.Properties.DisplayMember = "名称"; txtTempName.Properties.Columns[0].Visible = false; txtTempName.Properties.DataSource = data; if (data.Rows.Count > 0) { txtTempName.EditValue = data.Rows[0]["编号"]; }
}
private void GetDefaultLastPrinter() { try { string PrinterPath = System.AppDomain.CurrentDomain.BaseDirectory + "\\temp\\"; string PrinterFileName = PrinterPath + _LableType + _PrintTableName + "printerName.ini";
if (!Directory.Exists(PrinterPath)) { Directory.CreateDirectory(PrinterPath); } if (!File.Exists(PrinterFileName)) { using (File.Create(PrinterFileName)) {
} }
Dictionary<int, string> infoDic = new Dictionary<int, string>(); using (StreamReader fReader = new StreamReader(PrinterFileName)) { int key = 0; while (fReader.Peek() > -1) { string value = fReader.ReadLine(); if (value != null) { infoDic.Add(key, value); key++; } } }
if (infoDic.Count == 3) { //
if (infoDic[0] != "") { if (txtTempName.Properties.DataSource != null) { DataTable dt = txtTempName.Properties.DataSource as DataTable; if (dt.Select("编号 = '" + infoDic[0] + "'").Length > 0) { txtTempName.EditValue = infoDic[0]; }
} }
if (infoDic[1] != "") { if (txtPrint.Properties.Items.Contains(infoDic[1])) { txtPrint.Text = infoDic[1]; } }
if (infoDic[2] != "") { bool boolvalue = false; if (bool.TryParse(infoDic[2], out boolvalue)) { chkShowDialogFlag.Checked = boolvalue; } }
} } catch {
} }
private void txtLOTNO_KeyPress(object sender, KeyPressEventArgs e) { try { if (e.KeyChar == 13) { simpleButton4_Click(null, null); } } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.ToString()); } } } }
|