//读取文本文件转换为List /// <summary> /// 读取文本文件转换为List /// </summary> /// <param name="fileName"></param> /// <returns></returns> public static List <ToJsonMy> ReadJsonFileToList(string fileName) { if (!File.Exists(fileName)) { File.Create(fileName); } FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); List <ToJsonMy> list = new List <ToJsonMy>(); ToJsonMy my = new ToJsonMy(); StreamReader sr = new StreamReader(fs); //使用StreamReader类来读取文件 sr.BaseStream.Seek(0, SeekOrigin.Begin); // 从数据流中读取每一行,直到文件的最后一行 string tmp = sr.ReadLine(); while (tmp != null) { my = JsonConvert.DeserializeObject <ToJsonMy>(tmp); //if(my.status!="5") //{ list.Add(my); //} tmp = sr.ReadLine(); } //关闭此StreamReader对象 sr.Close(); fs.Close(); return(list); }
/// <summary> /// 编辑改变状态按钮函数 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void mydata_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0) { if (e.ColumnIndex == mydata.Columns["operation"].Index) { string id = mydata.Rows[e.RowIndex].Cells["id"].Value.ToString(); ToJsonMy file = database.find_myjson(id); switch (mydata.Rows[e.RowIndex].Cells["operation"].Value.ToString()) { case "通知已打印": file.changeStatusById("4"); mydata.Rows[e.RowIndex].Cells["status"].Value = "已打印"; mydata.Rows[e.RowIndex].Cells["operation"].Value = "确认付款"; break; case "确认付款": DialogResult dr = MessageBox.Show("确认付款?", "", MessageBoxButtons.YesNo); if (dr == DialogResult.Yes) { file.ensure_payed(); mydata.Rows.Remove(mydata.Rows[e.RowIndex]); } break; case "手动下载": download_errfile_class download_class = new download_errfile_class(this, file, e.RowIndex); download_class.download(); break; } } } }
//读取文本文件转换为List /// <summary> /// 读取文本文件转换为List /// </summary> /// <param name="fileName"></param> /// <returns></returns> public static List<ToJsonMy> ReadJsonFileToList(string fileName) { if (!File.Exists(fileName)) { File.Create(fileName); } FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); List<ToJsonMy> list = new List<ToJsonMy>(); ToJsonMy my = new ToJsonMy(); StreamReader sr = new StreamReader(fs); //使用StreamReader类来读取文件 sr.BaseStream.Seek(0, SeekOrigin.Begin); // 从数据流中读取每一行,直到文件的最后一行 string tmp = sr.ReadLine(); while (tmp != null) { my = JsonConvert.DeserializeObject<ToJsonMy>(tmp); //if(my.status!="5") //{ list.Add(my); //} tmp = sr.ReadLine(); } //关闭此StreamReader对象 sr.Close(); fs.Close(); return list; }
public override void Download() { //base.Download(); string filename = ""; filename = location_settings.file_path + "\\" + file.id + "_" + file.copies + "_" + file.double_side + "_" + file.student_number + "_" + file.name; string doc_extension = Path.GetExtension(location_settings.file_path + "/" + filename); if (doc_extension != ".pdf") { filename += ".pdf"; } string jsonUrl = API.GetMethod("/printer/task/" + file.id); JObject jo = JObject.Parse(jsonUrl); ToJsonMy thisOne = new ToJsonMy(); thisOne.url = (jo)["info"]["url"].ToString(); WebClient webClient = new WebClient(); String pathDoc = filename; webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(OnDownloadFileCompleted); webClient.DownloadFileAsync(new Uri(thisOne.url), pathDoc, file.id); MessageBox.Show("正在下载该文件!\n请等待,稍后请再次点击打印按钮"); }
/// <summary> /// 双击打开文件,若不存在,则自动下载,双击ID显示用户基本信息 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void mydata_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e) { if ((e.ColumnIndex >= 1) && (e.ColumnIndex < 2)) { string id = mydata.Rows[e.RowIndex].Cells["id"].Value.ToString(); ToJsonMy file = database.find_myjson(id); userInfo user = new userInfo(); user = usermessage(file.use_id); MessageBox.Show("用户:" + user.name + " 学号:" + user.student_number + " 手机号:" + user.phone); } else if ((e.ColumnIndex >= 2) && (e.ColumnIndex < 3)) { string id = mydata.Rows[e.RowIndex].Cells["id"].Value.ToString(); ToJsonMy file = database.find_myjson(id); if (file != null) { if (!file.is_ibook) { string filename = ""; filename = location_settings.file_path + "\\" + file.id + "_" + file.copies + "_" + file.double_side + "_" + file.student_number + "_" + file.name; string doc_extension = Path.GetExtension(location_settings.file_path + "/" + filename); if (doc_extension != ".pdf") { filename += ".pdf"; } if (File.Exists(@filename)) { System.Diagnostics.Process.Start(filename); } else { download_single_single_class file_download = new download_single_single_class(this, file); file_download.download(); } } else { string filename = ""; filename = location_settings.ibook_path + file.name.Substring(0, file.name.Length - "【店内书】".Length); if (File.Exists(@filename)) { System.Diagnostics.Process.Start(filename); } else { MessageBox.Show("本店电子书路径有误,请改正"); } } } } }
static public void direct_print_ibook(ToJsonMy file, login_download form) { string filename = ""; filename = location_settings.ibook_path + file.name.Substring(0, file.name.Length - "【店内书】".Length); if (File.Exists(@filename)) { PdfDocument doc = new PdfDocument(); doc.LoadFromFile(filename); PrintDialog dialogprint = new PrintDialog(); List <string> printer_use_list = new List <string>(); printer_use_list = remember.ReadTextFileToList(@"printer_setting.sjc"); if (printer_use_list.Count != 4) { throw new Exception("请先设置需要使用的打印机"); } dialogprint.PrinterSettings.PrinterName = printer_use_list[1]; dialogprint.PrinterSettings.Duplex = Duplex.Vertical; dialogprint.PrinterSettings.DefaultPageSettings.Color = false; dialogprint.UseEXDialog = true; dialogprint.AllowPrintToFile = true; dialogprint.AllowSomePages = true; dialogprint.PrinterSettings.MinimumPage = 1; dialogprint.PrinterSettings.MaximumPage = doc.Pages.Count; dialogprint.PrinterSettings.FromPage = 1; dialogprint.PrinterSettings.Collate = true; dialogprint.PrinterSettings.ToPage = doc.Pages.Count; string copy = file.copies.Substring(0, 1); dialogprint.PrinterSettings.Copies = (short)Int32.Parse(copy); doc.PrintFromPage = dialogprint.PrinterSettings.FromPage; doc.PrintToPage = dialogprint.PrinterSettings.ToPage; doc.PrintDocument.PrinterSettings = dialogprint.PrinterSettings; PrintDocument printdoc = doc.PrintDocument; dialogprint.Document = printdoc; printdoc.Print(); file.changeStatusById("4"); form.mydata.Rows[form.mydata.CurrentRow.Index].Cells["status"].Value = "已打印"; form.mydata.Rows[form.mydata.CurrentRow.Index].Cells["operation"].Value = "确认付款"; } else { MessageBox.Show("本店电子书路径有误,请改正"); } }
static public ToJsonMy find_myjson(string id) { ToJsonMy result = null; foreach (var item in jsonlist) { if (item.id == id) { result = item; break; } } return(result); }
/// <summary> /// 如果有备注信息则显示 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void requirements_Click(object sender, EventArgs e) { string current_id = mydata.Rows[mydata.CurrentRow.Index].Cells["id"].Value.ToString(); ToJsonMy file = database.find_myjson(current_id); if (file != null) { if (file.requirements != null) { MessageBox.Show(file.requirements, "备注信息"); } } //} }
static public void setbefore_print_file(ToJsonMy file, login_download form) { string filename = ""; filename = location_settings.file_path + "\\" + file.id + "_" + file.copies + "_" + file.double_side + "_" + file.student_number + "_" + file.name; string doc_extension = Path.GetExtension(location_settings.file_path + "/" + filename); if ((doc_extension == ".doc") || (doc_extension == ".docx")) { filename += ".pdf"; } if ((doc_extension == ".ppt") || (doc_extension == ".pptx")) { filename += ".pdf"; } PdfDocument doc = new PdfDocument(); doc.LoadFromFile(filename); PrintDialog dialogprint = new PrintDialog(); dialogprint.UseEXDialog = true; dialogprint.AllowPrintToFile = true; dialogprint.AllowSomePages = true; dialogprint.PrinterSettings.MinimumPage = 1; dialogprint.PrinterSettings.MaximumPage = doc.Pages.Count; dialogprint.PrinterSettings.FromPage = 1; dialogprint.PrinterSettings.Collate = true; dialogprint.PrinterSettings.ToPage = doc.Pages.Count; if (file.copies != "现场打印") { string copy = file.copies.Substring(0, 1); dialogprint.PrinterSettings.Copies = (short)Int32.Parse(copy); } if (dialogprint.ShowDialog() == DialogResult.OK) { doc.PrintFromPage = dialogprint.PrinterSettings.FromPage; doc.PrintToPage = dialogprint.PrinterSettings.ToPage; doc.PrintDocument.PrinterSettings = dialogprint.PrinterSettings; PrintDocument printdoc = doc.PrintDocument; dialogprint.Document = printdoc; printdoc.Print(); file.changeStatusById("4"); form.mydata.Rows[form.mydata.CurrentRow.Index].Cells["status"].Value = "已打印"; form.mydata.Rows[form.mydata.CurrentRow.Index].Cells["operation"].Value = "确认付款"; } }
private void dicret_download_Click(object sender, EventArgs e) { try { string current_id = mydata.Rows[mydata.CurrentRow.Index].Cells["id"].Value.ToString(); ToJsonMy file = database.find_myjson(current_id); if (file != null) { if (!file.is_ibook) { string filename = ""; filename = location_settings.file_path + "\\" + file.id + "_" + file.copies + "_" + file.double_side + "_" + file.student_number + "_" + file.name; string doc_extension = Path.GetExtension(location_settings.file_path + "/" + filename); if ((doc_extension == ".doc") || (doc_extension == ".docx")) { filename += ".pdf"; } if ((doc_extension == ".ppt") || (doc_extension == ".pptx")) { filename += ".pdf"; throw new Exception("ppt文件请设置文件后打印"); } if (File.Exists(@filename)) { print_class.direct_print_file(file, this); } else { download_single_single_class file_download = new download_single_single_class(this, file); file_download.download(); } } else { print_class.direct_print_ibook(file, this); } } } catch (Exception excep) { MessageBox.Show(excep.Message, "无法打印"); } }
/// <summary> /// 单击后判断该文件是否有备注信息 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void mydata_CellClick(object sender, DataGridViewCellEventArgs e) { if ((e.ColumnIndex > -1) && (e.RowIndex > -1)) { string current_id = mydata.Rows[e.RowIndex].Cells["id"].Value.ToString(); ToJsonMy file = database.find_myjson(current_id); if (file != null) { if (file.requirements == "") { requirements.Visible = false; } else { requirements.Visible = true; } } } }
static public void setbefore_print_ibook(ToJsonMy file, login_download form) { string filename = ""; filename = location_settings.ibook_path + file.name.Substring(0, file.name.Length - "【店内书】".Length); if (File.Exists(@filename)) { PdfDocument doc = new PdfDocument(); doc.LoadFromFile(filename); PrintDialog dialogprint = new PrintDialog(); dialogprint.UseEXDialog = true; dialogprint.AllowPrintToFile = true; dialogprint.AllowSomePages = true; dialogprint.PrinterSettings.MinimumPage = 1; dialogprint.PrinterSettings.MaximumPage = doc.Pages.Count; dialogprint.PrinterSettings.FromPage = 1; dialogprint.PrinterSettings.Collate = true; dialogprint.PrinterSettings.ToPage = doc.Pages.Count; string copy = file.copies.Substring(0, 1); dialogprint.PrinterSettings.Copies = (short)Int32.Parse(copy); if (dialogprint.ShowDialog() == DialogResult.OK) { doc.PrintFromPage = dialogprint.PrinterSettings.FromPage; doc.PrintToPage = dialogprint.PrinterSettings.ToPage; doc.PrintDocument.PrinterSettings = dialogprint.PrinterSettings; PrintDocument printdoc = doc.PrintDocument; dialogprint.Document = printdoc; printdoc.Print(); file.changeStatusById("4"); form.mydata.Rows[form.mydata.CurrentRow.Index].Cells["status"].Value = "已打印"; form.mydata.Rows[form.mydata.CurrentRow.Index].Cells["operation"].Value = "确认付款"; } } else { MessageBox.Show("本店电子书路径有误,请改正"); } }
/// <summary> /// 双击打开文件,若不存在,则自动下载,双击ID显示用户基本信息 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void mydata_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e) { if ((e.ColumnIndex >= 1) && (e.ColumnIndex < 2)) { string id = mydata.Rows[e.RowIndex].Cells["id"].Value.ToString(); foreach (var item in jsonlist) { if (id == item.id) { userInfo user = new userInfo(); user = usermessage(item.use_id); MessageBox.Show("用户:" + user.name + " 手机号:" + user.phone); } } } else { string id = mydata.Rows[e.RowIndex].Cells["id"].Value.ToString(); foreach (var item in jsonlist) { if (id == item.id) { string filename = ""; filename = path + "\\" + item.id + "_" + item.copies + "_" + item.double_side + "_" + item.student_number + "_" + item.name; if (File.Exists(@filename)) { //filename = path + filename; System.Diagnostics.Process.Start(filename); break; } else { filename = item.id + "_" + item.copies + "_" + item.double_side + "_" + item.student_number + "_" + item.name; //get 文件详细信息 URI操作示意: GET /File/1234 string jsonUrl = API.GetMethod("/File/" + item.id); JObject jo = JObject.Parse(jsonUrl); ToJsonMy thisOne = new ToJsonMy(); thisOne.url = (jo)["url"].ToString(); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } WebClient webClient = new WebClient(); String pathDoc = path + "/" + filename; webClient.DownloadFileAsync(new Uri(thisOne.url), pathDoc, id); //fileDownload(thisOne.url, filename, item.id); MessageBox.Show("正在下载该文件!\n等待会儿再打开"); } break; } } } }
/// <summary> /// 用于向jsonlist添加数据 /// </summary> /// <param name="ja"></param> public void addJson(JArray ja) { bool flag = true; int i = 0;//用于遍历的 //向jsonList中添加数据,如果json的id已经存在,则flag置为false //即不添加,维护jsonList for (i = 0; i < ja.Count; i++)//遍历ja数组 { bool flag2 = true; flag = true; foreach (var item in jsonlist) //此处应当存在一个问题,即循环中jsonlist列表会发生改变,能否使用foreach { //已存在的或是已支付的都可不予以考虑 if (item.id == ja[i]["id"].ToString()) { flag = false; break; } } if (ja[i]["status"].ToString() == "5") { flag = false; } if (ja[i]["status"].ToString() == "未下载") { flag2 = false; } if (flag == true) { //if (flag2 == false) //{ // this.notifyIcon1.Visible = true; // this.notifyIcon1.ShowBalloonTip(10000); //} ToJsonMy myJs = new ToJsonMy(); myJs.id = ja[i]["id"].ToString(); myJs.name = ja[i]["name"].ToString(); myJs.use_id = ja[i]["use_id"].ToString(); //myJs.pri_id = ja[i]["pri_id"].ToString(); //myJs.url = ja[i]["url"].ToString(); myJs.time = ja[i]["time"].ToString(); myJs.name = ja[i]["name"].ToString(); myJs.status = ja[i]["status"].ToString(); myJs.copies = ja[i]["copies"].ToString(); myJs.use_name = ja[i]["use_name"].ToString(); myJs.double_side = ja[i]["double_side"].ToString(); myJs.student_number = ja[i]["student_number"].ToString(); myJs.color = ja[i]["color"].ToString(); myJs.ppt_layout = ja[i]["ppt_layout"].ToString(); myJs.requirements = ja[i]["requirements"].ToString(); jsonlist.Add(myJs); } } }
/// <summary> /// 用于单个文件的下载 /// </summary> /// <param name="id"></param> private void Download(string id) { //获取文件的索引; foreach (var item in jsonlist) { if (item.id == id) { string s = null; string filename = null; string sides = null; Thread piThread1 = new Thread(delegate() { s = API.GetMethod("/File/" + item.id); JObject os = JObject.Parse(s); ToJsonMy my = new ToJsonMy(); my.url = os["url"].ToString(); sides = item.double_side; filename = item.id + "_" + item.copies + "_" + sides + "_" + item.student_number + "_" + item.name; fileDownload(my.url, filename, item.id); }); piThread1.Start(); } } }
private void dicret_download_Click(object sender, EventArgs e) { try { //MessageBox.Show("打印出错"); string current_id = mydata.Rows[mydata.CurrentRow.Index].Cells["id"].Value.ToString(); foreach (var item in jsonlist) { if (current_id == item.id) { string filename = ""; filename = path + "\\" + item.id + "_" + item.copies + "_" + item.double_side + "_" + item.student_number + "_" + item.name; if (File.Exists(@filename)) { filename = item.id + "_" + item.copies + "_" + item.double_side + "_" + item.student_number + "_" + item.name; PdfDocument doc = new PdfDocument(); doc.LoadFromFile(path + "/" + filename); PrintDialog dialogprint = new PrintDialog(); List<string> printerlist = new List<string>(); List<string> printers_only_canduplex = new List<string>(); List<string> printers_only_supportcolor = new List<string>(); List<string> printers_canduplex_supportcolor = new List<string>(); List<string> printers_no_cando = new List<string>(); string defaultprinter = dialogprint.PrinterSettings.PrinterName; foreach (string printname in PrinterSettings.InstalledPrinters) { if (!printerlist.Contains(printname)) { printerlist.Add(printname); } } printerlist.Remove("Microsoft XPS Document Writer"); printerlist.Remove("Fax"); foreach (string printername in printerlist) { if (!printers_only_canduplex.Contains(printername)) { dialogprint.PrinterSettings.PrinterName = printername; if ((dialogprint.PrinterSettings.CanDuplex) && (!dialogprint.PrinterSettings.SupportsColor)) { printers_only_canduplex.Add(printername); } } } foreach (string printername in printerlist) { if (!printers_only_supportcolor.Contains(printername)) { dialogprint.PrinterSettings.PrinterName = printername; if ((dialogprint.PrinterSettings.SupportsColor) && (!dialogprint.PrinterSettings.CanDuplex)) { printers_only_supportcolor.Add(printername); } } } foreach (string printername in printerlist) { if (!printers_canduplex_supportcolor.Contains(printername)) { dialogprint.PrinterSettings.PrinterName = printername; if ((dialogprint.PrinterSettings.SupportsColor) && (dialogprint.PrinterSettings.CanDuplex)) { printers_canduplex_supportcolor.Add(printername); } } } foreach (string printername in printerlist) { if (!printers_no_cando.Contains(printername)) { dialogprint.PrinterSettings.PrinterName = printername; if ((!dialogprint.PrinterSettings.CanDuplex) && (!dialogprint.PrinterSettings.SupportsColor)) { printers_no_cando.Add(printername); } } } if (printerlist.Count == 0) { throw new Exception("该电脑并未安装打印机"); } dialogprint.PrinterSettings.PrinterName = defaultprinter; if ((item.color == "0") && (item.double_side == "单面")) { if (dialogprint.PrinterSettings.SupportsColor) { if (printers_no_cando.Count == 0) { if (printers_only_canduplex.Count == 0) { if (printers_only_supportcolor.Count == 0) { dialogprint.PrinterSettings.PrinterName = printers_canduplex_supportcolor[0]; } else { dialogprint.PrinterSettings.PrinterName = printers_only_supportcolor[0]; } } else { dialogprint.PrinterSettings.PrinterName = printers_only_canduplex[0]; } } else { dialogprint.PrinterSettings.PrinterName = printers_no_cando[0]; } } else { dialogprint.PrinterSettings.PrinterName = defaultprinter; } dialogprint.PrinterSettings.Duplex = Duplex.Simplex; dialogprint.PrinterSettings.DefaultPageSettings.Color = false; } else if ((item.color == "1") && (item.double_side == "单面")) { //正常设置 //if (printers_only_supportcolor.Contains(defaultprinter) || printers_canduplex_supportcolor.Contains(defaultprinter)) //{ // dialogprint.PrinterSettings.PrinterName = defaultprinter; //} //else //{ // if (printers_only_supportcolor.Count == 0) // { // if (printers_canduplex_supportcolor.Count == 0) // { // throw new Exception("不存在满足要求的打印机"); // } // else // { // dialogprint.PrinterSettings.PrinterName = printers_canduplex_supportcolor[0]; // } // } // else // { // dialogprint.PrinterSettings.PrinterName = printers_only_supportcolor[0]; // } //} //dialogprint.PrinterSettings.Duplex = Duplex.Simplex; //dialogprint.PrinterSettings.DefaultPageSettings.Color = true; //光辉岁月单独设置 if (printers_canduplex_supportcolor.Contains(defaultprinter)) { dialogprint.PrinterSettings.PrinterName = defaultprinter; } else { if (printers_canduplex_supportcolor.Count == 0) { throw new Exception("不存在满足要求的打印机"); } else { dialogprint.PrinterSettings.PrinterName = printers_canduplex_supportcolor[0]; } } dialogprint.PrinterSettings.Duplex = Duplex.Simplex; dialogprint.PrinterSettings.DefaultPageSettings.Color = true; } else if ((item.color == "0") && (item.double_side == "双面")) { if (!printers_only_supportcolor.Contains(defaultprinter) || !printers_canduplex_supportcolor.Contains(defaultprinter)) { dialogprint.PrinterSettings.PrinterName = defaultprinter; } else { if (printers_only_canduplex.Count == 0) { if (printers_canduplex_supportcolor.Count == 0) { throw new Exception("不存在满足要求的打印机"); } else { dialogprint.PrinterSettings.PrinterName = printers_canduplex_supportcolor[0]; } } else { dialogprint.PrinterSettings.PrinterName = printers_only_canduplex[0]; } } dialogprint.PrinterSettings.Duplex = Duplex.Vertical; dialogprint.PrinterSettings.DefaultPageSettings.Color = false; } else if ((item.color == "1") && (item.double_side == "双面")) { if (printers_canduplex_supportcolor.Contains(defaultprinter)) { dialogprint.PrinterSettings.PrinterName = defaultprinter; } else { if (printers_canduplex_supportcolor.Count == 0) { throw new Exception("不存在满足要求的打印机"); } else { dialogprint.PrinterSettings.PrinterName = printers_canduplex_supportcolor[0]; } } dialogprint.PrinterSettings.Duplex = Duplex.Vertical; dialogprint.PrinterSettings.DefaultPageSettings.Color = true; } dialogprint.UseEXDialog = true; dialogprint.AllowPrintToFile = true; dialogprint.AllowSomePages = true; dialogprint.PrinterSettings.MinimumPage = 1; dialogprint.PrinterSettings.MaximumPage = doc.Pages.Count; dialogprint.PrinterSettings.FromPage = 1; dialogprint.PrinterSettings.Collate = true; //dialogprint.PrinterSettings.CanDuplex = true; //dialogprint.PrinterSettings. dialogprint.PrinterSettings.ToPage = doc.Pages.Count; string copy = item.copies.Substring(0, 1); dialogprint.PrinterSettings.Copies = (short)Int32.Parse(copy); //dialogprint.ShowDialog(); //if (dialogprint.ShowDialog() == DialogResult.OK) //{ doc.PrintFromPage = dialogprint.PrinterSettings.FromPage; doc.PrintToPage = dialogprint.PrinterSettings.ToPage; doc.PrintDocument.PrinterSettings = dialogprint.PrinterSettings; PrintDocument printdoc = doc.PrintDocument; dialogprint.Document = printdoc; printdoc.Print(); //} break; } else { filename = item.id + "_" + item.copies + "_" + item.double_side + "_" + item.student_number + "_" + item.name; //get 文件详细信息 URI操作示意: GET /File/1234 string jsonUrl = API.GetMethod("/File/" + item.id); JObject jo = JObject.Parse(jsonUrl); ToJsonMy thisOne = new ToJsonMy(); thisOne.url = (jo)["url"].ToString(); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } WebClient webClient = new WebClient(); String pathDoc = path + "/" + filename; webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(OnDownloadFileCompleted); webClient.DownloadFileAsync(new Uri(thisOne.url), pathDoc, id); //fileDownload(thisOne.url, filename, item.id); MessageBox.Show("正在下载该文件!\n请等待,稍后请再次点击打印按钮"); } break; } } } catch (Exception excep) { MessageBox.Show(excep.Message, "无法打印"); } }
/// <summary> /// 用于显示单个文件数据 /// </summary> /// <param name="json"></param> public void display(ToJsonMy json) { string userName1 = json.student_number + json.use_name; string buttontext = ""; string name = json.name; if (json.requirements != "") { name = "(注)" + name; } if (json.copies == "现场打印") { buttontext = "确认付款"; this.mydata.Rows.Add(json.id, userName1, name, json.copies, "-", "-", "-", json.time, json.status, buttontext); } else { switch (json.status) { case "已下载": buttontext = "通知已打印"; break; case "已打印": buttontext = "确认付款"; break; } this.mydata.Rows.Add(json.id, userName1, name, json.copies, json.double_side, json.strcolor, json.ppt, json.time, json.status, buttontext); } }
private void set_before_print_Click(object sender, EventArgs e) { try { //MessageBox.Show("打印出错"); string current_id = mydata.Rows[mydata.CurrentRow.Index].Cells["id"].Value.ToString(); foreach (var item in jsonlist) { if (current_id == item.id) { string filename = ""; filename = path + "\\" + item.id + "_" + item.copies + "_" + item.double_side + "_" + item.student_number + "_" + item.name; if (File.Exists(@filename)) { filename = item.id + "_" + item.copies + "_" + item.double_side + "_" + item.student_number + "_" + item.name; PdfDocument doc = new PdfDocument(); doc.LoadFromFile(path + "/" + filename); PrintDialog dialogprint = new PrintDialog(); dialogprint.UseEXDialog = true; dialogprint.AllowPrintToFile = true; dialogprint.AllowSomePages = true; dialogprint.PrinterSettings.MinimumPage = 1; dialogprint.PrinterSettings.MaximumPage = doc.Pages.Count; dialogprint.PrinterSettings.FromPage = 1; dialogprint.PrinterSettings.Collate = true; //dialogprint.PrinterSettings.CanDuplex = true; //dialogprint.PrinterSettings. dialogprint.PrinterSettings.ToPage = doc.Pages.Count; string copy = item.copies.Substring(0, 1); dialogprint.PrinterSettings.Copies = (short)Int32.Parse(copy); //dialogprint.ShowDialog(); if (dialogprint.ShowDialog() == DialogResult.OK) { doc.PrintFromPage = dialogprint.PrinterSettings.FromPage; doc.PrintToPage = dialogprint.PrinterSettings.ToPage; doc.PrintDocument.PrinterSettings = dialogprint.PrinterSettings; PrintDocument printdoc = doc.PrintDocument; dialogprint.Document = printdoc; printdoc.Print(); } break; } else { filename = item.id + "_" + item.copies + "_" + item.double_side + "_" + item.student_number + "_" + item.name; //get 文件详细信息 URI操作示意: GET /File/1234 string jsonUrl = API.GetMethod("/File/" + item.id); JObject jo = JObject.Parse(jsonUrl); ToJsonMy thisOne = new ToJsonMy(); thisOne.url = (jo)["url"].ToString(); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } WebClient webClient = new WebClient(); String pathDoc = path + "/" + filename; webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(OnDownloadFileCompleted); webClient.DownloadFileAsync(new Uri(thisOne.url), pathDoc, id); //fileDownload(thisOne.url, filename, item.id); MessageBox.Show("正在下载该文件!\n请等待,稍后请再次点击打印按钮"); } break; } } } catch (Exception excep) { MessageBox.Show(excep.Message, "无法打印"); } }
static public void direct_print_file(ToJsonMy file, login_download form) { string filename = ""; filename = location_settings.file_path + "\\" + file.id + "_" + file.copies + "_" + file.double_side + "_" + file.student_number + "_" + file.name; string doc_extension = Path.GetExtension(location_settings.file_path + "/" + filename); if ((doc_extension == ".doc") || (doc_extension == ".docx")) { filename += ".pdf"; } if ((doc_extension == ".ppt") || (doc_extension == ".pptx")) { filename += ".pdf"; throw new Exception("ppt文件请设置文件后打印"); } if (file.copies == "现场打印") { throw new Exception("请选择详细设置后打印"); } PdfDocument doc = new PdfDocument(); doc.LoadFromFile(filename); PrintDialog dialogprint = new PrintDialog(); List <string> printerlist = new List <string>(); string defaultprinter = dialogprint.PrinterSettings.PrinterName; List <string> printer_use_list = new List <string>(); printer_use_list = remember.ReadTextFileToList(@"printer_setting.sjc"); if (printer_use_list.Count != 4) { throw new Exception("请先设置需要使用的打印机"); } if ((file.color == "0") && (file.double_side == "单面")) { dialogprint.PrinterSettings.PrinterName = printer_use_list[0]; dialogprint.PrinterSettings.Duplex = Duplex.Simplex; dialogprint.PrinterSettings.DefaultPageSettings.Color = false; } else if ((file.color == "1") && (file.double_side == "单面")) { dialogprint.PrinterSettings.PrinterName = printer_use_list[2]; dialogprint.PrinterSettings.Duplex = Duplex.Simplex; dialogprint.PrinterSettings.DefaultPageSettings.Color = true; } else if ((file.color == "0") && (file.double_side == "双面")) { dialogprint.PrinterSettings.PrinterName = printer_use_list[1]; dialogprint.PrinterSettings.Duplex = Duplex.Vertical; dialogprint.PrinterSettings.DefaultPageSettings.Color = false; } else if ((file.color == "1") && (file.double_side == "双面")) { dialogprint.PrinterSettings.PrinterName = printer_use_list[3]; dialogprint.PrinterSettings.Duplex = Duplex.Vertical; dialogprint.PrinterSettings.DefaultPageSettings.Color = true; } dialogprint.UseEXDialog = true; dialogprint.AllowPrintToFile = true; dialogprint.AllowSomePages = true; dialogprint.PrinterSettings.MinimumPage = 1; dialogprint.PrinterSettings.MaximumPage = doc.Pages.Count; dialogprint.PrinterSettings.FromPage = 1; dialogprint.PrinterSettings.Collate = true; dialogprint.PrinterSettings.ToPage = doc.Pages.Count; string copy = file.copies.Substring(0, 1); dialogprint.PrinterSettings.Copies = (short)Int32.Parse(copy); doc.PrintFromPage = dialogprint.PrinterSettings.FromPage; doc.PrintToPage = dialogprint.PrinterSettings.ToPage; doc.PrintDocument.PrinterSettings = dialogprint.PrinterSettings; PrintDocument printdoc = doc.PrintDocument; dialogprint.Document = printdoc; printdoc.Print(); file.changeStatusById("4"); form.mydata.Rows[form.mydata.CurrentRow.Index].Cells["status"].Value = "已打印"; form.mydata.Rows[form.mydata.CurrentRow.Index].Cells["operation"].Value = "确认付款"; }
static public void display_single(login_download form, ToJsonMy file) { mydata_form data = new mydata_form(); data.mydata_userName = file.student_number + file.use_name; data.mydata_buttontext = ""; data.mydata_name = file.name; data.mydata_id = file.id; data.mydata_time = file.time; data.mydata_copies = file.copies; if (database.err_list.Contains(file.id)) { data.mydata_status = "下载失败"; } else { data.mydata_status = file.status; } data.mydata_doubleside = file.double_side; data.mydata_color = file.strcolor; data.mydata_ppt = file.ppt; if (file.requirements != "") { data.mydata_name = "(注)" + file.name; } if (file.isfirst == true) { data.mydata_name = "(首单!)" + file.name; } if (file.copies == "现场打印") { data.mydata_buttontext = "确认付款"; data.mydata_doubleside = "-"; data.mydata_color = "-"; data.mydata_ppt = "-"; delegate_display = display_fun; form.mydata.Invoke(delegate_display, new object[] { form, data }); } else { switch (file.status) { case "已下载": data.mydata_buttontext = "通知已打印"; break; case "已打印": data.mydata_buttontext = "确认付款"; break; case "正打印": data.mydata_buttontext = "通知已打印"; break; case "未下载": data.mydata_buttontext = "手动下载"; break; } delegate_display = display_fun; form.mydata.Invoke(delegate_display, new object[] { form, data }); } }
//public ToJsonMy file; public download_single_single_class(login_download form, ToJsonMy file) { this.form = form; this.file = file; }
static public bool jsonlist_add(JArray ja) { bool flag = true; bool flag_allpaid = true; //用于遍历的 //向jsonList中添加数据,如果json的id已经存在,则flag置为false //即不添加,维护jsonList for (int i = 0; i < ja.Count; i++)//遍历ja数组 { //bool flag2 = true; flag = true; foreach (var item in jsonlist) //此处应当存在一个问题,即循环中jsonlist列表会发生改变,能否使用foreach { //已存在的或是已支付的都可不予以考虑 if (item.id == ja[i]["id"].ToString()) { flag = false; break; } } if (ja[i]["payed"].ToString() == "1") { flag = false; } if (flag == true) { ToJsonMy myJs = new ToJsonMy(); myJs.id = ja[i]["id"].ToString(); myJs.name = ja[i]["name"].ToString(); //myJs.use_id = ja[i]["use"].ToString(); //myJs.pri_id = ja[i]["pri_id"].ToString(); //myJs.url = ja[i]["url"].ToString(); myJs.time = ja[i]["time"].ToString(); //myJs.name = ja[i]["name"].ToString(); myJs.status = ja[i]["status"].ToString(); myJs.copies = ja[i]["copies"].ToString(); myJs.use_name = ja[i]["user"].ToString(); myJs.double_side = ja[i]["double"].ToString(); //myJs.student_number = ja[i]["student_number"].ToString(); myJs.color = ja[i]["color"].ToString(); myJs.ppt_layout = ja[i]["format"].ToString(); myJs.requirements = ja[i]["requirements"].ToString(); if (ja[i].ToString().Contains("pro")) { myJs.isfirst = true; } else { myJs.isfirst = false; } string file_url = ""; string file_more = ""; file_more = API.GetMethod("/printer/task/" + myJs.id); file_url = JObject.Parse(file_more)["info"]["url"].ToString(); myJs.use_id = JObject.Parse(file_more)["info"]["use_id"].ToString(); if (!file_url.Contains("book")) { myJs.is_ibook = false; } else { myJs.is_ibook = true; } //file_url = ""; jsonlist.Add(myJs); } if (ja[i]["payed"].ToString() != "1") { flag_allpaid = false; } } return(flag_allpaid); }
public download_errfile_class(login_download form, ToJsonMy file, int RowIndex) { this.form = form; this.file = file; this.RowIndex = RowIndex; }