| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335 |
- using LabelManager2;
- using Seagull.BarTender.Print;
- using System;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using 贴标机标签打印.CustomControl;
- using 贴标机标签打印.Properties;
- using 贴标机标签打印.PublicMethod;
- namespace 贴标机标签打印
- {
- public partial class 客户标签维护 : Form
- {
- DataHelper dh;
- DataTable dt;
- //设置Grid中Combox的静态数据,这个格式是必须的,#前面是展示值,#后面是实际值
- string[] labeltype = { "机身标#机身标", "彩盒标#彩盒标", "卡通箱标#卡通箱标", "大箱标#大箱标", "栈板标#栈板标" };
- string[] defaultype = { "是#-1", "否#0" };
- //记录上次筛选时的条件,如果本次和上次相同则不进行查询
- string LastCondition = "";
- //用于拼接条件查询
- StringBuilder condition = new StringBuilder();
- StringBuilder sql = new StringBuilder();
- /*CodeSoft新建打印机引擎*/
- ApplicationClass lbl;
- Document doc;
- /*BarTender新建打印机引擎*/
- //private Engine engine = null;
- //private LabelFormatDocument format ;
- //点击行的LabelCode
- string LabelCode = "";
- //模板的路径
- string LabelPath = "";
- //模板编号的ID
- string CL_ID1;
- //Label表的主键,用于弹窗的传参
- string La_id;
- //参数个数
- int ParamNum;
- //添加在grid末列的操作列
- DataGridViewImageColumn OperateColumn = new DataGridViewImageColumn
- {
- Image = Resources.preview_16px_25980_easyicon_net,
- Width = 40,
- Name = "预览",
- ToolTipText = "预览模板参数",
- Tag = "Read",
- AutoSizeMode = DataGridViewAutoSizeColumnMode.None
- };
- AutoSizeFormClass asc = new AutoSizeFormClass();
- public 客户标签维护()
- {
- InitializeComponent();
- cu_code.FormName = Name;
- cu_code.Caller = "Make!CustLabel";
- cu_code.SetValueField = new string[] { "cu_code", "cu_name" };
- cl_custcode1.FormName = Name;
- cl_custcode1.Caller = "Make!CustLabel";
- cl_custcode1.SetValueField = new string[] { "cl_custcode1" };
- la_code.FormName = Name;
- la_code.Caller = "Make!CustLabel";
- la_code.SetValueField = new string[] { "la_code" };
- }
- private void 条码维护_Load(object sender, EventArgs e)
- {
- asc.controllInitializeSize(this);
- dh = new DataHelper();
- condition.Append("");
- lbl = new ApplicationClass();
- // engine = new Engine(true);
- ChooseAll.ChooseAll(LabelDataGridView);
- asc.controlAutoSize(this);
- //加载下拉框的静态值
- LoadData();
- }
- private void LabelDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
- {
- if (LabelDataGridView.Columns[e.ColumnIndex].HeaderText == "预览")
- {
- if (LabelCode != LabelDataGridView.Rows[e.RowIndex].Cells["cl_labelcode"].Value.ToString()) {
- //获取路径和标签名称
- LabelPath = LabelDataGridView.Rows[e.RowIndex].Cells["cl_labelurl"].Value.ToString();
- LabelCode = LabelDataGridView.Rows[e.RowIndex].Cells["cl_labelcode"].Value.ToString();
- CL_ID1 = LabelDataGridView.Rows[e.RowIndex].Cells["cl_id"].Value.ToString();
- La_id = LabelDataGridView.Rows[e.RowIndex].Cells["la_id"].Value.ToString();
- if (CodeSoft.Checked)
- {
- //打开文件需要至少2秒
- doc = lbl.Documents.Open(LabelPath, true);
- //如果文件已不存在则进行提示
- if (doc == null)
- {
- //LabelParamPreview.SelectionColor = Color.Red;
- //LabelParamPreview.AppendText("指定路径已找不到该文件\n");
- return;
- }
- //打印变量个数
- //LabelParamPreview.AppendText("变量个数:" + doc.Variables.FreeVariables.Count + "\n");
- //获取打印变量名称,CodeSoft10支持此读取参数,6.4版本暂未找到读取参数的方法
- //object vars = doc.ReadVariables(enumDataSource.lppxDataSourceFree);
- //object[,] keyValueArrays = (object[,])vars;
- ParamNum = doc.Variables.FreeVariables.Count;
- string[] ParamName = new string[ParamNum];
- for (int i = 0; i < ParamNum; i++)
- {
- ParamName[i] = doc.Variables.FreeVariables.Item(i + 1).Name;
- }
- doc = lbl.Documents.Open(LabelPath, true);
- int y = 185;
- for (int i = 0; i < ParamName.Length; i++)
- {
- //变量的名称Label
- Label Param = new Label();
- Param.Text = ParamName[i];
- Param.Anchor = AnchorStyles.Left;
- Param.Anchor = AnchorStyles.Top;
- Param.Location = new Point(1035, y + 5);
- this.Controls.Add(Param);
- //维护变量的打印测试参数
- EnterTextBox TempParam = new EnterTextBox();
- TempParam.Anchor = AnchorStyles.Left;
- TempParam.Anchor = AnchorStyles.Top;
- TempParam.Name = "Temp" + ParamName[i];
- TempParam.Location = new Point(1135, y);
- y = y + 30;
- TempParam.Size = new Size(150, 22);
- this.Controls.Add(TempParam);
- y = y + 30;
- }
- }
- //CodeSoftPrintParam parfrom = new CodeSoftPrintParam(CL_ID1, La_id, ParamName, doc);
- ////在这个窗体关闭的时候刷新页面的数据
- //parfrom.FormClosing += Screen_Click;
- //BaseUtil.SetFormCenter(parfrom);
- //parfrom.ShowDialog();
- }
- else if (Bartender.Checked)
- {
- string ID = LabelDataGridView.Rows[e.RowIndex].Cells["cl_id"].Value.ToString();
- string fileName = LabelDataGridView.Rows[e.RowIndex].Cells["cl_labelurl"].Value.ToString();
- System.Drawing.Image image = LabelFormatThumbnail.Create(fileName, Color.LightGray, 434, 347);
- BartenderPreview LabelPreView = new BartenderPreview(ID, image);
- LabelPreView.StartPosition = FormStartPosition.CenterParent;
- LabelPreView.ShowDialog();
- }
- }
- }
- private void Screen_Click(object sender, EventArgs e)
- {
- sql.Clear();
- condition.Clear();
- //如果条件全部为空的时候
- if (cu_code.Text == "" && cu_name.Text == "")
- {
- LoadData();
- }
- else
- {
- sql.Append("select cu_name,cl_labelurl,cl_labeltype,cl_isdefault,cl_custcode,cl_id,cl_labelcode,cl_detno,cl_labelsoft from customerlabel left join customer on cl_custcode=cu_code order by cl_custcode");
- //设置筛选的条件
- condition.Append(BaseUtil.GetScreenSqlCondition(cu_code));
- //最终刷选条件拼接成的sql
- LoadData();
- }
- }
- private void Update_Click(object sender, EventArgs e)
- {
- string LabelSoft = "";
- //需要处理新增的行和原有数据然后更新的行
- if (CodeSoft.Checked)
- {
- LabelSoft = "CodeSoft";
- }
- if (Bartender.Checked)
- {
- LabelSoft = "Bartender";
- }
- DataTable dt = (DataTable)LabelDataGridView.DataSource;
- //如果有改变的行才传递到后台
- if (dt.GetChanges() != null)
- {
- //如果是新增的默认加上Radio当前选中的打印软件
- for (int i = 0; i < LabelDataGridView.Rows.Count; i++)
- {
- if (LabelDataGridView.Rows[i].Cells["cl_labelsoft"].Value.ToString() == "")
- {
- LabelDataGridView.Rows[i].Cells["cl_labelsoft"].Value = LabelSoft;
- }
- }
- string sql = "Insert into customerlabel (cl_ID,cl_custCODE,cl_LABELTYPE,cl_LABELCODE,cl_LABELURL,cl_DETNO,cl_LABELSOFT,cl_ISDEFAULT) values( customerlabel_seq.nextval,'" + cu_code.Text + "',:cl_LABELTYPE,:cl_LABELCODE,:cl_LABELURL,:cl_DETNO,:cl_LABELSOFT,:cl_ISDEFAULT )";
- dh.UpDateTableByCondition(dt.GetChanges(), "customerlabel", "cl_id", sql.ToLower());
- LoadData();
- }
- }
- private void DeleteDetail_Click(object sender, EventArgs e)
- {
- string[] deleteid = new string[LabelDataGridView.RowCount];
- for (int i = 0; i < LabelDataGridView.RowCount; i++)
- {
- deleteid[i] = LabelDataGridView.Rows[i].Cells["cl_id"].Value.ToString();
- }
- dh.DeleteDataByID("customerlabel", "cl_id", deleteid);
- LoadData();
- }
- private void OpenFolder_Click(object sender, EventArgs e)
- {
- //根据勾选的不同设置不同的文件后缀过滤
- if (Bartender.Checked)
- {
- openFileDialog1.Filter = "(*.btw)|*.btw";
- }
- else if (CodeSoft.Checked)
- {
- openFileDialog1.Filter = "(*.lab)|*.lab";
- }
- DialogResult result = openFileDialog1.ShowDialog();
- if (result == DialogResult.OK)
- {
- FolderPath.Text = openFileDialog1.FileName;
- for (int i = 0; i < LabelDataGridView.Rows.Count; i++)
- {
- if (LabelDataGridView.Rows[i].Cells["Choose"].Value != null)
- {
- if ((bool)LabelDataGridView.Rows[i].Cells["Choose"].Value == true)
- {
- LabelDataGridView.Rows[i].Cells["cl_labelurl"].Value = FolderPath.Text;
- }
- }
- }
- }
- }
- private void LabelDataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
- {
- if (LabelDataGridView.Columns[e.ColumnIndex].Name == "cl_isdefault")
- {
- if (e.Value != null)
- {
- switch (e.Value.ToString())
- {
- case "0":
- e.Value = "否";
- break;
- case "1":
- e.Value = "是";
- break;
- default:
- break;
- }
- }
- }
- }
- private void LabelDataGridView_DataError(object sender, DataGridViewDataErrorEventArgs e)
- {
- //覆盖参数错误的事件,使得不会报错
- }
- private void LoadData()
- {
- //如果条件和上次一样则不进行数据读取
- //if (LastCondition != condition.ToString())
- {
- //如果没有任何筛选条件直接选取customerlabel的数据
- if (sql.Length == 0)
- {
- dt = (DataTable)dh.ExecuteSql("select cu_name,cl_labelurl,cl_labeltype,cl_isdefault,cl_custcode,cl_id,cl_labelcode,cl_detno,cl_labelsoft,la_id from customerlabel left join customer on cl_custcode=cu_code left join label on la_code=cl_custcode order by cl_custcode", "select");
- }
- else
- {
- dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
- }
- BaseUtil.FillDgvWithDataTable(LabelDataGridView, dt);
- string Field = BaseUtil.GetGridViewSelectContent(LabelDataGridView);
- pagination1.BindDataToNavigator(LabelDataGridView, "CustomerLabel left join customer on cl_custcode=cu_code left join label on la_code=cl_custcode", Field, "cl_id", "", condition.Replace("where", "").ToString(), OperateColumn);
- LastCondition = condition.ToString();
- }
- }
- private void PrintTest_Click(object sender, EventArgs e)
- {
- Console.WriteLine(LabelCode);
- if (LabelCode != "")
- {
- doc.Printer.SwitchTo(PrinterList.Text);
- doc.PrintDocument();
- }
- }
- private void 产品标签维护_FormClosing(object sender, FormClosingEventArgs e)
- {
- try
- {
- lbl.Application.Quit();
- }
- catch (Exception)
- {
- }
- }
- private void Save_Click(object sender, EventArgs e)
- {
- if (cl_custcode1.Text != "" && la_type.Text != "" && FolderPath.Text != "" && la_code.Text != "")
- {
- string SoftWare = Bartender.Checked ? "Bartender" : "CodeSoft";
- sql.Clear();
- sql.Append("insert into customerlabel (cl_id,cl_labelcode,cl_custcode,cl_labeltype,cl_labelurl,cl_labelsoft) values( customerlabel_seq.nextval, ");
- sql.Append("'" + la_code.Text + "','" + cl_custcode1.Text + "','" + la_type.Text + "','" + FolderPath.Text + "','" + SoftWare + "')");
- dh.ExecuteSql(sql.ToString(), "insert");
- sql.Clear();
- MessageBox.Show("保存成功!");
- LoadData();
- }
- else
- {
- MessageBox.Show("请填写完整参数!");
- }
- }
- private void 产品标签维护_SizeChanged(object sender, EventArgs e)
- {
- asc.controlAutoSize(this);
- }
- }
- }
|