客户标签维护.txt 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. using LabelManager2;
  2. using Seagull.BarTender.Print;
  3. using System;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using 贴标机标签打印.CustomControl;
  9. using 贴标机标签打印.Properties;
  10. using 贴标机标签打印.PublicMethod;
  11. namespace 贴标机标签打印
  12. {
  13. public partial class 客户标签维护 : Form
  14. {
  15. DataHelper dh;
  16. DataTable dt;
  17. //设置Grid中Combox的静态数据,这个格式是必须的,#前面是展示值,#后面是实际值
  18. string[] labeltype = { "机身标#机身标", "彩盒标#彩盒标", "卡通箱标#卡通箱标", "大箱标#大箱标", "栈板标#栈板标" };
  19. string[] defaultype = { "是#-1", "否#0" };
  20. //记录上次筛选时的条件,如果本次和上次相同则不进行查询
  21. string LastCondition = "";
  22. //用于拼接条件查询
  23. StringBuilder condition = new StringBuilder();
  24. StringBuilder sql = new StringBuilder();
  25. /*CodeSoft新建打印机引擎*/
  26. ApplicationClass lbl;
  27. Document doc;
  28. /*BarTender新建打印机引擎*/
  29. //private Engine engine = null;
  30. //private LabelFormatDocument format ;
  31. //点击行的LabelCode
  32. string LabelCode = "";
  33. //模板的路径
  34. string LabelPath = "";
  35. //模板编号的ID
  36. string CL_ID1;
  37. //Label表的主键,用于弹窗的传参
  38. string La_id;
  39. //参数个数
  40. int ParamNum;
  41. //添加在grid末列的操作列
  42. DataGridViewImageColumn OperateColumn = new DataGridViewImageColumn
  43. {
  44. Image = Resources.preview_16px_25980_easyicon_net,
  45. Width = 40,
  46. Name = "预览",
  47. ToolTipText = "预览模板参数",
  48. Tag = "Read",
  49. AutoSizeMode = DataGridViewAutoSizeColumnMode.None
  50. };
  51. AutoSizeFormClass asc = new AutoSizeFormClass();
  52. public 客户标签维护()
  53. {
  54. InitializeComponent();
  55. cu_code.FormName = Name;
  56. cu_code.Caller = "Make!CustLabel";
  57. cu_code.SetValueField = new string[] { "cu_code", "cu_name" };
  58. cl_custcode1.FormName = Name;
  59. cl_custcode1.Caller = "Make!CustLabel";
  60. cl_custcode1.SetValueField = new string[] { "cl_custcode1" };
  61. la_code.FormName = Name;
  62. la_code.Caller = "Make!CustLabel";
  63. la_code.SetValueField = new string[] { "la_code" };
  64. }
  65. private void 条码维护_Load(object sender, EventArgs e)
  66. {
  67. asc.controllInitializeSize(this);
  68. dh = new DataHelper();
  69. condition.Append("");
  70. lbl = new ApplicationClass();
  71. // engine = new Engine(true);
  72. ChooseAll.ChooseAll(LabelDataGridView);
  73. asc.controlAutoSize(this);
  74. //加载下拉框的静态值
  75. LoadData();
  76. }
  77. private void LabelDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
  78. {
  79. if (LabelDataGridView.Columns[e.ColumnIndex].HeaderText == "预览")
  80. {
  81. if (LabelCode != LabelDataGridView.Rows[e.RowIndex].Cells["cl_labelcode"].Value.ToString()) {
  82. //获取路径和标签名称
  83. LabelPath = LabelDataGridView.Rows[e.RowIndex].Cells["cl_labelurl"].Value.ToString();
  84. LabelCode = LabelDataGridView.Rows[e.RowIndex].Cells["cl_labelcode"].Value.ToString();
  85. CL_ID1 = LabelDataGridView.Rows[e.RowIndex].Cells["cl_id"].Value.ToString();
  86. La_id = LabelDataGridView.Rows[e.RowIndex].Cells["la_id"].Value.ToString();
  87. if (CodeSoft.Checked)
  88. {
  89. //打开文件需要至少2秒
  90. doc = lbl.Documents.Open(LabelPath, true);
  91. //如果文件已不存在则进行提示
  92. if (doc == null)
  93. {
  94. //LabelParamPreview.SelectionColor = Color.Red;
  95. //LabelParamPreview.AppendText("指定路径已找不到该文件\n");
  96. return;
  97. }
  98. //打印变量个数
  99. //LabelParamPreview.AppendText("变量个数:" + doc.Variables.FreeVariables.Count + "\n");
  100. //获取打印变量名称,CodeSoft10支持此读取参数,6.4版本暂未找到读取参数的方法
  101. //object vars = doc.ReadVariables(enumDataSource.lppxDataSourceFree);
  102. //object[,] keyValueArrays = (object[,])vars;
  103. ParamNum = doc.Variables.FreeVariables.Count;
  104. string[] ParamName = new string[ParamNum];
  105. for (int i = 0; i < ParamNum; i++)
  106. {
  107. ParamName[i] = doc.Variables.FreeVariables.Item(i + 1).Name;
  108. }
  109. doc = lbl.Documents.Open(LabelPath, true);
  110. int y = 185;
  111. for (int i = 0; i < ParamName.Length; i++)
  112. {
  113. //变量的名称Label
  114. Label Param = new Label();
  115. Param.Text = ParamName[i];
  116. Param.Anchor = AnchorStyles.Left;
  117. Param.Anchor = AnchorStyles.Top;
  118. Param.Location = new Point(1035, y + 5);
  119. this.Controls.Add(Param);
  120. //维护变量的打印测试参数
  121. EnterTextBox TempParam = new EnterTextBox();
  122. TempParam.Anchor = AnchorStyles.Left;
  123. TempParam.Anchor = AnchorStyles.Top;
  124. TempParam.Name = "Temp" + ParamName[i];
  125. TempParam.Location = new Point(1135, y);
  126. y = y + 30;
  127. TempParam.Size = new Size(150, 22);
  128. this.Controls.Add(TempParam);
  129. y = y + 30;
  130. }
  131. }
  132. //CodeSoftPrintParam parfrom = new CodeSoftPrintParam(CL_ID1, La_id, ParamName, doc);
  133. ////在这个窗体关闭的时候刷新页面的数据
  134. //parfrom.FormClosing += Screen_Click;
  135. //BaseUtil.SetFormCenter(parfrom);
  136. //parfrom.ShowDialog();
  137. }
  138. else if (Bartender.Checked)
  139. {
  140. string ID = LabelDataGridView.Rows[e.RowIndex].Cells["cl_id"].Value.ToString();
  141. string fileName = LabelDataGridView.Rows[e.RowIndex].Cells["cl_labelurl"].Value.ToString();
  142. System.Drawing.Image image = LabelFormatThumbnail.Create(fileName, Color.LightGray, 434, 347);
  143. BartenderPreview LabelPreView = new BartenderPreview(ID, image);
  144. LabelPreView.StartPosition = FormStartPosition.CenterParent;
  145. LabelPreView.ShowDialog();
  146. }
  147. }
  148. }
  149. private void Screen_Click(object sender, EventArgs e)
  150. {
  151. sql.Clear();
  152. condition.Clear();
  153. //如果条件全部为空的时候
  154. if (cu_code.Text == "" && cu_name.Text == "")
  155. {
  156. LoadData();
  157. }
  158. else
  159. {
  160. 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");
  161. //设置筛选的条件
  162. condition.Append(BaseUtil.GetScreenSqlCondition(cu_code));
  163. //最终刷选条件拼接成的sql
  164. LoadData();
  165. }
  166. }
  167. private void Update_Click(object sender, EventArgs e)
  168. {
  169. string LabelSoft = "";
  170. //需要处理新增的行和原有数据然后更新的行
  171. if (CodeSoft.Checked)
  172. {
  173. LabelSoft = "CodeSoft";
  174. }
  175. if (Bartender.Checked)
  176. {
  177. LabelSoft = "Bartender";
  178. }
  179. DataTable dt = (DataTable)LabelDataGridView.DataSource;
  180. //如果有改变的行才传递到后台
  181. if (dt.GetChanges() != null)
  182. {
  183. //如果是新增的默认加上Radio当前选中的打印软件
  184. for (int i = 0; i < LabelDataGridView.Rows.Count; i++)
  185. {
  186. if (LabelDataGridView.Rows[i].Cells["cl_labelsoft"].Value.ToString() == "")
  187. {
  188. LabelDataGridView.Rows[i].Cells["cl_labelsoft"].Value = LabelSoft;
  189. }
  190. }
  191. 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 )";
  192. dh.UpDateTableByCondition(dt.GetChanges(), "customerlabel", "cl_id", sql.ToLower());
  193. LoadData();
  194. }
  195. }
  196. private void DeleteDetail_Click(object sender, EventArgs e)
  197. {
  198. string[] deleteid = new string[LabelDataGridView.RowCount];
  199. for (int i = 0; i < LabelDataGridView.RowCount; i++)
  200. {
  201. deleteid[i] = LabelDataGridView.Rows[i].Cells["cl_id"].Value.ToString();
  202. }
  203. dh.DeleteDataByID("customerlabel", "cl_id", deleteid);
  204. LoadData();
  205. }
  206. private void OpenFolder_Click(object sender, EventArgs e)
  207. {
  208. //根据勾选的不同设置不同的文件后缀过滤
  209. if (Bartender.Checked)
  210. {
  211. openFileDialog1.Filter = "(*.btw)|*.btw";
  212. }
  213. else if (CodeSoft.Checked)
  214. {
  215. openFileDialog1.Filter = "(*.lab)|*.lab";
  216. }
  217. DialogResult result = openFileDialog1.ShowDialog();
  218. if (result == DialogResult.OK)
  219. {
  220. FolderPath.Text = openFileDialog1.FileName;
  221. for (int i = 0; i < LabelDataGridView.Rows.Count; i++)
  222. {
  223. if (LabelDataGridView.Rows[i].Cells["Choose"].Value != null)
  224. {
  225. if ((bool)LabelDataGridView.Rows[i].Cells["Choose"].Value == true)
  226. {
  227. LabelDataGridView.Rows[i].Cells["cl_labelurl"].Value = FolderPath.Text;
  228. }
  229. }
  230. }
  231. }
  232. }
  233. private void LabelDataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
  234. {
  235. if (LabelDataGridView.Columns[e.ColumnIndex].Name == "cl_isdefault")
  236. {
  237. if (e.Value != null)
  238. {
  239. switch (e.Value.ToString())
  240. {
  241. case "0":
  242. e.Value = "否";
  243. break;
  244. case "1":
  245. e.Value = "是";
  246. break;
  247. default:
  248. break;
  249. }
  250. }
  251. }
  252. }
  253. private void LabelDataGridView_DataError(object sender, DataGridViewDataErrorEventArgs e)
  254. {
  255. //覆盖参数错误的事件,使得不会报错
  256. }
  257. private void LoadData()
  258. {
  259. //如果条件和上次一样则不进行数据读取
  260. //if (LastCondition != condition.ToString())
  261. {
  262. //如果没有任何筛选条件直接选取customerlabel的数据
  263. if (sql.Length == 0)
  264. {
  265. 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");
  266. }
  267. else
  268. {
  269. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  270. }
  271. BaseUtil.FillDgvWithDataTable(LabelDataGridView, dt);
  272. string Field = BaseUtil.GetGridViewSelectContent(LabelDataGridView);
  273. 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);
  274. LastCondition = condition.ToString();
  275. }
  276. }
  277. private void PrintTest_Click(object sender, EventArgs e)
  278. {
  279. Console.WriteLine(LabelCode);
  280. if (LabelCode != "")
  281. {
  282. doc.Printer.SwitchTo(PrinterList.Text);
  283. doc.PrintDocument();
  284. }
  285. }
  286. private void 产品标签维护_FormClosing(object sender, FormClosingEventArgs e)
  287. {
  288. try
  289. {
  290. lbl.Application.Quit();
  291. }
  292. catch (Exception)
  293. {
  294. }
  295. }
  296. private void Save_Click(object sender, EventArgs e)
  297. {
  298. if (cl_custcode1.Text != "" && la_type.Text != "" && FolderPath.Text != "" && la_code.Text != "")
  299. {
  300. string SoftWare = Bartender.Checked ? "Bartender" : "CodeSoft";
  301. sql.Clear();
  302. sql.Append("insert into customerlabel (cl_id,cl_labelcode,cl_custcode,cl_labeltype,cl_labelurl,cl_labelsoft) values( customerlabel_seq.nextval, ");
  303. sql.Append("'" + la_code.Text + "','" + cl_custcode1.Text + "','" + la_type.Text + "','" + FolderPath.Text + "','" + SoftWare + "')");
  304. dh.ExecuteSql(sql.ToString(), "insert");
  305. sql.Clear();
  306. MessageBox.Show("保存成功!");
  307. LoadData();
  308. }
  309. else
  310. {
  311. MessageBox.Show("请填写完整参数!");
  312. }
  313. }
  314. private void 产品标签维护_SizeChanged(object sender, EventArgs e)
  315. {
  316. asc.controlAutoSize(this);
  317. }
  318. }
  319. }