客户标签维护.cs 19 KB

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