客户标签维护.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  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. namespace UAS_LabelMachine
  12. {
  13. public partial class 客户标签维护 : Form
  14. {
  15. DataHelper dh;
  16. DataTable dt;
  17. //设置Grid中Combox的静态数据,这个格式是必须的,#前面是展示值,#后面是实际值
  18. string[] labeltype = { "单盘#单盘", "中盒#中盒", "外箱#外箱", "全部#" };
  19. //记录上次筛选时的条件,如果本次和上次相同则不进行查询
  20. string LastCondition = "";
  21. //用于拼接条件查询
  22. StringBuilder condition = new StringBuilder();
  23. StringBuilder sql = new StringBuilder();
  24. /*CodeSoft新建打印机引擎*/
  25. ApplicationClass lbl;
  26. Document doc;
  27. /*BarTender新建打印机引擎*/
  28. //private Engine engine = null;
  29. //private LabelFormatDocument format ;
  30. //点击行的LabelCode
  31. string LabelCode = "";
  32. //模板的路径
  33. string LabelPath = "";
  34. //模板编号的ID
  35. string CL_ID1;
  36. string CL_ID2;
  37. //Label表的主键,用于弹窗的传参
  38. string La_id1;
  39. //添加在grid末列的操作列
  40. DataGridViewImageColumn PreviewColumn = new DataGridViewImageColumn
  41. {
  42. Image = Resources.preview_16px_25980_easyicon_net,
  43. Width = 40,
  44. Name = "预览",
  45. ToolTipText = "预览模板参数",
  46. Tag = "Read",
  47. AutoSizeMode = DataGridViewAutoSizeColumnMode.None
  48. };
  49. DataGridViewImageColumn OperateColumn = new DataGridViewImageColumn
  50. {
  51. Image = Resources.write_15_893687707641px_1181413_easyicon_net,
  52. Width = 40,
  53. Name = "编辑",
  54. ToolTipText = "编辑模板",
  55. Tag = "Read",
  56. AutoSizeMode = DataGridViewAutoSizeColumnMode.None
  57. };
  58. AutoSizeFormClass asc = new AutoSizeFormClass();
  59. public 客户标签维护()
  60. {
  61. InitializeComponent();
  62. cu_code.FormName = Name;
  63. cu_code.SetValueField = new string[] { "cu_code", "cu_name" };
  64. cu_code.TableName = "(select distinct cu_code,cu_name from customer left join customerlabel on cu_code=cl_custcode)";
  65. cu_code.SelectField = "cu_code # 客户编号,cu_name # 客户名称";
  66. 客户编号.FormName = Name;
  67. 客户编号.SetValueField = new string[] { "客户编号" };
  68. 客户编号.TableName = "(select distinct cu_code,cu_name from customer left join customerlabel on cu_code=cl_custcode)";
  69. 客户编号.SelectField = "cu_code # 客户编号,cu_name # 客户名称";
  70. la_code.FormName = Name;
  71. la_code.SetValueField = new string[] { "la_code" };
  72. la_code.TableName = "label";
  73. la_code.SelectField = "la_code # 模板编号,la_name # 模板名称";
  74. NetURL.Text = Settings.Default.ShareUrl;
  75. }
  76. private void 条码维护_Load(object sender, EventArgs e)
  77. {
  78. if (Settings.Default.FTPAddress == "")
  79. {
  80. FTPShare.Visible = false;
  81. }
  82. dh = new DataHelper();
  83. condition.Append("");
  84. ChooseAll.ChooseAll(LabelDataGridView);
  85. BaseUtil.SetComboxData(la_type, "display", "value", labeltype);
  86. //加载下拉框的静态值
  87. LoadData();
  88. Width = Width + 1;
  89. asc.controllInitializeSize(this);
  90. lbl = new ApplicationClass();
  91. Width = Width + 1;
  92. }
  93. private void LabelDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
  94. {
  95. if (LabelDataGridView.Columns[e.ColumnIndex].HeaderText == "预览")
  96. {
  97. if (lbl.Documents.Count > 0)
  98. {
  99. lbl.ActiveDocument.Close();
  100. }
  101. //获取路径和标签名称
  102. LabelPath = LabelDataGridView.Rows[e.RowIndex].Cells["cl_labelurl"].Value.ToString();
  103. LabelCode = LabelDataGridView.Rows[e.RowIndex].Cells["cl_labelcode"].Value.ToString();
  104. CL_ID1 = LabelDataGridView.Rows[e.RowIndex].Cells["cl_id"].Value.ToString();
  105. La_id1 = LabelDataGridView.Rows[e.RowIndex].Cells["la_id"].Value.ToString();
  106. System.DateTime time = Convert.ToDateTime(LabelDataGridView.Rows[e.RowIndex].Cells["cl_date"].Value.ToString());
  107. if (CodeSoft.Checked)
  108. {
  109. string LabelName = LabelDataGridView.Rows[e.RowIndex].Cells["cl_labelname"].Value.ToString();
  110. doc = lbl.Documents.Open(BaseUtil.GetLabelUrl(LabelPath, LabelName,time));
  111. Bitmap bit = new Bitmap(doc.CopyImageToFile());
  112. pictureBox1.Image = bit;
  113. //如果文件已不存在则进行提示
  114. if (doc == null)
  115. {
  116. return;
  117. }
  118. }
  119. }
  120. if (LabelDataGridView.Columns[e.ColumnIndex].HeaderText == "编辑")
  121. {
  122. if (e.RowIndex >= 0 && e.ColumnIndex >= 0)
  123. {
  124. CL_ID2 = LabelDataGridView.Rows[e.RowIndex].Cells["cl_id"].Value.ToString();
  125. LabelPath = LabelDataGridView.Rows[e.RowIndex].Cells["cl_labelurl"].Value.ToString();
  126. string LabelName = LabelDataGridView.Rows[e.RowIndex].Cells["cl_labelname"].Value.ToString();
  127. System.DateTime time = Convert.ToDateTime(LabelDataGridView.Rows[e.RowIndex].Cells["cl_date"].Value.ToString());
  128. BaseUtil.GetLabelUrl(LabelPath, LabelName, time);
  129. System.Diagnostics.Process.Start(ftpOperater.DownLoadTo + LabelName);
  130. 客户编号.Text = LabelDataGridView.Rows[e.RowIndex].Cells["CL_CUSTCODE2"].Value.ToString();
  131. la_type1.Text = LabelDataGridView.Rows[e.RowIndex].Cells["cl_labeltype"].Value.ToString();
  132. la_code.Text = LabelDataGridView.Rows[e.RowIndex].Cells["cl_labelcode"].Value.ToString();
  133. la_name.Text = LabelDataGridView.Rows[e.RowIndex].Cells["cl_labelname"].Value.ToString();
  134. FolderPath.Text = ftpOperater.DownLoadTo;
  135. }
  136. }
  137. //asc.controllInitializeSize(this);
  138. }
  139. private void Screen_Click(object sender, EventArgs e)
  140. {
  141. sql.Clear();
  142. condition.Clear();
  143. //如果条件全部为空的时候
  144. if (cu_code.Text == "" && cu_name.Text == "" && la_type.Text == "")
  145. {
  146. LoadData();
  147. }
  148. else
  149. {
  150. 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 ");
  151. //设置筛选的条件
  152. condition.Append(BaseUtil.GetScreenSqlCondition(cu_code, la_type));
  153. //最终刷选条件拼接成的sql
  154. LoadData();
  155. }
  156. }
  157. private void Update_Click(object sender, EventArgs e)
  158. {
  159. string LabelSoft = "";
  160. //需要处理新增的行和原有数据然后更新的行
  161. if (CodeSoft.Checked)
  162. {
  163. LabelSoft = "CodeSoft";
  164. }
  165. DataTable dt = (DataTable)LabelDataGridView.DataSource;
  166. //如果有改变的行才传递到后台
  167. if (dt.GetChanges() != null)
  168. {
  169. //如果是新增的默认加上Radio当前选中的打印软件
  170. for (int i = 0; i < LabelDataGridView.Rows.Count; i++)
  171. {
  172. if (LabelDataGridView.Rows[i].Cells["cl_labelsoft"].Value.ToString() == "")
  173. {
  174. LabelDataGridView.Rows[i].Cells["cl_labelsoft"].Value = LabelSoft;
  175. }
  176. }
  177. 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)";
  178. dh.UpDateTableByCondition(dt.GetChanges(), "customerlabel", "cl_id", sql.ToLower());
  179. LoadData();
  180. }
  181. }
  182. private void DeleteDetail_Click(object sender, EventArgs e)
  183. {
  184. string[] deleteid = new string[LabelDataGridView.RowCount];
  185. for (int i = 0; i < LabelDataGridView.RowCount; i++)
  186. {
  187. deleteid[i] = LabelDataGridView.Rows[i].Cells["cl_id"].Value.ToString();
  188. }
  189. dh.DeleteDataByID("customerlabel", "cl_id", deleteid);
  190. LoadData();
  191. }
  192. private void OpenFolder_Click(object sender, EventArgs e)
  193. {
  194. //根据勾选的不同设置不同的文件后缀过滤
  195. if (CodeSoft.Checked)
  196. {
  197. openFileDialog1.Filter = "(*.lab)|*.lab";
  198. }
  199. DialogResult result = openFileDialog1.ShowDialog();
  200. if (result == DialogResult.OK)
  201. {
  202. FolderPath.Text = openFileDialog1.FileName;
  203. la_name.Text = FolderPath.Text.Substring(FolderPath.Text.LastIndexOf("\\") + 1);
  204. for (int i = 0; i < LabelDataGridView.Rows.Count; i++)
  205. {
  206. if (LabelDataGridView.Rows[i].Cells["Choose"].Value != null)
  207. {
  208. if ((bool)LabelDataGridView.Rows[i].Cells["Choose"].Value == true)
  209. {
  210. LabelDataGridView.Rows[i].Cells["cl_labelurl"].Value = FolderPath.Text;
  211. }
  212. }
  213. }
  214. }
  215. }
  216. private void LabelDataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
  217. {
  218. if (LabelDataGridView.Columns[e.ColumnIndex].Name == "cl_isdefault")
  219. {
  220. if (e.Value != null)
  221. {
  222. switch (e.Value.ToString())
  223. {
  224. case "0":
  225. e.Value = "否";
  226. break;
  227. case "1":
  228. e.Value = "是";
  229. break;
  230. default:
  231. break;
  232. }
  233. }
  234. }
  235. }
  236. private void LabelDataGridView_DataError(object sender, DataGridViewDataErrorEventArgs e)
  237. {
  238. //覆盖参数错误的事件,使得不会报错
  239. }
  240. private void LoadData()
  241. {
  242. //如果条件和上次一样则不进行数据读取
  243. //if (LastCondition != condition.ToString())
  244. {
  245. //如果没有任何筛选条件直接选取customerlabel的数据
  246. if (sql.Length == 0)
  247. {
  248. 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");
  249. }
  250. else
  251. {
  252. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  253. }
  254. BaseUtil.FillDgvWithDataTable(LabelDataGridView, dt);
  255. string Field = BaseUtil.GetGridViewSelectContent(LabelDataGridView);
  256. 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);
  257. LastCondition = condition.ToString();
  258. }
  259. }
  260. private void PrintTest_Click(object sender, EventArgs e)
  261. {
  262. if (LabelCode != "")
  263. {
  264. doc.Printer.SwitchTo(PrinterList.Text);
  265. doc.PrintDocument();
  266. }
  267. }
  268. private void 产品标签维护_FormClosing(object sender, FormClosingEventArgs e)
  269. {
  270. try
  271. {
  272. lbl.Documents.CloseAll();
  273. lbl.Application.Quit();
  274. }
  275. catch (Exception)
  276. {
  277. }
  278. }
  279. private void Save_Click(object sender, EventArgs e)
  280. {
  281. if (la_type1.Text != "" && FolderPath.Text != "" && la_code.Text != "")
  282. {
  283. //文件名
  284. string fileName;
  285. //源路径
  286. string sourcePath;
  287. //未选择文件的之后默认是这个,从Text输入框中取
  288. if (openFileDialog1.FileName == "openFileDialog1")
  289. {
  290. fileName = la_name.Text;
  291. sourcePath = FolderPath.Text;
  292. }
  293. else
  294. {
  295. sourcePath = openFileDialog1.FileName.Substring(0, openFileDialog1.FileName.LastIndexOf(@"\"));
  296. fileName = openFileDialog1.FileName.Substring(openFileDialog1.FileName.LastIndexOf(@"\") + 1);
  297. }
  298. if (FTPShare.Checked)
  299. {
  300. ftpOperater ftp = new ftpOperater();
  301. ftp.UpLoadFile(sourcePath, fileName);
  302. string SoftWare = "CodeSoft";
  303. if (CL_ID2 != null)
  304. {
  305. sql.Clear();
  306. sql.Append("update customerlabel set cl_labelcode='" + la_code.Text + "',cl_custcode='" + 客户编号.Text + "',");
  307. sql.Append("cl_labeltype='" + la_type1.Text + "',cl_labelname='" + la_name.Text + "',cl_date=sysdate where cl_id=" + CL_ID2);
  308. }
  309. else
  310. {
  311. sql.Clear();
  312. 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, ");
  313. sql.Append("'" + la_code.Text + "','" + (客户编号.Text == "" ? "" : 客户编号.Text) + "','" + la_type1.Text + "','" + ftpOperater.FTPAddress + "','" + la_name.Text + "','" + SoftWare + "',sysdate)");
  314. }
  315. dh.ExecuteSql(sql.ToString(), "insert");
  316. sql.Clear();
  317. }
  318. else
  319. {
  320. //目标路径
  321. string targetPath = NetURL.Text;
  322. //var file = Directory.GetFiles(targetPath);
  323. string sourceFile = Path.Combine(sourcePath, fileName);
  324. string destFile = Path.Combine(targetPath, fileName);
  325. //获取指定路径下的全部文件名
  326. var file = Directory.GetFiles(targetPath);
  327. string overwrite = "";
  328. for (int i = 0; i < file.Length; i++)
  329. {
  330. if (file[i].Substring(file[i].LastIndexOf(@"\") + 1) == fileName)
  331. {
  332. overwrite = MessageBox.Show(this.ParentForm, "已存在名为" + fileName + "的文件,是否覆盖", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  333. break;
  334. }
  335. }
  336. if (overwrite == "Yes" || overwrite == "")
  337. {
  338. //不存在文件家的话进行创建
  339. if (!Directory.Exists(targetPath))
  340. Directory.CreateDirectory(targetPath);
  341. //将文件复制到指定位置
  342. File.Copy(sourceFile, destFile, true);
  343. string SoftWare = "CodeSoft";
  344. sql.Clear();
  345. 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, ");
  346. sql.Append("'" + la_code.Text + "','" + (客户编号.Text == "" ? "共用" : 客户编号.Text) + "','" + la_type1.Text + "','" + destFile + "','" + la_name.Text + "','" + SoftWare + "',sysdate)");
  347. dh.ExecuteSql(sql.ToString(), "insert");
  348. sql.Clear();
  349. }
  350. }
  351. MessageBox.Show("保存成功!");
  352. LoadData();
  353. }
  354. else
  355. {
  356. MessageBox.Show("请填写完整参数!");
  357. }
  358. }
  359. private void 产品标签维护_SizeChanged(object sender, EventArgs e)
  360. {
  361. asc.controlAutoSize(this);
  362. }
  363. private void NetURL_TextChanged(object sender, EventArgs e)
  364. {
  365. Settings.Default.ShareUrl = NetURL.Text;
  366. Settings.Default.Save();
  367. }
  368. private void NewLabel_Click(object sender, EventArgs e)
  369. {
  370. 客户编号.Text = "";
  371. la_type1.Text = "";
  372. la_code.Text = "";
  373. la_name.Text = "";
  374. FolderPath.Text = "";
  375. CL_ID2 = null;
  376. }
  377. }
  378. }