예제 #1
0
파일: MainForm.cs 프로젝트: kkcn-git/Egode
        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;
            }
        }
예제 #2
0
        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;
            }
        }