public static bool DirectoryDelete(List <GroupMsg> groupList, GroupMsg tmpmsg, string groupName, string localtime) { try { //int count = groupList.Count(t => t.GroupName == groupName); tmpmsg.isClearFile = true; lockFile lockfile = FileHelper.lockFileList.Find(t => t.Name == (groupName + "_.caselock")); if (!Directory.Exists(tmpmsg.FullName)) { return(true); } DirectoryInfo root = new DirectoryInfo(tmpmsg.FullName); if (lockfile != null) { lockfile.fs.Close(); lockfile.fs.Dispose(); lockfile.fs = null; lockfile.isOpen = false; FileHelper.lockFileList.Remove(lockfile); File.Delete(tmpmsg.FullName + @"\" + lockfile.Name); } AsyncGetDeleteFile(root); return(true); } catch (Exception ex) { MessageBox.Show(ex.Message); return(false); } }
public static void AddMs(GroupMsg msg) { if (!PrintList.Contains(msg)) { PrintList.Enqueue(msg); } }
public static bool InsertTmpUserMsg(GroupMsg groupMsg) { try { string sql1 = string.Format(@"INSERT into tmpusermsg( UserID,FileName,FullName,GroupName,FileDirectory,Count,VerForm,PrintColor,PaperType,Printer,PageCount,InitPageCount,Price,InitPrice,Time,Area,Phone,SetTime,LoadTime,FinishTime,DeleteTime,CreateTime,PayType,State,isRemove,isManual,Note,FileSize) VALUES ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}','{19}','{20}','{21}','{22}','{23}','{24}','{25}','{26}','{27}')", groupMsg.UserID, groupMsg.FileName, groupMsg.FullName, groupMsg.GroupName, groupMsg.FileDirectory, groupMsg.Count, groupMsg.VerForm, groupMsg.PrintColor, groupMsg.PaperType, groupMsg.Printer, groupMsg.PageCount, groupMsg.InitPageCount, groupMsg.Price, groupMsg.InitPrice, groupMsg.Time, groupMsg.Area, groupMsg.Phone, groupMsg.SetTime, groupMsg.LoadTime, groupMsg.FinishTime, groupMsg.DeleteTime, groupMsg.CreateTime, groupMsg.PayType, groupMsg.state, groupMsg.isRemove?"1":"0", groupMsg.isManual?"1":"0", groupMsg.Note, groupMsg.fileSize); sql1 = sql1.Replace("\\", "\\\\"); int i = SQLiteHelper.ExecuteNonQuery(sql1); string s = i > 0 ? "成功" : "失败"; LogOperate.Add("插入订单:" + groupMsg.UserID + " " + s); if (i == 0) { return(false); } else { return(true); } } catch (Exception ex) { MessageBox.Show(ex.Message); return(false); } }
public void AsyncPrinter(FilePrinter filePrintermsg, GroupMsg msg, bool isFast) { bool istmpFast = isFast; bool isIdel = true; foreach (var v in msg.FileMsgList) { if (usingPrinter.ContainsKey(v.Printer) && usingPrinter[v.Printer]) { isIdel = false; break; } } if (!isIdel) { MessageBox.Show("打印机有订单占用,请重新选择!"); return; } msg.isPrint = true; msg.isAbort = false; msg.isCanceling = false; foreach (var v in msg.FileMsgList) { if (usingPrinter.ContainsKey(v.Printer)) { usingPrinter[v.Printer] = true; } else { usingPrinter.TryAdd(v.Printer, true); } } ExcelHelper.AddMs(msg); iar = func.BeginInvoke(filePrintermsg, msg, istmpFast, callBack, msg); }
public void asyncGetPrinterStat(string PrinterDevice, GroupMsg groupMsg) { Action <string, GroupMsg> act = (printerDevice, groupmsg) => { List <string> list = new List <string>(); foreach (var v in groupmsg.FileMsgList.FindAll(t => int.Parse(t.state) == 3)) { list.Add(v.Printer); } }; }
private void callBack(IAsyncResult ar) { bool b = func.EndInvoke(ar); GroupMsg tmpmsg = ar.AsyncState as GroupMsg; if (b) { UserDB udb = new UserDB() { userName = tmpmsg.GroupName, lastAddr = tmpmsg.Area, lastTime = DateTime.Parse(tmpmsg.LoadTime), phone = tmpmsg.Phone }; if (tmpmsg.FileMsgList.Count(t => int.Parse(t.state) < 3) == 0) { OutUser(tmpmsg, udb); //ExcelHelper.AddMs(tmpmsg); } SqlModlus.SaveGroupMsg(tmpmsg); if (str.Length > 0) { MessageBox.Show("打印异常:" + str); str = ""; } foreach (var v in tmpmsg.FileMsgList) { if (usingPrinter.ContainsKey(v.Printer)) { usingPrinter[v.Printer] = false; } } tmpmsg.isPrint = false; } else { if (tmpmsg.isAbort) { tmpmsg.FileMsgList.ForEach(t => t.state = "0"); } foreach (var v in tmpmsg.FileMsgList) { if (usingPrinter.ContainsKey(v.Printer)) { usingPrinter[v.Printer] = false; } } } tmpmsg.isPrint = false; tmpmsg.isAbort = false; tmpmsg.isCanceling = false; }
public static bool deleteTmpUserMsg(GroupMsg groupMsg) { try { string sql1 = string.Format(@"delete FROM tmpusermsg where UserID = '{0}' ", groupMsg.UserID); int i = SQLiteHelper.ExecuteNonQuery(sql1); string s = i > 0 ? "成功" : "失败"; LogOperate.Add("删除订单:" + groupMsg.UserID + " " + s); return(true); } catch (Exception ex) { MessageBox.Show(ex.Message); return(false); } }
public static bool InsertUserMsg(GroupMsg groupMsg) { try { string sql1 = string.Format(@"INSERT into 订单信息( userID,UserName,PayType,Price,Time,Aera,State,Directory,LoadTime,FinishTime,Note,Phone,FileName,VerForm,Count,FileSize) VALUES ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}',{15})", groupMsg.UserID.ToString(), groupMsg.GroupName, groupMsg.PayType, groupMsg.Price == "----"?"0": groupMsg.Price, groupMsg.Time, groupMsg.Area, groupMsg.state.ToString(), groupMsg.FileDirectory.ToString(), groupMsg.LoadTime, groupMsg.FinishTime, groupMsg.Note == null?"":groupMsg.Note.ToString(), groupMsg.Phone == null?"":groupMsg.Phone.ToString(), groupMsg.FileName == null?"": groupMsg.FileName, groupMsg.VerForm, groupMsg.Count.ToString(), groupMsg.fileSize); sql1 = sql1.Replace("\\", "\\\\"); int i = SQLiteHelper.ExecuteNonQuery(sql1); return(i > 0?true:false); } catch (Exception ex) { MessageBox.Show(ex.Message); return(false); } }
public static bool UpdateUserMsg(GroupMsg groupMsg) { try { string sql1 = string.Format(@"update 订单信息 set userID = '{0}',UserName = '******',PayType = '{2}',Price = '{3}',Time = '{4}',Aera = '{5}',State = '{6}',Directory = '{7}',LoadTime = '{8}',FinishTime = '{9}',Note = '{10}',Phone = '{11}',FileName = '{12}',VerForm = '{13}',Count = '{14}',FileSize = {15} where userID = '{16}' ", groupMsg.UserID.ToString(), groupMsg.GroupName, groupMsg.PayType, groupMsg.Price == "----" ? "0" : groupMsg.Price, groupMsg.Time, groupMsg.Area, groupMsg.state.ToString(), groupMsg.FileDirectory.ToString(), groupMsg.LoadTime, groupMsg.FinishTime, groupMsg.Note == null ? "" : groupMsg.Note.ToString(), groupMsg.Phone == null ? "" : groupMsg.Phone.ToString(), groupMsg.FileName == null ? "" : groupMsg.FileName, groupMsg.VerForm, groupMsg.Count.ToString(), groupMsg.fileSize.ToString(), groupMsg.UserID.ToString()); sql1 = sql1.Replace("\\", "\\\\"); SQLiteHelper.ExecuteNonQuery(sql1); //} return(true); } catch (Exception ex) { MessageBox.Show(ex.Message); return(false); } }
public static bool UpdateTmpUserMsg(GroupMsg groupMsg) { try { string sql1 = string.Format(@"update tmpusermsg set UserID = '{0}',FileName = '{1}',FullName = '{2}',GroupName = '{3}',FileDirectory = '{4}',Count = '{5}',VerForm = '{6}',PrintColor = '{7}',PaperType = '{8}',Printer = '{9}',PageCount = '{10}',InitPageCount = '{11}',Price = '{12}',InitPrice = '{13}',Time = '{14}',Area = '{15}',Phone = '{16}',SetTime = '{17}',LoadTime = '{18}',FinishTime = '{19}',DeleteTime = '{20}',CreateTime = '{21}',PayType = '{22}',State = '{23}',isRemove = '{24}',isManual = '{25}',Note = '{26}',FileSize = '{27}' where UserID = '{28}'", groupMsg.UserID, groupMsg.FileName, groupMsg.FullName, groupMsg.GroupName, groupMsg.FileDirectory, groupMsg.Count, groupMsg.VerForm, groupMsg.PrintColor, groupMsg.PaperType, groupMsg.Printer, groupMsg.PageCount, groupMsg.InitPageCount, groupMsg.Price, groupMsg.InitPrice, groupMsg.Time, groupMsg.Area, groupMsg.Phone, groupMsg.SetTime, groupMsg.LoadTime, groupMsg.FinishTime, groupMsg.DeleteTime, groupMsg.CreateTime, groupMsg.PayType, groupMsg.state, groupMsg.isRemove ? "1" : "0", groupMsg.isManual ? "1" : "0", groupMsg.Note, groupMsg.fileSize, groupMsg.UserID); sql1 = sql1.Replace("\\", "\\\\"); int i = SQLiteHelper.ExecuteNonQuery(sql1); string s = i > 0 ? "成功" : "失败"; LogOperate.Add("更新订单:" + groupMsg.UserID + " " + s); return(true); } catch (Exception ex) { MessageBox.Show(ex.Message); return(false); } }
public void OutUser(GroupMsg tmpmsg, UserDB udb) { tmpmsg.FinishTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); tmpmsg.state = "3"; if (tmpmsg.FileDirectory == null) { tmpmsg.FileDirectory = frm_Main.CurrentPath; } SqlModlus.InsertUserMsg(tmpmsg); main.InsertOrUpdateUser(udb); if (null != tmpmsg.FileMsgList) { foreach (FileMsg fmsg in tmpmsg.FileMsgList) { SqlModlus.InsertFileMsg(fmsg, tmpmsg.GroupName); fmsg.state = "3"; } } tmpmsg.isShow = true; }
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == -1 || e.RowIndex == -1) { return; } if (dataGridView1.Columns[e.ColumnIndex].Name == "小票预览") { GroupMsg groupMsg = SqlModlus.GetGroupMsg(dataGridView1.Rows[e.RowIndex].Cells["用户ID"].Value.ToString(), dataGridView1.Rows[e.RowIndex].Cells["用户名"].Value.ToString()); if (groupMsg == null) { MessageBox.Show("获取小票失败!"); return; } int h = 0; Image img = ImageHelper.CreateImage(groupMsg, out h); pictureBox1.Height = h; pictureBox1.Image = img; } }
public static GroupMsg GetGroupMsg(string UserID, string UserName) { GroupMsg groupMsg = new GroupMsg(); groupMsg.FileMsgList = new List <FileMsg>(); SQLiteDataReader msdr = getUserMsg(UserName, UserID); while (msdr.Read()) { groupMsg.GroupName = msdr["UserName"].ToString(); groupMsg.Note = msdr["Note"].ToString() == ""?" ": msdr["Note"].ToString(); groupMsg.Area = msdr["Aera"].ToString(); groupMsg.Time = msdr["Time"].ToString(); groupMsg.Price = msdr["Price"].ToString(); groupMsg.FileName = msdr["FileName"].ToString(); groupMsg.VerForm = msdr["VerForm"].ToString(); groupMsg.Count = msdr["Count"].ToString(); groupMsg.Phone = msdr["Phone"].ToString(); } msdr.Close(); msdr = null; msdr = getFileMsg(UserID); while (msdr.Read()) { FileMsg fileMsg = new FileMsg(); fileMsg.Printer = msdr["Printer"].ToString(); fileMsg.FileName = msdr["FileName"].ToString(); fileMsg.Count = msdr["Count"].ToString(); fileMsg.VerForm = msdr["VerForm"].ToString(); fileMsg.FileSize = (double)msdr["FileSize"]; groupMsg.FileMsgList.Add(fileMsg); } if (groupMsg.FileMsgList == null || groupMsg.FileMsgList.Count == 0) { groupMsg.isManual = true; } msdr.Close(); return(groupMsg); }
public static void SaveGroupMsg(GroupMsg msg) { UpdateTmpUserMsg(msg); if (int.Parse(msg.state) >= 3) { UpdateUserMsg(msg); if (!msg.isManual) { UserDB udb = new UserDB() { userName = msg.GroupName, lastAddr = msg.Area, lastTime = DateTime.Parse(msg.LoadTime), phone = msg.Phone }; main.InsertOrUpdateUser(udb); } } if (msg.FileMsgList != null) { foreach (var v in msg.FileMsgList) { UpdateTmpFileMsg(v); } } }
public void setFormLable(GroupMsg msg) { 出货时间.Text = DateTime.Now.ToString("HH:mm:ss"); 订单.Text = "【" + msg.GroupName + "】"; List <string> s = new List <string>(); if (msg.FileMsgList == null) { 设备.Text = msg.Printer; } else { foreach (var v in msg.FileMsgList) { if (!s.Contains("【" + FileHelper.SubStringByByte2(v.Printer, 16) + "】")) { s.Add("【" + FileHelper.SubStringByByte2(v.Printer, 16) + "】"); } } } for (int i = 0; i < s.Count; i++) { if (i < 2) { 设备.Text += s[i] + " "; } else { 设备.Text += "..."; break; } } 文件个数.Text = msg.FileMsgList == null ? "0" : msg.FileMsgList.Count.ToString(); 配送时间.Text = msg.Time == null ? "" : msg.Time.ToString(); 备注.Text = msg.Note == null ? "" : msg.Note.ToString(); }
/// <summary> /// 生成文字图片 /// </summary> /// <param name="text"></param> /// <param name="isBold"></param> /// <param name="fontSize"></param> public static Image CreateImage(GroupMsg msg, out int height) { height = 0; int[] column = new int[] { 140, 30, 40 }; int[] margin = new int[] { 3, 3, 3, 3 }; int rowSpan = 3; int high = margin[3]; Point startPoint = new Point(margin[0], margin[3]); Image image = new Bitmap(column[0] + column[1] + column[2] + margin[0] + margin[2], margin[3]); Font font = new Font("宋体", 20, FontStyle.Bold); startPoint.Y = high; image = addRow(image, column[0] + column[1] + column[2] + margin[0] + margin[2], margin[1], 30, msg.GroupName, font); high += AddText(ref image, startPoint, msg.GroupName, font, column[0] + column[1] + column[2], 30, true, true, 0); high += rowSpan; font = new Font("宋体", 19, FontStyle.Bold); startPoint.Y = high; image = addRow(image, column[0] + column[1] + column[2] + margin[0] + margin[2], high, 25, msg.Area, font); high += AddText(ref image, startPoint, msg.Area, font, column[0] + column[1] + column[2], 25, true, false, 0); high += rowSpan; int sum = 0; if (msg.FileMsgList != null && msg.FileMsgList.Count != 0) { var tmpVar = msg.FileMsgList.GroupBy(t => t.Printer).ToList(); foreach (var v in tmpVar) { font = new Font("宋体", 10, FontStyle.Regular); startPoint.Y = high; image = addRow(image, column[0] + column[1] + column[2] + margin[0] + margin[2], high, 20, FileHelper.SubStringByByte(v.Key, 16) + "输出", font); high += AddText(ref image, startPoint, FileHelper.SubStringByByte(v.Key, 16) + "输出", font, column[0] + column[1] + column[2], 20, true, true, 2); high += rowSpan; var Enum = v.GetEnumerator(); Enum.MoveNext(); while (true) { var flist = Enum.Current; sum += int.Parse(flist.Count); string fileName = flist.FileName; string count = flist.Count.ToString(); string verForm = flist.VerForm.ToString(); if (!Enum.MoveNext() || Enum == null) { font = new Font("宋体", 10, FontStyle.Regular); startPoint.Y = high; image = addRow(image, column[0] + column[1] + column[2] + margin[0] + margin[2], high, 17, FileHelper.SubStringByByte2(fileName, 6), font); high += AddText(ref image, startPoint, FileHelper.SubStringByByte2(fileName, 12), font, column[0], 17, true, false, 2); high += rowSpan; AddText(ref image, new Point(startPoint.X + column[0], startPoint.Y), count, font, column[1], 17, false, false, 2); AddText(ref image, new Point(startPoint.X + column[0] + column[1], startPoint.Y), verForm, font, column[2], 17, false, false, 2); break; } else { font = new Font("宋体", 10, FontStyle.Regular); startPoint.Y = high; image = addRow(image, column[0] + column[1] + column[2] + margin[0] + margin[2], high, 17, FileHelper.SubStringByByte2(fileName, 6), font); high += AddText(ref image, startPoint, FileHelper.SubStringByByte2(fileName, 12), font, column[0], 17, true, false, 0); high += rowSpan; AddText(ref image, new Point(startPoint.X + column[0], startPoint.Y), count, font, column[1], 17, false, false, 0); AddText(ref image, new Point(startPoint.X + column[0] + column[1], startPoint.Y), verForm, font, column[2], 17, false, false, 0); } } } font = new Font("宋体", 10, FontStyle.Bold); startPoint.Y = high; image = addRow(image, column[0] + column[1] + column[2] + margin[0] + margin[2], high, 20, string.Format(@"文件总数:{0}", sum.ToString()), font); high += AddText(ref image, startPoint, string.Format(@"文件总数:{0}", sum.ToString()), font, column[0] + column[1] + column[2], 20, true, true, 0); high += rowSpan; } else { font = new Font("宋体", 10, FontStyle.Regular); startPoint.Y = high; image = addRow(image, column[0] + column[1] + column[2] + margin[0] + margin[2], high, 20, "打印输出", font); high += AddText(ref image, startPoint, "打印输出", font, column[0] + column[1] + column[2], 20, true, true, 2); high += rowSpan; font = new Font("宋体", 10, FontStyle.Regular); startPoint.Y = high; image = addRow(image, column[0] + column[1] + column[2] + margin[0] + margin[2], high, 17, FileHelper.SubStringByByte2(msg.FileName, 12), font); high += AddText(ref image, startPoint, FileHelper.SubStringByByte2(msg.FileName, 12), font, column[0], 17, true, false, 2); high += rowSpan; AddText(ref image, new Point(startPoint.X + column[0], startPoint.Y), msg.Count.ToString(), font, column[1], 17, false, false, 2); AddText(ref image, new Point(startPoint.X + column[0] + column[1], startPoint.Y), msg.VerForm.ToString(), font, column[2], 17, false, false, 2); } font = new Font("宋体", 10, FontStyle.Bold); startPoint.Y = high; image = addRow(image, column[0] + column[1] + column[2] + margin[0] + margin[2], high, 20, 3, msg.Note, font); high += AddHeightText(ref image, startPoint, msg.Note, font, column[0] + column[1] + column[2], 20, 3, true, true, 0xF); high += rowSpan; if (!File.Exists(frm_Main.sysConfigData.BarcodePath)) { MessageBox.Show("二维码路径设置异常!"); return(null); } Image i = Image.FromFile(frm_Main.sysConfigData.BarcodePath); //if (i.Size.Width > column[0] + column[1] + column[2]) //{ // MessageBox.Show("二维码图片尺寸过大!"); // height = high; // return null; //} startPoint.Y = high; image = addRow(image, column[0] + column[1] + column[2] + margin[0] + margin[2], high, i.Height + 10); high += AddImage(ref image, i, startPoint, column[0] + column[1] + column[2], i.Height + 10, 0); high += rowSpan; font = new Font("宋体", 16, FontStyle.Bold); startPoint.Y = high; image = addRow(image, column[0] + column[1] + column[2] + margin[0] + margin[2], high, 22, msg.Price.ToString(), font); high += AddText(ref image, startPoint, msg.Price.ToString() + "元", font, column[0] + column[1] + column[2], 22, false, false, 0); high += rowSpan; string shopName = frm_Main.sysConfigData.ShopName; font = new Font("宋体", 14, FontStyle.Bold); startPoint.Y = high; image = addRow(image, column[0] + column[1] + column[2] + margin[0] + margin[2], high, 20, shopName, font); high += AddText(ref image, startPoint, shopName, font, column[0] + column[1] + column[2], 20, false, false, 0); high += rowSpan; font = new Font("宋体", 14, FontStyle.Bold); startPoint.Y = high; image = addRow(image, column[0] + column[1] + column[2] + margin[0] + margin[2], high, 20, string.Format(@"{0}/{1}", msg.Area, msg.Time), font); high += AddText(ref image, startPoint, string.Format(@"{0}/{1}", msg.Area, msg.Time), font, column[0] + column[1] + column[2], 20, false, false, 0); high += rowSpan; font = new Font("宋体", 14, FontStyle.Bold); startPoint.Y = high; image = addRow(image, column[0] + column[1] + column[2] + margin[0] + margin[2], high, 25, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), font); high += AddText(ref image, startPoint, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), font, column[0] + column[1] + column[2], 25, false, false, 0); high += rowSpan; font = new Font("宋体", 14, FontStyle.Bold); startPoint.Y = high; string p = msg.Phone == null ? "" : msg.Phone.ToString(); image = addRow(image, column[0] + column[1] + column[2] + margin[0] + margin[2], high, 25, p, font); high += AddText(ref image, startPoint, p, font, column[0] + column[1] + column[2], 25, false, false, 0); high += rowSpan; //font = new Font("宋体", 20, FontStyle.Bold); //startPoint.Y = high; //image = addRow(image, column[0] + column[1] + column[2] + margin[0] + margin[2], margin[1], high,10, "打印机1 输出...打印机1 输出...打印机1 输出...", // font); //high += AddHeightText(ref image, startPoint, "打印机1 输出...打印机1 输出...打印机1 输出...", font, 200, 35,10, true, true, 0xF); //Image i = Image.FromFile(@"二维码.png"); //startPoint.Y = high; //image = addRow(image, column[0] + column[1] + column[2] + margin[0] + margin[2], high,i.Height+10); //AddImage(ref image,i,startPoint, column[0] + column[1] + column[2], i.Height + 10,0); //startPoint.Y = high; //high += 30; //image = addRow(image, column[0] + column[1] + column[2] + margin[0] + margin[2], high + margin[1]); //AddText(ref image, startPoint, "文件1", font, column[0], 30, true, false, 0x0); //AddText(ref image, new Point(startPoint.X + column[0],startPoint.Y), "12", font, column[1], 30, true, false, 0x0); //AddText(ref image, new Point(startPoint.X + column[0] + column[1], startPoint.Y), "正反", font, column[2], 30, true, false, 0x0); height = high; return(image); }
public static List <GroupMsg> selectTmpUserMsg() { try { List <GroupMsg> GroupMsgList = new List <GroupMsg>(); string s1 = DateTime.Now.ToString("yyyy-MM-dd"); string s2 = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"); string s3 = DateTime.Now.AddDays(-2).ToString("yyyy-MM-dd"); string s4 = DateTime.Now.AddDays(-3).ToString("yyyy-MM-dd"); string s5 = DateTime.Now.AddDays(-4).ToString("yyyy-MM-dd"); string sql1 = string.Format(@" select DISTINCT UserID, FileName, FullName, GroupName, FileDirectory, Count, VerForm, PrintColor, PaperType, Printer, PageCount, InitPageCount, Price, InitPrice, Time, Area, Phone, SetTime, LoadTime, FinishTime, DeleteTime, CreateTime, PayType, State, isRemove, isManual, Note, FileSize from tmpusermsg where LoadTime like '{0}%' or LoadTime like '{1}%' or LoadTime like '{2}%' or LoadTime like '{3}%' or LoadTime like '{4}%' ", s1, s2, s3, s4, s5); SQLiteDataReader msdr = SQLiteHelper.ExecuteDataReader(sql1); while (msdr.Read()) { GroupMsg groupMsg = new GroupMsg(); groupMsg.UserID = msdr["UserID"] == DBNull.Value ? "" : msdr["UserID"].ToString(); groupMsg.FileName = msdr["FileName"] == DBNull.Value ? "" : msdr["FileName"].ToString(); groupMsg.FullName = msdr["FullName"] == DBNull.Value ? "" : msdr["FullName"].ToString(); groupMsg.GroupName = msdr["GroupName"] == DBNull.Value ? "" : msdr["GroupName"].ToString(); groupMsg.FileDirectory = msdr["FileDirectory"] == DBNull.Value ? "" : msdr["FileDirectory"].ToString(); groupMsg.Count = msdr["Count"] == DBNull.Value ? "" : msdr["Count"].ToString(); groupMsg.VerForm = msdr["VerForm"] == DBNull.Value ? "" : msdr["VerForm"].ToString(); groupMsg.PrintColor = msdr["PrintColor"] == DBNull.Value ? "" : msdr["PrintColor"].ToString(); groupMsg.PaperType = msdr["PaperType"] == DBNull.Value ? "" : msdr["PaperType"].ToString(); groupMsg.Printer = msdr["Printer"] == DBNull.Value ? "" : msdr["Printer"].ToString(); groupMsg.PageCount = msdr["PageCount"] == DBNull.Value ? "" : msdr["PageCount"].ToString(); groupMsg.InitPageCount = msdr["InitPageCount"] == DBNull.Value ? "" : msdr["InitPageCount"].ToString(); groupMsg.Price = msdr["Price"] == DBNull.Value ? "" : msdr["Price"].ToString(); groupMsg.InitPrice = msdr["InitPrice"] == DBNull.Value ? "" : msdr["InitPrice"].ToString(); groupMsg.Time = msdr["Time"] == DBNull.Value ? "" : msdr["Time"].ToString(); groupMsg.Area = msdr["Area"] == DBNull.Value ? "" : msdr["Area"].ToString(); groupMsg.Phone = msdr["Phone"] == DBNull.Value ? "" : msdr["Phone"].ToString(); groupMsg.SetTime = msdr["SetTime"] == DBNull.Value ? "" : msdr["SetTime"].ToString(); groupMsg.LoadTime = msdr["LoadTime"] == DBNull.Value ? "" : msdr["LoadTime"].ToString(); groupMsg.FinishTime = msdr["FinishTime"] == DBNull.Value ? "" : msdr["FinishTime"].ToString(); groupMsg.DeleteTime = msdr["DeleteTime"] == DBNull.Value ? "" : msdr["DeleteTime"].ToString(); groupMsg.CreateTime = msdr["CreateTime"] == DBNull.Value ? "" : msdr["CreateTime"].ToString(); groupMsg.PayType = msdr["PayType"] == DBNull.Value ? "" : msdr["PayType"].ToString(); groupMsg.state = msdr["State"] == DBNull.Value ? "" : msdr["State"].ToString(); string s = msdr["isRemove"] == DBNull.Value ? "0": msdr["isRemove"].ToString(); groupMsg.isRemove = (s == "0" ? false: true); s = msdr["isManual"] == DBNull.Value ? "0" : msdr["isManual"].ToString(); groupMsg.isManual = (s == "0" ? false : true); groupMsg.Note = msdr["Note"] == DBNull.Value ? "" : msdr["Note"].ToString(); GroupMsgList.Add(groupMsg); } msdr.Close(); return(GroupMsgList); } catch (Exception ex) { MessageBox.Show(ex.Message); return(null); } }
public static bool DeleteGroupMsg(GroupMsg msg) { return(deleteAllFileMsg(msg.UserID) && deleteUserMsg(msg.UserID) && deleteAllTmpFileMsg(msg.UserID) && deleteTmpUserMsg(msg)); }
public static void GetUserMsg(string root) { string destPath = System.Windows.Forms.Application.StartupPath + @"\tmpCaeaload"; if (!Directory.Exists(destPath)) { Directory.CreateDirectory(destPath); } int i = 0; DirectoryInfo tmpRootInfo = new DirectoryInfo(root); List <GroupMsg> tmpList = new List <GroupMsg>(); DirectoryInfo[] tmpInfoArray = tmpRootInfo.GetDirectories(); foreach (var tmpInfo in tmpInfoArray) { if (frm_Main.bExit) { break; } if (FileHelper.GetFileCount(tmpInfo) == 0) { //tmpInfo.Delete(); //MessageBox.Show("文件夹:" + tmpInfo.Name + " 异常!"); LogOperate.Add("文件夹:" + tmpInfo.Name + "为空"); //tmpInfoArray = tmpRootInfo.GetDirectories(); continue; } List <FileMsg> tmpFileMsg = new List <FileMsg>(); string tmps = destPath + "\\" + tmpInfo.Name + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + "(_caeaload)"; string newName = tmps.Replace(destPath + "\\", ""); if ((tmpFileMsg = GetAllFile(tmpInfo, tmpInfo.Name, newName, tmps, tmpInfo.FullName)) != null && tmpFileMsg.Count != 0) { try { newName = tmpInfo.Name; LogOperate.Add("开始移动订单:" + tmpInfo.Name); tmpInfo.MoveTo(tmps); } catch (Exception ex) { LogOperate.Add("移动订单失败:" + tmpInfo.Name + "," + ex.Message); //MessageBox.Show("移动订单失败:" + tmpInfo.Name + "," + ex.Message); Thread.Sleep(100); tmpInfoArray = tmpRootInfo.GetDirectories(); continue; } GroupMsg groupmsg = new GroupMsg() { UserID = tmpInfo.Name, CreateTime = tmpInfo.CreationTime.ToString("yyyy-MM-dd HH:mm:ss"), FileMsgList = tmpFileMsg, LoadTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), FileDirectory = frm_Main.CurrentPath, state = "0", GroupName = newName, Count = "1", PageCount = tmpFileMsg.Sum(t => t.PageCount == "----" ? 0 : int.Parse(t.PageCount)).ToString(), //initPageCount = tmpFileMsg.Sum(t => t.PageCount == -1 ? 0 : t.PageCount), VerForm = "正反", PrintColor = "黑白", PaperType = GetPaperType.defaultBWPaper, Printer = GetPrinterType.defaultBWPrinter, PayType = "4", SetTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), FullName = tmpInfo.FullName.Trim('\\'), isInit = true }; groupmsg.FileName = groupmsg.GetDisplayFileName(); groupmsg.InitPageCount = groupmsg.PageCount; groupmsg.InitPrice = "-2"; tmpList.Add(groupmsg); Thread.Sleep(10); } else { Thread.Sleep(100); } } #region //while (tmpInfoArray.Count() > 0) //{ // if (frm_Main.bExit) // break; // DirectoryInfo tmpInfo = tmpInfoArray[0]; // if (FileHelper.GetFileCount(tmpInfo) == 0) // { // //tmpInfo.Delete(); // MessageBox.Show("文件夹:" + tmpInfo.Name + " 异常!"); // tmpInfoArray = tmpRootInfo.GetDirectories(); // continue ; // } // List<FileMsg> tmpFileMsg = new List<FileMsg>(); // string tmps = destPath + "\\" + tmpInfo.Name + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + "(_caeaload)"; // string newName = tmps.Replace(destPath + "\\",""); // if ((tmpFileMsg = GetAllFile(tmpInfo, tmpInfo.Name, newName, tmps, tmpInfo.FullName)) != null && tmpFileMsg.Count != 0) // { // try // { // newName = tmpInfo.Name; // LogOperate.Add("开始移动订单:" + tmpInfo.Name); // tmpInfo.MoveTo(tmps); // } // catch (Exception ex) // { // LogOperate.Add("移动订单失败:" + tmpInfo.Name + "," + ex.Message); // MessageBox.Show("移动订单失败:" + tmpInfo.Name + "," + ex.Message); // Thread.Sleep(100); // tmpInfoArray = tmpRootInfo.GetDirectories(); // continue; // } // GroupMsg groupmsg = new GroupMsg() // { // UserID = tmpInfo.Name, // CreateTime = tmpInfo.CreationTime.ToString("yyyy-MM-dd HH:mm:ss"), // FileMsgList = tmpFileMsg, // LoadTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), // FileDirectory = frm_Main.CurrentPath, // state = "0", // GroupName = newName, // Count = "1", // PageCount = tmpFileMsg.Sum(t => t.PageCount == "----" ? 0: int.Parse( t.PageCount)).ToString(), // //initPageCount = tmpFileMsg.Sum(t => t.PageCount == -1 ? 0 : t.PageCount), // VerForm = "正反", // PrintColor = "黑白", // PaperType = GetPaperType.defaultBWPaper, // Printer = GetPrinterType.defaultBWPrinter, // PayType = "4", // SetTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), // FullName = tmpInfo.FullName.Trim('\\'), // isInit = true // }; // groupmsg.FileName = groupmsg.GetDisplayFileName(); // groupmsg.InitPageCount = groupmsg.PageCount; // groupmsg.InitPrice = "-2"; // tmpList.Add(groupmsg); // Thread.Sleep(10); // } // else // Thread.Sleep(100); // tmpInfoArray = tmpRootInfo.GetDirectories(); //} #endregion foreach (var v in tmpList) { UserDB userDB = SqlModlus.selectUserMsg(v.GroupName); v.Printer = v.FileMsgList.Count() == v.FileMsgList.Count(t => t.isNormalFile) ? "----" : GetPrinterType.defaultBWPrinter; v.PaperType = GetPaperType.defaultBWPaper; v.Area = FileHelper.addrList.Contains(userDB.lastAddr) ? userDB.lastAddr : null; v.Phone = userDB.phone; foreach (var subv in v.FileMsgList) { subv.Printer = subv.isNormalFile ? "----" : GetPrinterType.defaultBWPrinter; subv.PaperType = GetPaperType.defaultBWPaper; subv.Price = subv.GetPrice(); subv.InitPrice = "-2"; } v.Price = v.GetPrice(); v.GetDisplayVerForm(); } foreach (var v in tmpList) { if (v.FileMsgList.Count == 0) { MessageBox.Show("订单有效文件为空!"); continue; } if (!SqlModlus.InsertTmpUserMsg(v)) { MessageBox.Show("订单保存异常!"); } Thread.Sleep(1); foreach (var v1 in v.FileMsgList) { if (!SqlModlus.InsertTmpFileMsg(v1)) { MessageBox.Show("文件保存异常!"); } Thread.Sleep(1); } } if (main.groupList == null) { main.groupList = new List <GroupMsg>(); } foreach (var v in main.groupList) { if (v.isRemove) { continue; } if (v.isManual) { v.isInit = true; continue; } } main.groupList.AddRange(tmpList); main.groupList.ForEach(t => t.isPrint = false); //main.groupList.RemoveAll(t => t.isRemove == true); }
public static void ExportExcel(GroupMsg msg, string printer, bool isPreView) { if (!File.Exists(frm_Main.sysConfigData.BarcodePath)) { MessageBox.Show("获取二维码失败,请重新设置!"); return; } int rowCount = 1; Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application(); Workbook wbks = app.Workbooks.Add(true); Worksheet ws = (Worksheet)wbks.Worksheets[1]; try { ws.Rows.AutoFit(); ws.Columns[1].ColumnWidth = 20; ws.Columns[2].ColumnWidth = 3; ws.Columns[3].ColumnWidth = 5; int sum = 0; app.Rows.AutoFit(); AddMergeText(rowCount++, ws, msg.GroupName, true, 24, 30, true, true, 0); AddMergeText(rowCount++, ws, msg.Area, true, 24, 25, true, false, 0); if (msg.FileMsgList != null && msg.FileMsgList.Count != 0) { var tmpVar = msg.FileMsgList.GroupBy(t => t.Printer).ToList(); foreach (var v in tmpVar) { AddMergeText(rowCount++, ws, FileHelper.SubStringByByte(v.Key, 16) + "输出", false, 10, 18, true, true, 2); var Enum = v.GetEnumerator(); Enum.MoveNext(); while (true) { var flist = Enum.Current; sum += int.Parse(flist.Count); string fileName = flist.FileName; string count = flist.Count.ToString(); string verForm = flist.VerForm.ToString(); if (!Enum.MoveNext() || Enum == null) { AddText(rowCount++, ws, new string[] { FileHelper.SubStringByByte2(fileName, 16), count, verForm }, true, 10, 18, false, 2); break; } else { AddText(rowCount++, ws, new string[] { FileHelper.SubStringByByte2(fileName, 16), count, verForm }, true, 10, 18, false, 0); } } } AddMergeText(rowCount++, ws, string.Format(@"文件总数:{0}", sum.ToString()), true, 10, 18, true, false, 0); AddMergeText(rowCount++, ws, "", true, 10, 10, true, false, 0); } else { AddMergeText(rowCount++, ws, "手动输出", false, 10, 18, true, true, 2); AddText(rowCount++, ws, new string[] { FileHelper.SubStringByByte2(msg.FileName, 16), msg.Count.ToString(), msg.VerForm.ToString() }, true, 10, 18, false, 0); AddMergeText(rowCount++, ws, "", true, 10, 10, true, false, 1); } if (msg.Note != null && msg.Note != "") { AddNote(rowCount++, ws, msg.Note, true, 10, 3, 0x0f); rowCount = rowCount + 3; } AddPic(rowCount++, ws, 4, frm_Main.sysConfigData.BarcodePath); rowCount = rowCount + 4; AddMergeText(rowCount++, ws, msg.Price.ToString() + "元", true, 16, 25, false, false, 0); string shopName = frm_Main.sysConfigData.ShopName; AddMergeText(rowCount++, ws, shopName, true, 12, 20, false, false, 0); AddMergeText(rowCount++, ws, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), true, 12, 16, false, false, 0); AddMergeText(rowCount++, ws, string.Format(@"{0}/{1}", msg.Area, msg.Time), true, 18, 25, false, false, 0); AddMergeText(rowCount++, ws, msg.Phone == null?"":msg.Phone, true, 18, 25, false, false, 0); ws.PageSetup.Zoom = false; ws.PageSetup.FitToPagesTall = 1; ws.PageSetup.FitToPagesWide = 1; ws.PageSetup.TopMargin = 0.5 / 0.035; //上边距为2cm(转换为in) ws.PageSetup.BottomMargin = 0.5 / 0.035; //下边距为1.5cm ws.PageSetup.LeftMargin = 0.001 / 0.035; //左边距为2cm ws.PageSetup.RightMargin = 0.001 / 0.035; //右边距为2cm ws.PageSetup.CenterHorizontally = true; ws.Visible = XlSheetVisibility.xlSheetVisible; app.Visible = false; //ws.PrintPreview(true); if (isPreView) { ws.PrintPreview(true); } else { ws.PrintOutEx(Missing.Value, Missing.Value, Missing.Value, Missing.Value, printer, Missing.Value, Missing.Value, Missing.Value, Missing.Value); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { wbks.Saved = true; wbks.SaveCopyAs(Environment.CurrentDirectory + @"\123.XLSX"); app.Quit(); app = null; GC.Collect(); } }