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;
using QMAPP.FJC.Entity.Operation;
using QMAPP.ServicesAgent;

namespace QMAPP.WinForm.Forms.RePrint
{
    public partial class ReprintForm : Form
    {
        public ReprintForm()
        {
            InitializeComponent();
        }

        private void tsbClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void tsbSave_Click(object sender, EventArgs e)
        {
            if (tbxProductCode.Text.Trim().Length == 0)
            {
                lbinfo.Text = "请输入要打印的条码信息!";
                this.lbinfo.ForeColor = Color.Red;
                return;
            }

           
            try
            {
                Product condition = new Product() { PRODUCTCODE = tbxProductCode.Text.Trim().ToUpper() };

                QMAPP.ServicesAgent.ServiceAgent agent = ClientContext.GetServiceAgent();

                Product entity = agent.InvokeServiceFunction<Product>(B9IPCService.ProductBLL_GetByCondition.ToString(), condition);

                if (entity == null || string.IsNullOrEmpty(entity.PRODUCTCODE))
                {
                    lbinfo.Text = "该条码不存在!";
                    this.lbinfo.ForeColor = Color.Red;
                    return;

                }

                QM.Assist.LabelInfo ll = new QM.Assist.LabelInfo();
                ll.BarCode = entity.PRODUCTCODE + ",*" + entity.PRODUCTCODE + "*";
                QM.Assist.PrintUtil.LabelList2.Add(ll);
                QM.Assist.PrintUtil pu = new QM.Assist.PrintUtil();
                pu.PrintLabel2(System.Configuration.ConfigurationManager.AppSettings["proPath"].ToString
                    (), System.Configuration.ConfigurationManager.AppSettings["reprintPath"].ToString
                    (), System.Configuration.ConfigurationManager.AppSettings["redataPath"].ToString
                    ());

                lbinfo.Text = "打印成功!";
                this.lbinfo.ForeColor = Color.Green;
                tbxProductCode.Text = "";
            }
            catch (Exception ex)
            {

                lbinfo.Text = "打印异常!";
                this.lbinfo.ForeColor = Color.Red;
                return;
            }
          
        }

    }
}