private void send() { if (progress == null) { var context = TaskScheduler.FromCurrentSynchronizationContext(); progress = new Progress(); progress.Owner = this; progress.Show(); ids.Clear(); results.Clear(); // MessageBox.Show(id1.ToString() + " " + id2.ToString(), "ids", MessageBoxButtons.OK, MessageBoxIcon.Error); System.Threading.Tasks.Task task = System.Threading.Tasks.Task.Factory.StartNew(() => { if (type == "image" || type == "pdf") { path = httpReq.uploadFile(path); } if (path != null && !path.Equals("0")) { if (type == "result") { readDocx(path); } else { String ii = beg_id.Text; ii = (ii.Substring(0, ii.LastIndexOf("-"))).Replace("-", ""); for (int i = id1; i <= id2; i++) { IdModel im = new IdModel(); im.id = ii + i.ToString(); ids.Add(im); } mme.header = path; } String json = createJsonArray(); Console.WriteLine("send ssd " + json); Console.ReadLine(); res = httpReq.sendNotice(this.phone, this.password, name, json, dept, type); Console.WriteLine("send ssd "); } }).ContinueWith(_ => { dept = null; path = null; type = null; progress.Close(); progress = null; if (res != "0") { errorMsg.setMsg("Successful", "Send"); errorMsg.ShowDialog(); } else { errorMsg.setMsg("Error", "Failed"); errorMsg.ShowDialog(); } Console.WriteLine("send result callBack " + res); }, context); } else { errorMsg.Activate(); } }
private Boolean readDocx(String docPath) { Boolean header = true; int s_conter = 0; int total_sub = 0; int result_attr = 3; String allSub = null; String hedMsg = null; int n = 0; String[] arr = new String[result_attr]; String[] tem = new String[result_attr]; String id = ""; String[] sub = new String[4]; ids.Clear(); results.Clear(); int c = 0; try { //string docPath = "E:\\CsharpResultText.docx"; Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application(); Document doc = app.Documents.Open(docPath); String words = doc.Content.Text; //Console.Write("Docx texx " + words); doc.Close(); app.Quit(); using (StringReader reader = new StringReader(words)) { string line; while ((line = reader.ReadLine()) != null) { if (header && !line.Equals("Id")) { hedMsg = hedMsg + "\n" + line; } else if ((line.Contains("Id")) || (line.Contains("Subject")) || (line.Contains("Credit")) || (line.Contains("GPA"))) { if (line.Contains("Subject")) { total_sub++; } if ((s_conter < result_attr) && !(line.Contains("Id"))) { arr[s_conter] = line; s_conter++; } if (header) { mme.header = hedMsg; } header = false; } else if (!line.Equals(" ") && !line.Equals("\n")) { line = line.Replace(" ", ""); line = line.Replace("\u0007", ""); Regex reg2 = new Regex(ID_PATTERN); Match m2 = reg2.Match(line); if (m2.Success) { results.Clear(); id = line; allSub = null; foreach (var item in arr) { allSub = allSub + " " + item; } allSub = allSub + "\n"; } else if (!line.Equals(" ") && !line.Equals("")) { tem[n] = line; if (n == (result_attr - 1)) { ResultModel rr = new ResultModel(); rr.subject = tem[0]; rr.credit = tem[1]; rr.gpa = tem[2]; results.Add(rr); n = 0; } else { n++; } if (c == ((result_attr * total_sub) - 1)) { IdModel i = new IdModel(); i.id = id; ids.Add(i); var sss = JsonConvert.SerializeObject(new { res = results }); temlist.Add(JObject.Parse(sss)); //Console.WriteLine("all sub "+sss); //Console.Write("id " + id + " " + sub[0] + " " + sub[2]); c = 0; } else { c++; } } } } // Console.Write("Docx Header " + hedMsg); } } catch (Exception e) { Console.WriteLine("Docx texx exception " + e); return(false); } return(true); }
private void ttt() { Boolean header = true; int s_conter = 0; int total_sub = 0; int result_attr = 3; String allSub = null; int n = 0; String[] arr = new String[result_attr]; String id = ""; String[] sub = new String[4]; int c = 0; try { string docPath = "E:\\CsharpResultText.docx"; Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application(); Document doc = app.Documents.Open(docPath); String words = doc.Content.Text; //Console.Write("Docx texx " + words); doc.Close(); app.Quit(); using (StringReader reader = new StringReader(words)) { string line; while ((line = reader.ReadLine()) != null) { if (header && !line.Equals("Id")) { hedMsg = hedMsg + "\n" + line; } else if ((line.Contains("Id")) || (line.Contains("Subject")) || (line.Contains("Credit")) || (line.Contains("GPA"))) { if (line.Contains("Subject")) { total_sub++; } if ((s_conter < result_attr) && !(line.Contains("Id"))) { arr[s_conter] = line; s_conter++; } if (header) { mme.header = hedMsg; } header = false; } else if (!line.Equals(" ") && !line.Equals("\n")) { line = line.Replace(" ", ""); line = line.Replace("\u0007", ""); Regex reg2 = new Regex(ID_PATTERN); Match m2 = reg2.Match(line); if (m2.Success) { id = line; allSub = null; foreach (var item in arr) { allSub = allSub + " " + item; } allSub = allSub + "\n"; } else { if (c == 1) { allSub = allSub + line; } else { allSub = allSub + ", " + line; } if (n == result_attr) { allSub = allSub + "\n"; n = 0; } n++; if (c == 9) { IdModel i = new IdModel(); i.id = id; ids.Add(i); ResultModel rr = new ResultModel(); // rr.result = allSub; results.Add(rr); // Console.WriteLine("all sub "+allSub); //Console.Write("id " + id + " " + sub[0] + " " + sub[2]); c = 0; } else { c++; } } } } // Console.Write("Docx Header " + hedMsg); } } catch (Exception e) { Console.WriteLine("Docx texx exception " + e); } }