public PdfPacketInfoListViewItem(PdfPacketInfoEx p) { _p = p; _p.OnDataChanged += new EventHandler(_p_OnDataChanged); this.UseItemStyleForSubItems = false; //this.Text = index.ToString("000"); this.SubItems.Add(PdfPacketInfo.GetPacketTypeDesc(_p.Type)); this.SubItems.Add(_p.MatchedRecipientName); this.SubItems.Add(_p.RecipientName); this.SubItems.Add(_p.ReceiverPhone); this.SubItems.Add(_p.ShipmentNumber); this.SubItems.Add(_p.Weight.ToString("0.0kg")); this.SubItems.Add(_p.Status); this.SubItems.Add(_p.Address); this.SubItems.Add(Path.GetFileName(_p.Filename)); this.SubItems[2].BackColor = Color.LightBlue; if (string.IsNullOrEmpty(_p.ShipmentNumber)) { this.SubItems[5].Text = "未找到国际单号"; this.SubItems[5].ForeColor = Color.Red; } }
public PdfPacketInfoListViewItem(PdfPacketInfoEx p) { _p = p; _p.OnDataChanged += new EventHandler(_p_OnDataChanged); this.Text = _p.MatchedRecipientName; this.SubItems.Add(_p.RecipientName); this.SubItems.Add(_p.ReceiverPhone); this.SubItems.Add(_p.ShipmentNumber); this.SubItems.Add(_p.Weight.ToString("0.0kg")); this.SubItems.Add(Path.GetFileName(_p.Filename)); this.SubItems[0].BackColor = Color.LightBlue; this.UseItemStyleForSubItems = false; }
// Modified by KK on 2015/12/24. // 不再使用系统Clipboard来传递单号信息. // 在PacketInfoListForm中保存全局静态包裹单信息, 总是记录当前选中的包裹单. // 为兼容旧代码, 函数名沿用CopyShipmentNumberInfoToClipboard() //private void CopyShipmentNumberInfoToClipboard() //{ // if (lvwPdfPacketInfos.SelectedItems.Count <= 0) // return; // PdfPacketInfoEx ppi = ((PdfPacketInfoListViewItem)lvwPdfPacketInfos.SelectedItems[0]).PacketInfo; // string shipmentNumberInfo = string.Format("[{0}] {1}", Packet.GetPacketTypePrefix(ppi.Type), ppi.ShipmentNumber); // SetCliboardText(shipmentNumberInfo); // Application.DoEvents(); // ClipboardPromptForm cpf = new ClipboardPromptForm("单号", shipmentNumberInfo); // cpf.Show(this); // cpf.Location = new Point(this.Location.X + (this.Width - cpf.Width) / 2, this.Location.Y + (this.Height - cpf.Height) / 2); // lblClipboardPrompt.Text = string.Format("单号<{0}>已复制到剪贴板", shipmentNumberInfo); // lblClipboardPrompt.Visible = true; // Application.DoEvents(); //} private void CopyShipmentNumberInfoToClipboard() { if (lvwPdfPacketInfos.SelectedItems.Count <= 0) { return; } _selectedPacketInfo = ((PdfPacketInfoListViewItem)lvwPdfPacketInfos.SelectedItems[0]).PacketInfo; //string shipmentNumberInfo = string.Format("[{0}] {1}", Packet.GetPacketTypePrefix(ppi.Type), ppi.ShipmentNumber); //SetCliboardText(shipmentNumberInfo); //Application.DoEvents(); //ClipboardPromptForm cpf = new ClipboardPromptForm("单号", shipmentNumberInfo); //cpf.Show(this); //cpf.Location = new Point(this.Location.X + (this.Width - cpf.Width) / 2, this.Location.Y + (this.Height - cpf.Height) / 2); lblClipboardPrompt.Text = string.Format("包裹单信息已记录: [{0}]{1}", Packet.GetPacketTypeDesc(_selectedPacketInfo.Type), _selectedPacketInfo.ShipmentNumber); lblClipboardPrompt.Visible = true; Application.DoEvents(); }
void btnSearchByRecipientPinyinName_Click(object sender, EventArgs e) { if (null == this.OnSearch) { return; } PdfPacketInfoEx ppi = (PdfPacketInfoEx)((Button)sender).Tag; if (!string.IsNullOrEmpty(ppi.ShipmentNumber)) { Clipboard.SetText(ppi.ShipmentNumber); ClipboardPromptForm cpf = new ClipboardPromptForm("µ¥ºÅ", ppi.ShipmentNumber); cpf.Show(this); cpf.Location = new Point(this.Location.X + (this.Width - cpf.Width) / 2, this.Location.Y + (this.Height - cpf.Height) / 2); Application.DoEvents(); } this.OnSearch(ppi.RecipientName.Replace(" ", string.Empty).Trim()); }
private List <PdfPacketInfoEx> GetPdfPacketInfos(string folder) { string[] pdfFiles = Directory.GetFiles(folder, "*.pdf"); if (null == pdfFiles || pdfFiles.Length <= 0) { return(null); } List <PdfPacketInfoEx> pdfPackets = new List <PdfPacketInfoEx>(); foreach (string pdfFile in pdfFiles) { PdfPacketInfoEx ppi = PdfPacketInfoEx.GetPdfPacketInfoEx(pdfFile); if (null == ppi) { continue; } pdfPackets.Add(ppi); Trace.WriteLine(string.Format("{0},{1},{2},{3}", ppi.Type, ppi.RecipientName, ppi.ShipmentNumber, ppi.Weight)); } return(pdfPackets); }
public static List <PdfPacketInfoEx> GetPdfPacketInfos(string folder, bool includeSubdir) { string[] pdfFiles = Directory.GetFiles(folder, "*.pdf", includeSubdir ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly); if (null == pdfFiles || pdfFiles.Length <= 0) { return(null); } List <PdfPacketInfoEx> pdfPackets = new List <PdfPacketInfoEx>(); foreach (string pdfFile in pdfFiles) { PdfPacketInfoEx ppi = PdfPacketInfoEx.GetPdfPacketInfoEx(pdfFile); if (null == ppi) { continue; } pdfPackets.Add(ppi); Trace.WriteLine(string.Format("{0},{1},{2},{3}", ppi.Type, ppi.RecipientName, ppi.ShipmentNumber, ppi.Weight)); } return(pdfPackets); }
private void UpdateShipmentNumberInPackingList(string packingListExcel, List <PdfPacketInfoEx> pdfPackets) { Cursor.Current = Cursors.WaitCursor; Excel excel = null; try { excel = new Excel(packingListExcel, true); } catch { MessageBox.Show( this, "Open Excel file of packing list failed.\nMake sure the Excel file was not opened and try again.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } try { DataSet ds = excel.Get("Sheet1", string.Empty); if (null == ds) { return; } for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { DataRow dr = ds.Tables[0].Rows[i]; //Trace.WriteLine(dr.ItemArray[1].ToString()); string recipientNameCn = dr.ItemArray[1].ToString(); if (string.IsNullOrEmpty(recipientNameCn)) { continue; } if (recipientNameCn.Equals("张秋兰")) { Trace.Write(""); } string recipientNamePinyin = HanZiToPinYin.Convert(recipientNameCn); PdfPacketInfoEx ppi = PdfPacketInfoEx.GetItem(recipientNamePinyin, pdfPackets, true); if (null == ppi) { PdfPacketInfoEx ppi1 = new PdfPacketInfoEx(string.Empty, PacketTypes.Unknown, string.Empty, string.Empty, 0); ppi1.MatchedRecipientName = recipientNameCn; pdfPackets.Add(ppi1); continue; } ppi.MatchedRecipientName = recipientNameCn; try { excel.Update( "Sheet1", "运单号", string.Format("{0}:{1}", ppi.RecipientName, ppi.ShipmentNumber), "序号", dr.ItemArray[0].ToString()); //"收货人", recipientNameCn); ppi.Updated = true; } catch (Exception ex) { Trace.WriteLine(ex); } //Trace.WriteLine(string.Format("Matched: {0}, {1}, {2}, {3}", recipientNameCn, ppi.RecipientName, ppi.ShipmentNumber, ppi.Weight)); } } catch (Exception ex) { MessageBox.Show(this, "Error occured during udpate shipment number into excel file.\n" + ex.ToString(), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } finally { excel.Close(); Cursor.Current = Cursors.Default; } }
private void UpdateShipmentNumberInPackingList(string packingListExcel) { Cursor.Current = Cursors.WaitCursor; Excel excel = null; try { excel = new Excel(packingListExcel, true); } catch { MessageBox.Show( this, "Open Excel file of packing list failed.\nMake sure the Excel file was not opened and try again.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } try { DataSet ds = excel.Get("Sheet1", string.Empty); if (null == ds) { return; } for (int i = 1; i <= ds.Tables[0].Rows.Count; i++) { excel.Insert("Sheet1", string.Format("G{0}:G{0}", i), string.Format("'x{0}'", Guid.NewGuid().ToString())); } excel.Close(); System.Threading.Thread.Sleep(500); Application.DoEvents(); } catch (Exception ex) { Trace.WriteLine(ex); } try { excel = new Excel(packingListExcel, true); DataSet ds = excel.Get("Sheet1", string.Empty); if (null == ds) { return; } for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { DataRow dr = ds.Tables[0].Rows[i]; //Trace.WriteLine(dr.ItemArray[1].ToString()); string recipientNameCn = dr.ItemArray[1].ToString(); if (string.IsNullOrEmpty(recipientNameCn)) { continue; } PdfPacketInfoEx ppi = PdfPacketInfoEx.GetItemByRecipientName(recipientNameCn, _packetInfos, true); if (null == ppi) { PdfPacketInfoEx ppi1 = new PdfPacketInfoEx(string.Empty, PacketTypes.Unknown, string.Empty, string.Empty, string.Empty, 0, string.Empty, string.Empty); ppi1.MatchedRecipientName = recipientNameCn; _packetInfos.Add(ppi1); lvwPdfPacketInfos.Items.Add(new PdfPacketInfoListViewItem(ppi1)); continue; } ppi.MatchedRecipientName = recipientNameCn; try { excel.Update( "Sheet1", "运单号", string.Format("{0}:{1}", ppi.RecipientName, ppi.ShipmentNumber), //"序号", dr.ItemArray[0].ToString()); //"收货人", recipientNameCn); //"序号", dr.ItemArray[0].ToString()); "reserved", dr.ItemArray[6].ToString()); ppi.Updated = true; //Trace.WriteLine(dr.ItemArray[0].ToString()); //if (dr.ItemArray[0].ToString().Equals("28")) // Trace.WriteLine(""); } catch (Exception ex) { Trace.WriteLine(ex); } //Trace.WriteLine(string.Format("Matched: {0}, {1}, {2}, {3}", recipientNameCn, ppi.RecipientName, ppi.ShipmentNumber, ppi.Weight)); } } catch (Exception ex) { MessageBox.Show(this, "Error occured during udpate shipment number into excel file.\n" + ex.ToString(), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } finally { excel.Close(); Cursor.Current = Cursors.Default; } }