客户标签维护.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  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. Activate();
  76. LogicHandler.CustInit("0");
  77. if (Settings.Default.FTPAddress == "")
  78. {
  79. FTPShare.Visible = false;
  80. }
  81. if (dh.GetConfig("PrintMethod", "CodeOrBar").ToString() == "")
  82. {
  83. CodeSoft.Checked = true;
  84. }
  85. else
  86. {
  87. BarTender.Checked = true;
  88. }
  89. condition.Append("");
  90. ChooseAll.ChooseAll(LabelDataGridView);
  91. //PortModel.Checked = Settings.Default.FTPModel;
  92. BaseUtil.SetComboxData(la_type, "display", "value", labeltype);
  93. //加载下拉框的静态值
  94. LoadData();
  95. Width = Width + 1;
  96. asc.controllInitializeSize(this);
  97. Width = Width + 1;
  98. }
  99. private void LabelDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
  100. {
  101. if (LabelDataGridView.Columns[e.ColumnIndex].HeaderText == "预览")
  102. {
  103. //获取路径和标签名称
  104. LabelPath = LabelDataGridView.Rows[e.RowIndex].Cells["cl_labelurl"].Value.ToString();
  105. LabelCode = LabelDataGridView.Rows[e.RowIndex].Cells["cl_labelcode"].Value.ToString();
  106. CL_ID1 = LabelDataGridView.Rows[e.RowIndex].Cells["cl_id"].Value.ToString();
  107. La_id1 = LabelDataGridView.Rows[e.RowIndex].Cells["la_id"].Value.ToString();
  108. System.DateTime time;
  109. try
  110. {
  111. time = Convert.ToDateTime(LabelDataGridView.Rows[e.RowIndex].Cells["cl_date"].Value.ToString());
  112. }
  113. catch (Exception)
  114. {
  115. time = System.DateTime.Now;
  116. }
  117. if (CodeSoft.Checked)
  118. {
  119. string LabelName = LabelDataGridView.Rows[e.RowIndex].Cells["cl_labelname"].Value.ToString();
  120. //如果文件已不存在则进行提示
  121. }
  122. }
  123. if (LabelDataGridView.Columns[e.ColumnIndex].HeaderText == "编辑")
  124. {
  125. if (e.RowIndex >= 0 && e.ColumnIndex >= 0)
  126. {
  127. CL_ID2 = LabelDataGridView.Rows[e.RowIndex].Cells["cl_id"].Value.ToString();
  128. LabelPath = LabelDataGridView.Rows[e.RowIndex].Cells["cl_labelurl"].Value.ToString();
  129. string LabelName = LabelDataGridView.Rows[e.RowIndex].Cells["cl_labelname"].Value.ToString();
  130. System.DateTime time;
  131. try
  132. {
  133. time = Convert.ToDateTime(LabelDataGridView.Rows[e.RowIndex].Cells["cl_date"].Value.ToString());
  134. }
  135. catch (Exception)
  136. {
  137. time = System.DateTime.Now;
  138. }
  139. BaseUtil.GetLabelUrl(LabelPath, LabelName, time);
  140. System.Diagnostics.Process.Start(ftpOperater.DownLoadTo + LabelName);
  141. 客户编号.Text = LabelDataGridView.Rows[e.RowIndex].Cells["CL_CUSTCODE2"].Value.ToString();
  142. la_type1.Text = LabelDataGridView.Rows[e.RowIndex].Cells["cl_labeltype"].Value.ToString();
  143. la_code.Text = LabelDataGridView.Rows[e.RowIndex].Cells["cl_labelcode"].Value.ToString();
  144. la_name.Text = LabelDataGridView.Rows[e.RowIndex].Cells["cl_labelname"].Value.ToString();
  145. FolderPath.Text = ftpOperater.DownLoadTo;
  146. }
  147. }
  148. //asc.controllInitializeSize(this);
  149. }
  150. private void Screen_Click(object sender, EventArgs e)
  151. {
  152. sql.Clear();
  153. condition.Clear();
  154. //如果条件全部为空的时候
  155. if (cu_code.Text == "" && cu_name.Text == "" && la_type.Text == "")
  156. {
  157. LoadData();
  158. }
  159. else
  160. {
  161. 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 ");
  162. //设置筛选的条件
  163. condition.Append(BaseUtil.GetScreenSqlCondition(cu_code, la_type));
  164. //最终刷选条件拼接成的sql
  165. LoadData();
  166. }
  167. }
  168. private void Update_Click(object sender, EventArgs e)
  169. {
  170. string LabelSoft = "";
  171. //需要处理新增的行和原有数据然后更新的行
  172. if (CodeSoft.Checked)
  173. {
  174. LabelSoft = "CodeSoft";
  175. }
  176. if (BarTender.Checked)
  177. {
  178. LabelSoft = "BarTender";
  179. }
  180. DataTable dt = (DataTable)LabelDataGridView.DataSource;
  181. //如果有改变的行才传递到后台
  182. if (dt.GetChanges() != null)
  183. {
  184. //如果是新增的默认加上Radio当前选中的打印软件
  185. for (int i = 0; i < LabelDataGridView.Rows.Count; i++)
  186. {
  187. if (LabelDataGridView.Rows[i].Cells["cl_labelsoft"].Value.ToString() == "")
  188. {
  189. LabelDataGridView.Rows[i].Cells["cl_labelsoft"].Value = LabelSoft;
  190. }
  191. }
  192. 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)";
  193. dh.UpDateTableByCondition(dt.GetChanges(), "customerlabel", "cl_id", sql.ToLower());
  194. LoadData();
  195. }
  196. }
  197. private void DeleteDetail_Click(object sender, EventArgs e)
  198. {
  199. string[] deleteid = new string[LabelDataGridView.RowCount];
  200. for (int i = 0; i < LabelDataGridView.RowCount; i++)
  201. {
  202. deleteid[i] = LabelDataGridView.Rows[i].Cells["cl_id"].Value.ToString();
  203. }
  204. dh.DeleteDataByID("customerlabel", "cl_id", deleteid);
  205. LoadData();
  206. }
  207. private void OpenFolder_Click(object sender, EventArgs e)
  208. {
  209. //根据勾选的不同设置不同的文件后缀过滤
  210. if (CodeSoft.Checked)
  211. {
  212. openFileDialog1.Filter = "(*.btw)|*.btw";
  213. }
  214. if (BarTender.Checked)
  215. {
  216. openFileDialog1.Filter = "(*.btw)|*.btw";
  217. }
  218. DialogResult result = openFileDialog1.ShowDialog();
  219. if (result == DialogResult.OK)
  220. {
  221. FolderPath.Text = openFileDialog1.FileName;
  222. la_name.Text = FolderPath.Text.Substring(FolderPath.Text.LastIndexOf("\\") + 1);
  223. for (int i = 0; i < LabelDataGridView.Rows.Count; i++)
  224. {
  225. if (LabelDataGridView.Rows[i].Cells["Choose"].Value != null)
  226. {
  227. if ((bool)LabelDataGridView.Rows[i].Cells["Choose"].Value == true)
  228. {
  229. LabelDataGridView.Rows[i].Cells["cl_labelurl"].Value = FolderPath.Text;
  230. }
  231. }
  232. }
  233. }
  234. }
  235. private void LabelDataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
  236. {
  237. if (LabelDataGridView.Columns[e.ColumnIndex].Name == "cl_isdefault")
  238. {
  239. if (e.Value != null)
  240. {
  241. switch (e.Value.ToString())
  242. {
  243. case "0":
  244. e.Value = "否";
  245. break;
  246. case "1":
  247. e.Value = "是";
  248. break;
  249. default:
  250. break;
  251. }
  252. }
  253. }
  254. }
  255. private void LabelDataGridView_DataError(object sender, DataGridViewDataErrorEventArgs e)
  256. {
  257. //覆盖参数错误的事件,使得不会报错
  258. }
  259. private void LoadData()
  260. {
  261. //如果条件和上次一样则不进行数据读取
  262. //if (LastCondition != condition.ToString())
  263. {
  264. //如果没有任何筛选条件直接选取customerlabel的数据
  265. if (sql.Length == 0)
  266. {
  267. 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");
  268. }
  269. else
  270. {
  271. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  272. }
  273. BaseUtil.FillDgvWithDataTable(LabelDataGridView, dt);
  274. string Field = BaseUtil.GetGridViewSelectContent(LabelDataGridView);
  275. 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);
  276. LastCondition = condition.ToString();
  277. }
  278. }
  279. private void PrintTest_Click(object sender, EventArgs e)
  280. {
  281. if (LabelCode != "")
  282. {
  283. }
  284. }
  285. private void 产品标签维护_FormClosing(object sender, FormClosingEventArgs e)
  286. {
  287. try
  288. {
  289. }
  290. catch (Exception)
  291. {
  292. }
  293. }
  294. private void Save_Click(object sender, EventArgs e)
  295. {
  296. if (la_type1.Text != "" && FolderPath.Text != "" && la_code.Text != "")
  297. {
  298. //文件名
  299. string fileName;
  300. //源路径
  301. string sourcePath;
  302. //未选择文件的之后默认是这个,从Text输入框中取
  303. if (openFileDialog1.FileName == "openFileDialog1")
  304. {
  305. fileName = la_name.Text;
  306. sourcePath = FolderPath.Text;
  307. }
  308. else
  309. {
  310. sourcePath = openFileDialog1.FileName.Substring(0, openFileDialog1.FileName.LastIndexOf(@"\"));
  311. fileName = openFileDialog1.FileName.Substring(openFileDialog1.FileName.LastIndexOf(@"\") + 1);
  312. }
  313. if (FTPShare.Checked)
  314. {
  315. ftpOperater ftp = new ftpOperater(PortModel.Checked);
  316. ftp.UpLoadFile(sourcePath, fileName);
  317. string SoftWare = CodeSoft.Checked ? "CodeSoft" : "BarTender";
  318. if (CL_ID2 != null)
  319. {
  320. sql.Clear();
  321. sql.Append("update customerlabel set cl_labelcode='" + la_code.Text + "',cl_custcode='" + 客户编号.Text + "',");
  322. sql.Append("cl_labeltype='" + la_type1.Text + "',cl_labelname='" + la_name.Text + "',cl_date=sysdate where cl_id=" + CL_ID2);
  323. }
  324. else
  325. {
  326. 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");
  327. if (dt.Rows.Count > 0)
  328. {
  329. MessageBox.Show("已有名称为" + la_name.Text + "的标签用作" + dt.Rows[0]["cl_custcode"].ToString() + dt.Rows[0]["cl_labeltype"].ToString());
  330. return;
  331. }
  332. sql.Clear();
  333. 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, ");
  334. sql.Append("'" + la_code.Text + "','" + (客户编号.Text == "" ? "" : 客户编号.Text) + "','" + la_type1.Text + "','" + ftpOperater.FTPAddress + "','" + la_name.Text + "','" + SoftWare + "',sysdate)");
  335. }
  336. dh.ExecuteSql(sql.ToString(), "insert");
  337. sql.Clear();
  338. }
  339. else
  340. {
  341. //目标路径
  342. string targetPath = NetURL.Text;
  343. //var file = Directory.GetFiles(targetPath);
  344. string sourceFile = Path.Combine(sourcePath, fileName);
  345. string destFile = Path.Combine(targetPath, fileName);
  346. //获取指定路径下的全部文件名
  347. var file = Directory.GetFiles(targetPath);
  348. string overwrite = "";
  349. for (int i = 0; i < file.Length; i++)
  350. {
  351. if (file[i].Substring(file[i].LastIndexOf(@"\") + 1) == fileName)
  352. {
  353. overwrite = MessageBox.Show(this.ParentForm, "已存在名为" + fileName + "的文件,是否覆盖", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  354. break;
  355. }
  356. }
  357. if (overwrite == "Yes" || overwrite == "")
  358. {
  359. //不存在文件家的话进行创建
  360. if (!Directory.Exists(targetPath))
  361. Directory.CreateDirectory(targetPath);
  362. //将文件复制到指定位置
  363. File.Copy(sourceFile, destFile, true);
  364. string SoftWare = "CodeSoft";
  365. sql.Clear();
  366. 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, ");
  367. sql.Append("'" + la_code.Text + "','" + (客户编号.Text == "" ? "共用" : 客户编号.Text) + "','" + la_type1.Text + "','" + destFile + "','" + la_name.Text + "','" + SoftWare + "',sysdate)");
  368. dh.ExecuteSql(sql.ToString(), "insert");
  369. sql.Clear();
  370. }
  371. }
  372. MessageBox.Show("保存成功!");
  373. LoadData();
  374. }
  375. else
  376. {
  377. MessageBox.Show("请填写完整参数!");
  378. }
  379. }
  380. private void 产品标签维护_SizeChanged(object sender, EventArgs e)
  381. {
  382. asc.controlAutoSize(this);
  383. }
  384. private void NetURL_TextChanged(object sender, EventArgs e)
  385. {
  386. Settings.Default.ShareUrl = NetURL.Text;
  387. Settings.Default.Save();
  388. }
  389. private void NewLabel_Click(object sender, EventArgs e)
  390. {
  391. 客户编号.Text = "";
  392. la_type1.Text = "";
  393. la_code.Text = "";
  394. la_name.Text = "";
  395. FolderPath.Text = "";
  396. CL_ID2 = null;
  397. }
  398. private void PortModel_CheckedChanged(object sender, EventArgs e)
  399. {
  400. Settings.Default.FTPModel = PortModel.Checked;
  401. Settings.Default.Save();
  402. }
  403. }
  404. }