| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350 |
-
- 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<DataRow> PrintData
- {
- get;
- set;
- }
- public F_SET_014003()
- {
- InitializeComponent();
- }
- private void F_SET_014003_Load(object sender, EventArgs e)
- {
- try
- {
- //_printDataRow = new List<DataRow>();
- //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();
- }
- /// <summary>
- /// 清除查询条件
- /// </summary>
- 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);
- }
- }
- /// <summary>
- /// 获取查询实体
- /// </summary>
- 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";
- }
- /// <summary>
- /// 查询数据
- /// </summary>
- /// <returns>验证通过true,其他false</returns>
- private void QueryDataFromOther()
- {
- try
- {
- this.SearchSelectEntity();
- this.dgvInvoice.DataSource = null;
- ServiceResultEntity sre = DoAsync<ServiceResultEntity>(() =>
- {
- 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<BarcodeBatchConfig>(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<DataRow> _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);
- }
- }
- }
- }
|