private void btnDelete_Click(object sender, Control.AuthEventArgs e) { if (tbTemplete.SelectedTab == null) { return; } ListView lv = tbTemplete.SelectedTab.Tag as ListView; if (lv == null) { return; } if (lv.SelectedItems.Count == 0) { return; } bool ok = false; foreach (ListViewItem item in lv.SelectedItems) { DocTemplete tpl = item.Tag as DocTemplete; if (tpl == null) { return; } ok = _tempLogic.DeleteTemplete(tpl.TempleteID); } if (ok) { ShowTemplete(lv, (DocType)(tbTemplete.SelectedIndex + 1)); } }
private void listView_DoubleClick(object sender, EventArgs e) { if (tbTemplete.SelectedTab == null) { return; } ListView lv = tbTemplete.SelectedTab.Tag as ListView; if (lv == null) { return; } if (lv.SelectedItems.Count == 0) { return; } DocTemplete tpl = lv.SelectedItems[0].Tag as DocTemplete; if (tpl == null) { return; } if (!Directory.Exists(GObj.TEMP_DIR)) { Directory.CreateDirectory(GObj.TEMP_DIR); } string path = string.Format(@"{0}\{1}", GObj.TEMP_DIR, tpl.TempleteName); if (FileKit.Write(path, tpl.TempleteData, System.IO.FileMode.OpenOrCreate)) { Process.Start(path); } }
public bool AddTemplate(string path, out DocType type) { type = DocType.Word; if (string.IsNullOrWhiteSpace(path)) { return(false); } if (!System.IO.File.Exists(path)) { return(false); } string fileName = path.Substring(path.LastIndexOf('\\') + 1); string fileExt = fileName.Substring(fileName.LastIndexOf('.') + 1); switch (fileExt) { case "doc": case "docx": type = DocType.Word; break; case "ppt": case "pptx": type = DocType.PPT; break; case "xls": case "xlsx": type = DocType.Excel; break; } byte[] data = FileKit.GetFileData(path); DocTemplete t = new DocTemplete { TempleteName = fileName, TempleteExt = fileExt, TempleteData = data, TempleteType = (int)type }; return(Service.InsertTemplete(t)); }