using System; using System.Collections.Generic; using System.Data; using System.Drawing; using System.IO.Packaging; using System.Reflection; using System.Runtime.InteropServices; using System.Windows.Forms; using Curtain.Framework.Json; using Dongke.IBOSS.PRD.Basics.BaseResources; using Dongke.IBOSS.PRD.Client.CommonModule; using Dongke.IBOSS.PRD.WCF.DataModels; using Dongke.IBOSS.PRD.WCF.DataModels.BarcodeBatchSet; using Dongke.IBOSS.PRD.WCF.Proxys; using Dongke.WinForm.Controls; namespace Dongke.IBOSS.PRD.Client.Controls { public partial class F_SET_014003 : DKFormBase { private ClientRequestEntity _clientRequestEntity = null; // 查询条件实体 private BarcodeBatchConfig _setData; private DataTable _DataItem; public List PrintData { get; set; } public F_SET_014003() { InitializeComponent(); } private void F_SET_014003_Load(object sender, EventArgs e) { try { //_printDataRow = new List(); //if (PrintData != null) //{ // foreach (DataRow item in PrintData.Rows) // { // if (item["SEL"] + "" == "1" && string.IsNullOrEmpty(item["BARCODE"] + "")) // { // _printDataRow.Add(item); // } // } //} } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), MethodBase.GetCurrentMethod().Name, this.Text, ex); } } private void F_SET_014003_Shown(object sender, EventArgs e) { try { this.QueryDataFromOther(); } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), MethodBase.GetCurrentMethod().Name, this.Text, ex); } } private void tsbtnClose_Click(object sender, EventArgs e) { this.Close(); } private void tsbtnAdaptive_Click(object sender, EventArgs e) { this.dgvInvoice.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells); } private void tsbtnClearCondition_Click(object sender, EventArgs e) { this.ClearConditions(); } /// /// 清除查询条件 /// public void ClearConditions() { this.txtInvoiceName.Text = string.Empty; this.txtRemarks.Text = string.Empty; } private void tsbtnSearch_Click(object sender, EventArgs e) { try { this.QueryDataFromOther(); } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 获取查询实体 /// private void SearchSelectEntity() { this._clientRequestEntity = new ClientRequestEntity(); this._clientRequestEntity.NameSpace = "F_SET_014001"; this._clientRequestEntity.Name = "GetBarCodeBatchLayoutList"; // 模板名称 this._clientRequestEntity.Properties["layoutname"] = this.txtInvoiceName.Text.Trim(); this._clientRequestEntity.Properties["remarks"] = this.txtRemarks.Text.Trim(); this._clientRequestEntity.Properties["valueflag"] = "1"; } /// /// 查询数据 /// /// 验证通过true,其他false private void QueryDataFromOther() { try { this.SearchSelectEntity(); this.dgvInvoice.DataSource = null; ServiceResultEntity sre = DoAsync(() => { return SystemModuleProxy.Service.DoBarCodePrint(this._clientRequestEntity); } ); if (sre.Status == Constant.ServiceResultStatus.Success) { // 查询成功 this.dgvInvoice.DataSource = sre.Data.Tables[0]; if (sre.Data.Tables[0].Rows.Count > 0) { this.dgvInvoice.Rows[0].Selected = true; } } } catch (Exception ex) { throw ex; } } private void tsbtnPageSetting_Click(object sender, EventArgs e) { try { this.pageSetupDialog.ShowDialog(); } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } private void tsbtnPrinterSetting_Click(object sender, EventArgs e) { try { this.printDialog.ShowDialog(); } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } private bool CheckLayoutData() { if (PrintData == null || PrintData.Count == 0) { MessageBox.Show("没有打印数据", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } DataRowView row = this.dgvInvoice.CurrentRow?.DataBoundItem as DataRowView; if (row == null) { MessageBox.Show("未选择打印模板", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } int LayoutID = Convert.ToInt32(row["LayoutID"]); ClientRequestEntity cre = new ClientRequestEntity(); cre.NameSpace = "F_SET_014001"; cre.Name = "GetBarCodeBatchLayout"; cre.Properties["LayoutID"] = LayoutID; ServiceResultEntity sre = SystemModuleProxy.Service.DoBarCodePrint(cre); if (sre != null && sre.Data != null && sre.Data.Tables.Count > 0 && sre.Data.Tables[0].Rows.Count > 0) { byte[] bytes = sre.Data.Tables[0].Rows[0]["LayoutData"] as byte[]; string ss_dd = System.Text.Encoding.UTF8.GetString(bytes); _setData = JsonHelper.ToObject(ss_dd); _DataItem = sre.Data.Tables[1]; printDocument1.DocumentName = sre.Data.Tables[0].Rows[0]["LayoutName"] + ""; } else { MessageBox.Show("无打印模板", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } return true; } private void tsbtnPrintPreview_Click(object sender, EventArgs e) { try { if (!CheckLayoutData()) { return; } printPreviewDialog1.WindowState = FormWindowState.Maximized; printPreviewDialog1.PrintPreviewControl.Columns = 1; printPreviewDialog1.PrintPreviewControl.Rows = 1; printPreviewDialog1.PrintPreviewControl.StartPage = 0; printPreviewDialog1.ShowDialog(); } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } private void tsbtnPrint_Click(object sender, EventArgs e) { try { if (!CheckLayoutData()) { return; } printDocument1.Print(); } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } private void printDocument1_BeginPrint(object sender, System.Drawing.Printing.PrintEventArgs e) { try { _nextIndex = 0; } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } private void printDocument1_EndPrint(object sender, System.Drawing.Printing.PrintEventArgs e) { try { } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } private void printDocument1_QueryPageSettings(object sender, System.Drawing.Printing.QueryPageSettingsEventArgs e) { try { } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } private int _nextIndex = 0; //List _printDataRow; private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { try { if (_nextIndex == 0) { _setData.DpiX = e.Graphics.DpiX; _setData.DpiY = e.Graphics.DpiY; BarcodeBatchPrint.DoToPixel(_setData); } using (Image image = BarcodeBatchPrint.CreateImagePage(_setData, _DataItem, PrintData, _nextIndex, out _nextIndex)) { //image.Save("D://p" + _nextIndex + ".png"); Rectangle rect = _setData.RangePixel; rect.X = 0; rect.Y = 0; e.Graphics.DrawImage(image, 0, 0, rect, GraphicsUnit.Pixel); } if (_nextIndex < 0 || _nextIndex >= PrintData.Count) { e.HasMorePages = false; } else { e.HasMorePages = true; } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } } }