客户标签维护.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. using LabelManager2;
  2. using System;
  3. using System.Data;
  4. using System.Drawing;
  5. using System.Text;
  6. using System.IO;
  7. using System.Windows.Forms;
  8. using UAS_LabelMachine.CustomControl;
  9. using UAS_LabelMachine.Properties;
  10. using UAS_LabelMachine.PublicMethod;
  11. using UAS_LabelMachine.Entity;
  12. namespace UAS_LabelMachine
  13. {
  14. public partial class 客户标签维护 : Form
  15. {
  16. DataHelper dh;
  17. DataTable dt;
  18. //设置Grid中Combox的静态数据,这个格式是必须的,#前面是展示值,#后面是实际值
  19. string[] labeltype = { "单盘#单盘", "中盒#中盒", "外箱#外箱", "全部#" };
  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. string CL_ID2;
  38. //Label表的主键,用于弹窗的传参
  39. string La_id1;
  40. //添加在grid末列的操作列
  41. DataGridViewImageColumn PreviewColumn = new DataGridViewImageColumn
  42. {
  43. Image = Resources.preview_16px_25980_easyicon_net,
  44. Width = 40,
  45. Name = "预览",
  46. ToolTipText = "预览模板参数",
  47. Tag = "Read",
  48. AutoSizeMode = DataGridViewAutoSizeColumnMode.None
  49. };
  50. DataGridViewImageColumn OperateColumn = new DataGridViewImageColumn
  51. {
  52. Image = Resources.write_15_893687707641px_1181413_easyicon_net,
  53. Width = 40,
  54. Name = "编辑",
  55. ToolTipText = "编辑模板",
  56. Tag = "Read",
  57. AutoSizeMode = DataGridViewAutoSizeColumnMode.None
  58. };
  59. AutoSizeFormClass asc = new AutoSizeFormClass();
  60. public 客户标签维护()
  61. {
  62. InitializeComponent();
  63. cu_code.FormName = Name;
  64. cu_code.SetValueField = new string[] { "cu_code", "cu_name" };
  65. cu_code.TableName = "(select distinct cu_code,cu_name from customer left join customerlabel on cu_code=cl_custcode)";
  66. cu_code.SelectField = "cu_code # 客户编号,cu_name # 客户名称";
  67. 客户编号.FormName = Name;
  68. 客户编号.SetValueField = new string[] { "客户编号" };
  69. 客户编号.TableName = "(select distinct cu_code,cu_name from customer left join customerlabel on cu_code=cl_custcode)";
  70. 客户编号.SelectField = "cu_code # 客户编号,cu_name # 客户名称";
  71. la_code.FormName = Name;
  72. la_code.SetValueField = new string[] { "la_code" };
  73. la_code.TableName = "label";
  74. la_code.SelectField = "la_code # 模板编号,la_name # 模板名称";
  75. NetURL.Text = Settings.Default.ShareUrl;
  76. }
  77. private void 条码维护_Load(object sender, EventArgs e)
  78. {
  79. if (Settings.Default.FTPAddress == "")
  80. {
  81. FTPShare.Visible = false;
  82. }
  83. dh = SystemInf.dh;
  84. condition.Append("");
  85. ChooseAll.ChooseAll(LabelDataGridView);
  86. BaseUtil.SetComboxData(la_type, "display", "value", labeltype);
  87. //加载下拉框的静态值
  88. LoadData();
  89. Width = Width + 1;
  90. asc.controllInitializeSize(this);
  91. lbl = SystemInf.lbl;
  92. Width = Width + 1;
  93. }
  94. private void LabelDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
  95. {
  96. if (LabelDataGridView.Columns[e.ColumnIndex].HeaderText == "预览")
  97. {
  98. if (lbl.Documents.Count > 0)
  99. {
  100. lbl.ActiveDocument.Close();
  101. }
  102. //获取路径和标签名称
  103. LabelPath = LabelDataGridView.Rows[e.RowIndex].Cells["cl_labelurl"].Value.ToString();
  104. LabelCode = LabelDataGridView.Rows[e.RowIndex].Cells["cl_labelcode"].Value.ToString();
  105. CL_ID1 = LabelDataGridView.Rows[e.RowIndex].Cells["cl_id"].Value.ToString();
  106. La_id1 = LabelDataGridView.Rows[e.RowIndex].Cells["la_id"].Value.ToString();
  107. System.DateTime time;
  108. try
  109. {
  110. time = Convert.ToDateTime(LabelDataGridView.Rows[e.RowIndex].Cells["cl_date"].Value.ToString());
  111. }
  112. catch (Exception)
  113. {
  114. time = System.DateTime.Now;
  115. }
  116. if (CodeSoft.Checked)
  117. {
  118. string LabelName = LabelDataGridView.Rows[e.RowIndex].Cells["cl_labelname"].Value.ToString();
  119. doc = lbl.Documents.Open(BaseUtil.GetLabelUrl(LabelPath, LabelName,time));
  120. Bitmap bit = new Bitmap(doc.CopyImageToFile());
  121. pictureBox1.Image = bit;
  122. //如果文件已不存在则进行提示
  123. if (doc == null)
  124. {
  125. return;
  126. }
  127. }
  128. }
  129. if (LabelDataGridView.Columns[e.ColumnIndex].HeaderText == "编辑")
  130. {
  131. if (e.RowIndex >= 0 && e.ColumnIndex >= 0)
  132. {
  133. CL_ID2 = LabelDataGridView.Rows[e.RowIndex].Cells["cl_id"].Value.ToString();
  134. LabelPath = LabelDataGridView.Rows[e.RowIndex].Cells["cl_labelurl"].Value.ToString();
  135. string LabelName = LabelDataGridView.Rows[e.RowIndex].Cells["cl_labelname"].Value.ToString();
  136. System.DateTime time;
  137. try
  138. {
  139. time = Convert.ToDateTime(LabelDataGridView.Rows[e.RowIndex].Cells["cl_date"].Value.ToString());
  140. }
  141. catch (Exception)
  142. {
  143. time = System.DateTime.Now;
  144. }
  145. BaseUtil.GetLabelUrl(LabelPath, LabelName, time);
  146. System.Diagnostics.Process.Start(ftpOperater.DownLoadTo + LabelName);
  147. 客户编号.Text = LabelDataGridView.Rows[e.RowIndex].Cells["CL_CUSTCODE2"].Value.ToString();
  148. la_type1.Text = LabelDataGridView.Rows[e.RowIndex].Cells["cl_labeltype"].Value.ToString();
  149. la_code.Text = LabelDataGridView.Rows[e.RowIndex].Cells["cl_labelcode"].Value.ToString();
  150. la_name.Text = LabelDataGridView.Rows[e.RowIndex].Cells["cl_labelname"].Value.ToString();
  151. FolderPath.Text = ftpOperater.DownLoadTo;
  152. }
  153. }
  154. //asc.controllInitializeSize(this);
  155. }
  156. private void Screen_Click(object sender, EventArgs e)
  157. {
  158. sql.Clear();
  159. condition.Clear();
  160. //如果条件全部为空的时候
  161. if (cu_code.Text == "" && cu_name.Text == "" && la_type.Text == "")
  162. {
  163. LoadData();
  164. }
  165. else
  166. {
  167. sql.Append("select to_char(nvl(cl_date,sysdate),'YYYY-MM-DD HH24:Mi:SS') cl_date,cu_name,cl_labelurl,cl_labeltype,cl_isdefault,cl_custcode,cl_labelname,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 ");
  168. //设置筛选的条件
  169. condition.Append(BaseUtil.GetScreenSqlCondition(cu_code, la_type));
  170. //最终刷选条件拼接成的sql
  171. LoadData();
  172. }
  173. }
  174. private void Update_Click(object sender, EventArgs e)
  175. {
  176. string LabelSoft = "";
  177. //需要处理新增的行和原有数据然后更新的行
  178. if (CodeSoft.Checked)
  179. {
  180. LabelSoft = "CodeSoft";
  181. }
  182. DataTable dt = (DataTable)LabelDataGridView.DataSource;
  183. //如果有改变的行才传递到后台
  184. if (dt.GetChanges() != null)
  185. {
  186. //如果是新增的默认加上Radio当前选中的打印软件
  187. for (int i = 0; i < LabelDataGridView.Rows.Count; i++)
  188. {
  189. if (LabelDataGridView.Rows[i].Cells["cl_labelsoft"].Value.ToString() == "")
  190. {
  191. LabelDataGridView.Rows[i].Cells["cl_labelsoft"].Value = LabelSoft;
  192. }
  193. }
  194. string sql = "Insert into customerlabel (cl_ID,cl_custCODE,cl_LABELTYPE,cl_LABELCODE,cl_LABELURL,cl_DETNO,cl_LABELSOFT,cl_ISDEFAULT, cl_date) values(customerlabel_seq.nextval,'" + cu_code.Text + "',:cl_LABELTYPE,:cl_LABELCODE,:cl_LABELURL,:cl_DETNO,:cl_LABELSOFT,:cl_ISDEFAULT,sysdate)";
  195. dh.UpDateTableByCondition(dt.GetChanges(), "customerlabel", "cl_id", sql.ToLower());
  196. LoadData();
  197. }
  198. }
  199. private void DeleteDetail_Click(object sender, EventArgs e)
  200. {
  201. string[] deleteid = new string[LabelDataGridView.RowCount];
  202. for (int i = 0; i < LabelDataGridView.RowCount; i++)
  203. {
  204. deleteid[i] = LabelDataGridView.Rows[i].Cells["cl_id"].Value.ToString();
  205. }
  206. dh.DeleteDataByID("customerlabel", "cl_id", deleteid);
  207. LoadData();
  208. }
  209. private void OpenFolder_Click(object sender, EventArgs e)
  210. {
  211. //根据勾选的不同设置不同的文件后缀过滤
  212. if (CodeSoft.Checked)
  213. {
  214. openFileDialog1.Filter = "(*.lab)|*.lab";
  215. }
  216. DialogResult result = openFileDialog1.ShowDialog();
  217. if (result == DialogResult.OK)
  218. {
  219. FolderPath.Text = openFileDialog1.FileName;
  220. la_name.Text = FolderPath.Text.Substring(FolderPath.Text.LastIndexOf("\\") + 1);
  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 to_char(nvl(cl_date,sysdate),'YYYY-MM-DD HH24:Mi:SS') cl_date,cu_name,cl_labelurl,cl_labeltype,cl_isdefault,cl_labelname,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_LABELCODE 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_LABELCODE", Field, "cl_id", "", condition.Replace("where", "").ToString(), PreviewColumn, OperateColumn);
  274. LastCondition = condition.ToString();
  275. }
  276. }
  277. private void PrintTest_Click(object sender, EventArgs e)
  278. {
  279. if (LabelCode != "")
  280. {
  281. doc.Printer.SwitchTo(PrinterList.Text);
  282. doc.PrintDocument();
  283. }
  284. }
  285. private void 产品标签维护_FormClosing(object sender, FormClosingEventArgs e)
  286. {
  287. try
  288. {
  289. lbl.Documents.CloseAll();
  290. }
  291. catch (Exception)
  292. {
  293. }
  294. }
  295. private void Save_Click(object sender, EventArgs e)
  296. {
  297. if (la_type1.Text != "" && FolderPath.Text != "" && la_code.Text != "")
  298. {
  299. //文件名
  300. string fileName;
  301. //源路径
  302. string sourcePath;
  303. //未选择文件的之后默认是这个,从Text输入框中取
  304. if (openFileDialog1.FileName == "openFileDialog1")
  305. {
  306. fileName = la_name.Text;
  307. sourcePath = FolderPath.Text;
  308. }
  309. else
  310. {
  311. sourcePath = openFileDialog1.FileName.Substring(0, openFileDialog1.FileName.LastIndexOf(@"\"));
  312. fileName = openFileDialog1.FileName.Substring(openFileDialog1.FileName.LastIndexOf(@"\") + 1);
  313. }
  314. if (FTPShare.Checked)
  315. {
  316. ftpOperater ftp = new ftpOperater(false);
  317. ftp.UpLoadFile(sourcePath, fileName);
  318. string SoftWare = "CodeSoft";
  319. if (CL_ID2 != null)
  320. {
  321. sql.Clear();
  322. sql.Append("update customerlabel set cl_labelcode='" + la_code.Text + "',cl_custcode='" + 客户编号.Text + "',");
  323. sql.Append("cl_labeltype='" + la_type1.Text + "',cl_labelname='" + la_name.Text + "',cl_date=sysdate where cl_id=" + CL_ID2);
  324. }
  325. else
  326. {
  327. sql.Clear();
  328. sql.Append("insert into customerlabel (cl_id,cl_labelcode,cl_custcode,cl_labeltype,cl_labelurl,cl_labelname,cl_labelsoft,cl_date) values( customerlabel_seq.nextval, ");
  329. sql.Append("'" + la_code.Text + "','" + (客户编号.Text == "" ? "" : 客户编号.Text) + "','" + la_type1.Text + "','" + ftpOperater.FTPAddress + "','" + la_name.Text + "','" + SoftWare + "',sysdate)");
  330. }
  331. dh.ExecuteSql(sql.ToString(), "insert");
  332. sql.Clear();
  333. }
  334. else
  335. {
  336. //目标路径
  337. string targetPath = NetURL.Text;
  338. //var file = Directory.GetFiles(targetPath);
  339. string sourceFile = Path.Combine(sourcePath, fileName);
  340. string destFile = Path.Combine(targetPath, fileName);
  341. //获取指定路径下的全部文件名
  342. var file = Directory.GetFiles(targetPath);
  343. string overwrite = "";
  344. for (int i = 0; i < file.Length; i++)
  345. {
  346. if (file[i].Substring(file[i].LastIndexOf(@"\") + 1) == fileName)
  347. {
  348. overwrite = MessageBox.Show(this.ParentForm, "已存在名为" + fileName + "的文件,是否覆盖", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  349. break;
  350. }
  351. }
  352. if (overwrite == "Yes" || overwrite == "")
  353. {
  354. //不存在文件家的话进行创建
  355. if (!Directory.Exists(targetPath))
  356. Directory.CreateDirectory(targetPath);
  357. //将文件复制到指定位置
  358. File.Copy(sourceFile, destFile, true);
  359. string SoftWare = "CodeSoft";
  360. sql.Clear();
  361. sql.Append("insert into customerlabel (cl_id,cl_labelcode,cl_custcode,cl_labeltype,cl_labelurl,cl_labelname,cl_labelsoft,cl_date) values( customerlabel_seq.nextval, ");
  362. sql.Append("'" + la_code.Text + "','" + (客户编号.Text == "" ? "共用" : 客户编号.Text) + "','" + la_type1.Text + "','" + destFile + "','" + la_name.Text + "','" + SoftWare + "',sysdate)");
  363. dh.ExecuteSql(sql.ToString(), "insert");
  364. sql.Clear();
  365. }
  366. }
  367. MessageBox.Show("保存成功!");
  368. LoadData();
  369. }
  370. else
  371. {
  372. MessageBox.Show("请填写完整参数!");
  373. }
  374. }
  375. private void 产品标签维护_SizeChanged(object sender, EventArgs e)
  376. {
  377. asc.controlAutoSize(this);
  378. }
  379. private void NetURL_TextChanged(object sender, EventArgs e)
  380. {
  381. Settings.Default.ShareUrl = NetURL.Text;
  382. Settings.Default.Save();
  383. }
  384. private void NewLabel_Click(object sender, EventArgs e)
  385. {
  386. 客户编号.Text = "";
  387. la_type1.Text = "";
  388. la_code.Text = "";
  389. la_name.Text = "";
  390. FolderPath.Text = "";
  391. CL_ID2 = null;
  392. }
  393. }
  394. }