SystemSetting_LabelMaintain.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. using LabelManager2;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.IO;
  6. using System.Drawing;
  7. using System.Text;
  8. using System.Threading;
  9. using System.Windows.Forms;
  10. using UAS_MES_NEW.CustomControl.TextBoxWithIcon;
  11. using UAS_MES_NEW.DataOperate;
  12. using UAS_MES_NEW.Properties;
  13. using UAS_MES_NEW.PublicForm;
  14. using UAS_MES_NEW.PublicMethod;
  15. namespace UAS_MES_NEW.SystemSetting
  16. {
  17. public partial class SystemSetting_LabelMaintain : Form
  18. {
  19. DataHelper dh;
  20. DataTable dt;
  21. //设置Grid中Combox的静态数据,这个格式是必须的,#前面是展示值,#后面是实际值
  22. string[] labeltype = { "机身标#机身标", "彩盒标#彩盒标", "卡通箱标#卡通箱标", "大箱标#大箱标", "栈板标#栈板标", "SN标签#SN标签", "自定义#自定义"};
  23. string[] defaultype = { "是#1", "否#0" };
  24. Dictionary<string, string> dic = new Dictionary<string, string>();
  25. //用于拼接条件查询
  26. StringBuilder condition = new StringBuilder();
  27. LogStringBuilder sql = new LogStringBuilder();
  28. /*CodeSoft新建打印机引擎*/
  29. ApplicationClass lbl;
  30. Document doc;
  31. /*BarTender新建打印机引擎*/
  32. //private Engine engine = null;
  33. //private LabelFormatDocument format ;
  34. //点击行的LabelCode
  35. string LabelCode = "";
  36. //模板的路径
  37. string LabelPath = "";
  38. //参数个数
  39. int ParamNum;
  40. //标签参数的数组
  41. string[] ParamName;
  42. //模板编号的ID
  43. string pl_id1;
  44. //用于保存更新的模板ID
  45. string pl_id2 = "";
  46. //用于保存更新的产品编号
  47. string pr_code_1 = "";
  48. //用于保存更新的标签名
  49. string la_type_1 = "";
  50. //用于保存更新的模板默认值
  51. string pl_default = "";
  52. //Label表的主键,用于弹窗的传参
  53. string La_id1;
  54. //添加在grid末列的操作列
  55. DataTable dbfind;
  56. ftpOperater ftp;
  57. Thread InitPrint;
  58. DataGridViewImageColumn PerviewColumn = new DataGridViewImageColumn
  59. {
  60. Image = Resources.preview_16px_25980_easyicon_net,
  61. Width = 40,
  62. Name = "预览",
  63. ToolTipText = "预览模板参数",
  64. Tag = "Read",
  65. AutoSizeMode = DataGridViewAutoSizeColumnMode.None
  66. };
  67. DataGridViewImageColumn OperateColumn = new DataGridViewImageColumn
  68. {
  69. Image = Resources.write_15_893687707641px_1181413_easyicon_net,
  70. Width = 40,
  71. Name = "编辑",
  72. ToolTipText = "编辑模板",
  73. Tag = "Read",
  74. AutoSizeMode = DataGridViewAutoSizeColumnMode.None
  75. };
  76. Thread thread;
  77. AutoSizeFormClass asc = new AutoSizeFormClass();
  78. public SystemSetting_LabelMaintain()
  79. {
  80. InitializeComponent();
  81. }
  82. private void 条码维护_Load(object sender, EventArgs e)
  83. {
  84. asc.controllInitializeSize(this);
  85. dh = new DataHelper();
  86. condition.Append(" ");
  87. LoadData();
  88. //加loading框
  89. InitPrint = new Thread(InPrint);
  90. SetLoadingWindow stw = new SetLoadingWindow(InitPrint, "初始化打印程序");
  91. BaseUtil.SetFormCenter(stw);
  92. stw.ShowDialog();
  93. pr_code.FormName = Name;
  94. pr_code.SetValueField = new string[] { "pr_code" };
  95. pr_code.TableName = "product";
  96. pr_code.SelectField = "pr_code # 物料编号,pr_detail # 物料名称,pr_kind # 物料种类,pr_spec # 物料规格";
  97. pr_code.DbChange += Pr_code_DbChange;
  98. la_code.FormName = Name;
  99. la_code.SetValueField = new string[] { "la_code" };
  100. la_code.TableName = "label";
  101. la_code.SelectField = "la_code # 标签编号,la_name # 标签名称";
  102. la_code.DbChange += La_code_DbChange;
  103. //加载下拉框的静态值
  104. BaseUtil.SetDgvColumnComboxData((DataGridViewComboBoxColumn)LabelDataGridView.Columns["pl_labeltype"], "pl_labeltype", "display", "value", labeltype);
  105. BaseUtil.SetDgvColumnComboxData((DataGridViewComboBoxColumn)LabelDataGridView.Columns["pl_isdefault"], "pl_isdefault", "display", "value", defaultype);
  106. ChooseAll.ChooseAll(LabelDataGridView);
  107. pr_code2.KeyDown += ScreenEvent;
  108. pr_detail.KeyDown += ScreenEvent;
  109. pr_spec.KeyDown += ScreenEvent;
  110. SavePath.Text = Properties.Settings.Default.Properties["FTPAddress"].DefaultValue.ToString();
  111. //BaseUtil.SetCacheData("SavePath", SavePath.Text);
  112. ftp = new ftpOperater();
  113. }
  114. private void InPrint()
  115. {
  116. try
  117. {
  118. lbl = new ApplicationClass();
  119. BaseUtil.WriteLbl();
  120. }
  121. catch (Exception ex)
  122. {
  123. MessageBox.Show("未正确安装codesoft");
  124. }
  125. }
  126. private void La_code_DbChange(object sender, EventArgs e)
  127. {
  128. dbfind = la_code.ReturnData;
  129. BaseUtil.SetFormValue(this.Controls, dbfind);
  130. }
  131. private void Pr_code_DbChange(object sender, EventArgs e)
  132. {
  133. dbfind = pr_code.ReturnData;
  134. BaseUtil.SetFormValue(this.Controls, dbfind);
  135. }
  136. private void LabelDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
  137. {
  138. if (e.ColumnIndex >= 0 && e.RowIndex >= 0)
  139. {
  140. if (LabelDataGridView.Columns[e.ColumnIndex].HeaderText == "预览")
  141. {
  142. //获取路径和标签名称
  143. LabelPath = LabelDataGridView.Rows[e.RowIndex].Cells["pl_labelurl"].Value.ToString();
  144. LabelCode = LabelDataGridView.Rows[e.RowIndex].Cells["pl_labelcode"].Value.ToString();
  145. pl_id1 = LabelDataGridView.Rows[e.RowIndex].Cells["pl_id"].Value.ToString();
  146. La_id1 = LabelDataGridView.Rows[e.RowIndex].Cells["la_id"].Value.ToString();
  147. if (CodeSoft.Checked)
  148. {
  149. string LabelName = LabelDataGridView.Rows[e.RowIndex].Cells["pl_labelname"].Value.ToString();
  150. doc = lbl.Documents.Open(BaseUtil.GetLabelUrl(LabelPath, LabelName));
  151. if (doc == null)
  152. {
  153. MessageBox.Show("指定位置文件不存在");
  154. return;
  155. }
  156. ParamNum = doc.Variables.FreeVariables.Count;
  157. //去除之前添加的控件
  158. for (int i = 0; i < (ParamName == null ? 0 : ParamName.Length); i++)
  159. {
  160. if (this.Controls["LabelParam"].Controls[ParamName[i] + "_label"] != null)
  161. {
  162. this.Controls["LabelParam"].Controls.Remove(this.Controls["LabelParam"].Controls[ParamName[i] + "_label"]);
  163. this.Controls["LabelParam"].Controls.Remove(this.Controls["LabelParam"].Controls[ParamName[i]]);
  164. }
  165. }
  166. ParamName = new string[ParamNum];
  167. for (int i = 0; i < ParamNum; i++)
  168. {
  169. ParamName[i] = doc.Variables.FreeVariables.Item(i + 1).Name;
  170. }
  171. int y = 20;
  172. for (int i = 0; i < ParamName.Length; i++)
  173. {
  174. //变量的名称Label
  175. Label Param = new Label();
  176. Param.Text = ParamName[i];
  177. Param.Name = ParamName[i] + "_label";
  178. Param.AutoSize = true;
  179. Param.Anchor = AnchorStyles.Left;
  180. Param.Anchor = AnchorStyles.Top;
  181. Param.Location = new Point(30, y + 5);
  182. this.Controls["LabelParam"].Controls.Add(Param);
  183. //维护变量的打印测试参数
  184. EnterTextBox TempParam = new EnterTextBox();
  185. TempParam.Anchor = AnchorStyles.Left;
  186. TempParam.Anchor = AnchorStyles.Top;
  187. TempParam.Name = ParamName[i];
  188. TempParam.Location = new Point(110, y);
  189. y = y + 30;
  190. TempParam.Size = new Size(170, 22);
  191. this.Controls["LabelParam"].Controls.Add(TempParam);
  192. y = y + 30;
  193. }
  194. doc.Close();
  195. }
  196. }
  197. if (LabelDataGridView.Columns[e.ColumnIndex].HeaderText == "编辑")
  198. {
  199. if (e.RowIndex >= 0 && e.ColumnIndex >= 0)
  200. {
  201. LabelPath = LabelDataGridView.Rows[e.RowIndex].Cells["pl_labelurl"].Value.ToString();
  202. string LabelName = LabelDataGridView.Rows[e.RowIndex].Cells["pl_labelname"].Value.ToString();
  203. pr_code.Text = LabelDataGridView.Rows[e.RowIndex].Cells["pr_code1"].Value.ToString();
  204. la_code.Text = LabelDataGridView.Rows[e.RowIndex].Cells["pl_labelcode"].Value.ToString();
  205. la_name.Text = LabelDataGridView.Rows[e.RowIndex].Cells["pl_labelname"].Value.ToString();
  206. la_type.Text = LabelDataGridView.Rows[e.RowIndex].Cells["pl_labeltype"].Value.ToString();
  207. FolderPath.Text = ftpOperater.DownLoadTo;
  208. pl_id2 = LabelDataGridView.Rows[e.RowIndex].Cells["pl_id"].Value.ToString();
  209. pr_code_1 = LabelDataGridView.Rows[e.RowIndex].Cells["pr_code1"].Value.ToString();
  210. la_type_1 = LabelDataGridView.Rows[e.RowIndex].Cells["pl_labeltype"].Value.ToString();
  211. pl_default = LabelDataGridView.Rows[e.RowIndex].Cells["pl_isdefault"].Value.ToString();
  212. System.Diagnostics.Process.Start(BaseUtil.GetLabelUrl(LabelPath, LabelName));
  213. }
  214. }
  215. }
  216. }
  217. private void Screen_Click(object sender, EventArgs e)
  218. {
  219. sql.Clear();
  220. condition.Clear();
  221. //如果条件全部为空的时候
  222. if (pr_code2.Text == "" && pr_detail.Text == "" && pr_spec.Text == "")
  223. {
  224. LoadData();
  225. }
  226. else
  227. {
  228. sql.Append("select pl_labelurl,pl_labeltype,pl_labelname,pl_isdefault,pl_prodcode,pl_id,pl_labelcode,pl_detno,pl_labelsoft,pr_detail,pr_spec,pr_code from productlabel left join product on pl_prodcode=pr_code");
  229. //设置筛选的条件
  230. condition.Append(BaseUtil.GetScreenSqlCondition(pr_code2, pr_detail, pr_spec));
  231. //最终刷选条件拼接成的sql
  232. LoadData();
  233. }
  234. }
  235. private void Update_Click(object sender, EventArgs e)
  236. {
  237. string LabelSoft = "";
  238. //需要处理新增的行和原有数据然后更新的行
  239. if (CodeSoft.Checked)
  240. {
  241. LabelSoft = "CodeSoft";
  242. }
  243. DataTable dt = (DataTable)LabelDataGridView.DataSource;
  244. //如果有改变的行才传递到后台
  245. if (dt.GetChanges() != null)
  246. {
  247. for (int i = 0; i < LabelDataGridView.Rows.Count; i++)
  248. {
  249. //如果是新增的默认加上Radio当前选中的打印软件
  250. if (LabelDataGridView.Rows[i].Cells["pl_labelsoft"].Value.ToString() == "")
  251. {
  252. LabelDataGridView.Rows[i].Cells["pl_labelsoft"].Value = LabelSoft;
  253. }
  254. //从表格判断一个产品以及对应的打印模板是否存在默认选项
  255. if (!dic.ContainsKey(LabelDataGridView.Rows[i].Cells["pl_prodcode"].Value.ToString() + LabelDataGridView.Rows[i].Cells["pl_labeltype"].Value.ToString()))
  256. {
  257. dic.Add(LabelDataGridView.Rows[i].Cells["pl_prodcode"].Value.ToString() + LabelDataGridView.Rows[i].Cells["pl_labeltype"].Value.ToString(), LabelDataGridView.Rows[i].Cells["pl_isdefault"].Value.ToString());
  258. }
  259. else
  260. {
  261. string outvalue = dic[LabelDataGridView.Rows[i].Cells["pl_prodcode"].Value.ToString() + LabelDataGridView.Rows[i].Cells["pl_labeltype"].Value.ToString()];
  262. if (outvalue == "0")
  263. {
  264. dic[LabelDataGridView.Rows[i].Cells["pl_prodcode"].Value.ToString() + LabelDataGridView.Rows[i].Cells["pl_labeltype"].Value.ToString()] = LabelDataGridView.Rows[i].Cells["pl_isdefault"].Value.ToString();
  265. }
  266. else if (LabelDataGridView.Rows[i].Cells["pl_isdefault"].Value.ToString() == "1" && (LabelDataGridView.Rows[i].Cells["pl_prodcode"].Value.ToString() == LabelDataGridView.Rows[i - 1].Cells["pl_prodcode"].Value.ToString()) && (LabelDataGridView.Rows[i].Cells["pl_labeltype"].Value.ToString() == LabelDataGridView.Rows[i - 1].Cells["pl_labeltype"].Value.ToString()))
  267. {
  268. MessageBox.Show("产品"+LabelDataGridView.Rows[i].Cells["pr_detail1"].Value.ToString() +" "+ LabelDataGridView.Rows[i].Cells["pl_labeltype"].Value.ToString()+ " 保存的模板之前具有默认模板");
  269. LabelDataGridView.Rows[i].Cells["pl_isdefault"].Value = "0";
  270. }
  271. }
  272. //从数据库核对是否同时存在一个产品以及对应打印模板是否存在默认选项
  273. DataTable table = (DataTable)dh.ExecuteSql("select pl_isdefault from productlabel where pl_id = '" + LabelDataGridView.Rows[i].Cells["pl_id"].Value.ToString() + " '", "select");
  274. if (LabelDataGridView.Rows[i].Cells["pl_isdefault"].Value.ToString() == "1" && table.Rows[0][0].ToString() == "0")
  275. {
  276. int is_defualt = isdefault(LabelDataGridView.Rows[i].Cells["pl_prodcode"].Value.ToString(), LabelDataGridView.Rows[i].Cells["pl_labeltype"].Value.ToString());
  277. if (is_defualt == 0)
  278. {
  279. MessageBox.Show("产品" + LabelDataGridView.Rows[i].Cells["pr_detail1"].Value.ToString()+" "+ LabelDataGridView.Rows[i].Cells["pl_labeltype"].Value.ToString()+ " 保存的模板之前具有默认模板");
  280. LabelDataGridView.Rows[i].Cells["pl_isdefault"].Value = is_defualt;
  281. }
  282. }
  283. }
  284. string sql = "Insert into productlabel (PL_ID,PL_PRODCODE,PL_LABELTYPE,PL_LABELCODE,PL_LABELURL,PL_DETNO,PL_LABELSOFT,PL_ISDEFAULT) values( ProductLabel_seq.nextval,'" + pr_code.Text + "',:PL_LABELTYPE,:PL_LABELCODE,:PL_LABELURL,:PL_DETNO,:PL_LABELSOFT,:PL_ISDEFAULT )";
  285. dh.SaveDataTable(dt.GetChanges(), "productlabel", "pl_id", sql.ToLower());
  286. LoadData();
  287. dic.Clear();
  288. }
  289. }
  290. private void DeleteDetail_Click(object sender, EventArgs e)
  291. {
  292. string[] deleteid = new string[LabelDataGridView.RowCount];
  293. for (int i = 0; i < LabelDataGridView.RowCount; i++)
  294. {
  295. deleteid[i] = LabelDataGridView.Rows[i].Cells["pl_id"].Value.ToString();
  296. }
  297. dh.DeleteDataByID("productlabel", "pl_id", deleteid);
  298. LoadData();
  299. }
  300. private void OpenFolder_Click(object sender, EventArgs e)
  301. {
  302. //根据勾选的不同设置不同的文件后缀过滤
  303. if (CodeSoft.Checked)
  304. {
  305. openFileDialog1.Filter = "(*.lab)|*.lab";
  306. }
  307. DialogResult result = openFileDialog1.ShowDialog();
  308. if (result == DialogResult.OK)
  309. {
  310. string FullPath = openFileDialog1.FileName;
  311. FolderPath.Text = FullPath.Substring(0, FullPath.LastIndexOf("\\"));
  312. la_name.Text = FullPath.Substring(FullPath.LastIndexOf("\\") + 1);
  313. //for (int i = 0; i < LabelDataGridView.Rows.Count; i++)
  314. //{
  315. // if (LabelDataGridView.Rows[i].Cells["Choose"].Value != null)
  316. // {
  317. // if ((bool)LabelDataGridView.Rows[i].Cells["Choose"].Value == true)
  318. // {
  319. // LabelDataGridView.Rows[i].Cells["pl_labelurl"].Value = FolderPath.Text;
  320. // }
  321. // }
  322. //}
  323. }
  324. }
  325. private void LabelDataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
  326. {
  327. if (LabelDataGridView.Columns[e.ColumnIndex].Name == "pl_isdefault")
  328. {
  329. if (e.Value != null)
  330. {
  331. switch (e.Value.ToString())
  332. {
  333. case "0":
  334. e.Value = "否";
  335. break;
  336. case "1":
  337. e.Value = "是";
  338. break;
  339. default:
  340. break;
  341. }
  342. }
  343. }
  344. }
  345. private void LabelDataGridView_DataError(object sender, DataGridViewDataErrorEventArgs e)
  346. {
  347. //覆盖参数错误的事件,使得不会报错
  348. }
  349. //判断与维护标签相同ID是否具有默认模板
  350. private int isdefault(string pl_prodcode, string pl_labeltype)
  351. {
  352. LogStringBuilder sql2 = new LogStringBuilder();
  353. sql2.Append("select la_id,pl_labelname,pl_labelurl,pl_labeltype,pl_isdefault,pl_prodcode,pl_id,pl_labelcode,pl_detno,pl_labelsoft,pr_detail,pr_spec,");
  354. sql2.Append("pr_code from productlabel left join product on pl_prodcode=pr_code left join label on pl_labelcode=la_code");
  355. sql2.Append(" where pl_isdefault = '1' and pl_prodcode = '" + pl_prodcode + "' and pl_labeltype = '" + pl_labeltype + "'");
  356. dt = (DataTable)dh.ExecuteSql(sql2.GetString(), "select");
  357. if (dt.Rows.Count > 0)
  358. {
  359. sql2.Clear();
  360. return 0;
  361. }
  362. else
  363. {
  364. sql2.Clear();
  365. return 1;
  366. }
  367. }
  368. //判断与标签保存时是否已经有同类型标签存在
  369. private Boolean isSameLabel(string pl_prodcode, string pl_labeltype, string pl_labelname,string pl_labelcode)
  370. {
  371. sql.Clear();
  372. sql.Append("select la_id,pl_labelname,pl_labelurl,pl_labeltype,pl_isdefault,pl_prodcode,pl_id,pl_labelcode,pl_detno,pl_labelsoft,pr_detail,pr_spec,");
  373. sql.Append("pr_code from productlabel left join product on pl_prodcode=pr_code left join label on pl_labelcode=la_code");
  374. sql.Append(" where pl_prodcode = '" + pl_prodcode + "' and pl_labeltype = '" + pl_labeltype + "' and pl_labelname = '" + pl_labelname + "' and pl_labelcode = '"+ pl_labelcode + "'");
  375. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  376. if (dt.Rows.Count > 0)
  377. {
  378. sql.Clear();
  379. return true;
  380. }
  381. else
  382. {
  383. sql.Clear();
  384. return false;
  385. }
  386. }
  387. private void LoadData()
  388. {
  389. //如果没有任何筛选条件直接选取productlabel的数据
  390. if (sql.GetString().Length == 0)
  391. {
  392. sql.Clear();
  393. sql.Append("select la_id,pl_labelname,pl_labelurl,pl_labeltype,pl_isdefault,pl_prodcode,pl_id,pl_labelcode,pl_detno,pl_labelsoft,pr_detail,pr_spec,");
  394. sql.Append("pr_code from productlabel left join product on pl_prodcode=pr_code left join label on pl_labelcode=la_code");
  395. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  396. }
  397. else
  398. {
  399. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  400. }
  401. BaseUtil.FillDgvWithDataTable(LabelDataGridView, dt, PerviewColumn, OperateColumn);
  402. string Field = BaseUtil.GetGridViewSelectContent(LabelDataGridView);
  403. pagination1.BindDataToNavigator(LabelDataGridView, "productlabel left join product on pl_prodcode=pr_code left join label on pl_labelcode=la_code", Field, "pl_id", "", condition.Replace("where", "").ToString(), PerviewColumn, OperateColumn);
  404. }
  405. private void PrintTest_Click(object sender, EventArgs e)
  406. {
  407. if (LabelCode != "")
  408. {
  409. doc.Save();
  410. doc.PrintDocument();
  411. doc.Close();
  412. }
  413. }
  414. private void 产品标签维护_FormClosing(object sender, FormClosingEventArgs e)
  415. {
  416. //关闭所有的打印文件
  417. BaseUtil.ClosePrint(lbl);
  418. }
  419. private void Save_Click(object sender, EventArgs e)
  420. {
  421. if (la_code.Text != "" && la_type.Text != "" && FolderPath.Text != "" && pr_code.Text != "")
  422. {
  423. if (FTPShare.Checked)
  424. {
  425. string SoftWare = "CodeSoft";
  426. ftp.UpLoadFile(FolderPath.Text, la_name.Text,SavePath.Text);
  427. if (pl_id2 != "")
  428. {
  429. if (!isSameLabel(pr_code.Text, la_type.Text, la_name.Text,la_code.Text)&&(((isdefault(pr_code.Text, la_type.Text)==1)&& (pl_default == "1")||(pr_code.Text ==pr_code_1 && la_type.Text == la_type_1))|| (pl_default == "0")))
  430. {
  431. sql.Clear();
  432. sql.Append("update productlabel set pl_labelcode=:pl_labelcode,pl_labeltype=:pl_labeltype,pl_labelurl=:pl_labelurl,pl_labelname=:pl_labelname,");
  433. sql.Append("pl_prodcode=:pl_prodcode,pl_indate=sysdate where pl_id='" + pl_id2 + "'");
  434. dh.ExecuteSql(sql.GetString(), "update", la_code.Text, la_type.Text,SavePath.Text + @"\" + la_name.Text,la_name.Text, pr_code.Text);
  435. }
  436. else
  437. {
  438. MessageBox.Show("编号" + pr_code.Text + "商品已有相同标签或已有默认值");
  439. sql.Clear();
  440. LoadData();
  441. return;
  442. }
  443. }
  444. else
  445. {
  446. if (!isSameLabel(pr_code.Text, la_type.Text, la_name.Text,la_code.Text))
  447. {
  448. sql.Clear();
  449. sql.Append("insert into productlabel (pl_id,pl_labelcode,pl_labeltype,pl_isdefault,pl_labelurl,pl_labelsoft,pl_labelname,pl_prodcode,pl_indate) values( productlabel_seq.nextval, ");
  450. sql.Append("'" + la_code.Text + "','" + la_type.Text + "','" + isdefault(pr_code.Text, la_type.Text) + "','" + SavePath.Text + @"\" + la_name.Text + "','" + SoftWare + "','" + la_name.Text + "','" + pr_code.Text + "',sysdate)");
  451. dh.ExecuteSql(sql.GetString(), "insert");
  452. }
  453. else
  454. {
  455. MessageBox.Show("编号" + pr_code.Text + "商品已有相同标签或已有默认值");
  456. sql.Clear();
  457. LoadData();
  458. return;
  459. }
  460. }
  461. pl_id2 = "";
  462. la_type_1 = "";
  463. pr_code_1 = "";
  464. MessageBox.Show("保存成功!");
  465. sql.Clear();
  466. LoadData();
  467. }
  468. }
  469. else
  470. MessageBox.Show("所有参数必须填写");
  471. }
  472. private void 产品标签维护_SizeChanged(object sender, EventArgs e)
  473. {
  474. asc.controlAutoSize(this);
  475. }
  476. private void ScreenEvent(object sender, KeyEventArgs e)
  477. {
  478. if (e.KeyCode == Keys.Enter)
  479. Screen.PerformClick();
  480. }
  481. private void Delete_Click(object sender, EventArgs e)
  482. {
  483. string[] deleteid = new string[LabelDataGridView.RowCount];
  484. string[] deletelabel = new string[LabelDataGridView.RowCount];
  485. string[] deletelabname = new string[LabelDataGridView.RowCount];
  486. for (int i = 0; i < LabelDataGridView.RowCount; i++)
  487. {
  488. if (LabelDataGridView.Rows[i].Cells["Choose"].Value != null)
  489. {
  490. if (LabelDataGridView.Rows[i].Cells["Choose"].Value is Boolean)
  491. {
  492. if ((bool)LabelDataGridView.Rows[i].Cells["Choose"].Value == true)
  493. {
  494. deleteid[i] = LabelDataGridView.Rows[i].Cells["pl_id"].Value.ToString();
  495. deletelabname[i] = LabelDataGridView.Rows[i].Cells["pl_labelname"].Value.ToString();
  496. deletelabel[i] = LabelDataGridView.Rows[i].Cells["pl_labelurl"].Value.ToString();
  497. }
  498. }
  499. }
  500. }
  501. dh.DeleteDataByID("productlabel", "pl_id", deleteid);
  502. for (int i = 0; i < deletelabname.Length; i++)
  503. {
  504. if (deletelabname[i] != null)
  505. {
  506. sql.Clear();
  507. sql.Append("select pl_labelname from productlabel left join product on pl_prodcode=pr_code left join label on pl_labelcode=la_code where pl_labelname = '" + deletelabname[i] + "'");
  508. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  509. if (dt.Rows.Count == 0)
  510. {
  511. try
  512. {
  513. // ftp.Delete(deletelabname[i]);
  514. File.Delete(deletelabel[i]);
  515. }
  516. catch{
  517. }
  518. }
  519. }
  520. }
  521. sql.Clear();
  522. LoadData();
  523. }
  524. private void OpernSaveFolder_Click(object sender, EventArgs e)
  525. {
  526. FolderBrowserDialog folder = new FolderBrowserDialog();
  527. folder.Description = "选择文件夹";
  528. DialogResult result = folder.ShowDialog();
  529. if (result == DialogResult.OK)
  530. {
  531. SavePath.Text = folder.SelectedPath;
  532. if (SavePath.Text.LastIndexOf('\\') != SavePath.Text.Length-1) {
  533. SavePath.Text += ("\\");
  534. }
  535. }
  536. BaseUtil.SetCacheData("SavePath", SavePath.Text);
  537. }
  538. }
  539. }