Beispiel #1
0
        private void tsbtnExportHigo_Click(object sender, EventArgs e)
        {
            if (lvwOrders.SelectedItems.Count <= 0)
            {
                MessageBox.Show(this, "请选择需要导出的订单先.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            Cursor.Current = Cursors.WaitCursor;

            try
            {
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Filter          = "Excel Files(*.xls)|*.xls|All Files(*.*)|*.*";
                sfd.FileName        = string.Format("buy{0}-dd.xls", DateTime.Now.ToString("yyyyMMdd"));
                sfd.OverwritePrompt = true;
                if (DialogResult.OK == sfd.ShowDialog(this))
                {
                    string templateFilename = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "template-higo.xls");
                    File.Copy(templateFilename, sfd.FileName);
                    Egode.Excel excel = new Egode.Excel(sfd.FileName, Excel.OledbVersions.OLEDB40);

                    foreach (DangdangOrderListViewItem item in lvwOrders.SelectedItems)
                    {
                        DangdangAddressParser ai = new DangdangAddressParser(item.Order.Address);
                        //Trace.WriteLine(item.Order.Address);
                        //Trace.WriteLine(string.Format("{0}, {1}, {2}, {3}", ai.Province, ai.City, ai.District, ai.StreetAddress));
                        //Trace.WriteLine(string.Empty);
                        //continue;

                        object[] args = new object[] {
                            "SAL06", "NBBLK", "邮政国内小包", item.Order.OrderId,
                            string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty,
                            "否",
                            string.Empty, string.Empty,
                            string.Empty,
                            item.Order.RecipientName, item.Order.Mobile,
                            string.Empty,
                            ai.Province, ai.City, ai.District, ai.StreetAddress,
                            ProductInfo.GetProductByDangdangCode(item.Order.UniqueProductCode).NingboId,
                            string.Empty, string.Empty,
                            item.Order.ActualCount,
                            string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty,
                            "否",
                            string.Empty, string.Empty,
                            string.Format("{0},{1}", item.Order.RecipientName, item.Order.IdNumber), "支付宝", string.Empty,
                            string.Empty, string.Empty, string.Empty, string.Empty, string.Empty
                        };

                        excel.Insert("合作代发订单导入模板", string.Empty, args);
                    }

                    excel.Close();
                }
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
Beispiel #2
0
        private void tsbtnImportDangdangOrders_Click(object sender, EventArgs e)
        {
            if (lvwOrders.Items.Count > 0)
            {
                DialogResult dr = MessageBox.Show(this, "当前列表中的订单信息将会被清除.\n是否加载订单文件?", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
                if (DialogResult.No == dr)
                {
                    return;
                }
            }

            Cursor.Current = Cursors.WaitCursor;

            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "Excel Files(*.xlsx)|*.xlsx|Excel Files 97-2003(*.xls)|*.xls|All Files(*.*)|*.*";
            if (DialogResult.OK == ofd.ShowDialog(this))
            {
                Egode.Excel excel = null;
                try
                {
                    excel = new Egode.Excel(ofd.FileName, Excel.OledbVersions.OLEDB12);
                    DataSet ds = excel.Get("Sheet0", string.Empty);
                    lvwOrders.Items.Clear();
                    for (int i = 1; i < ds.Tables[0].Rows.Count; i++)
                    {
                        DataRow  row             = ds.Tables[0].Rows[i];
                        string   orderId         = row.ItemArray[1].ToString();
                        string   sellerId        = row.ItemArray[2].ToString();
                        string   recipientName   = row.ItemArray[3].ToString();
                        string   idNumber        = row.ItemArray[4].ToString();
                        string   mobile          = row.ItemArray[5].ToString();
                        string   address         = row.ItemArray[6].ToString();
                        string   deliveryType    = row.ItemArray[7].ToString();
                        string   deliveryTime    = row.ItemArray[8].ToString();
                        string   paymentType     = row.ItemArray[9].ToString();
                        float    totalMoney      = float.Parse(row.ItemArray[10].ToString());                 ///
                        DateTime dealTime        = DateTime.Parse(row.ItemArray[15].ToString());
                        DateTime payTime         = string.IsNullOrEmpty(row.ItemArray[16].ToString()) ? DateTime.MinValue : DateTime.Parse(row.ItemArray[16].ToString());
                        string   invoice         = row.ItemArray[20].ToString();
                        string   status          = row.ItemArray[24].ToString();
                        float    fee             = float.Parse(row.ItemArray[26].ToString());
                        float    tax             = float.Parse(row.ItemArray[28].ToString());
                        string   productCode     = row.ItemArray[29].ToString();
                        int      count           = int.Parse(row.ItemArray[30].ToString());
                        float    price           = float.Parse(row.ItemArray[31].ToString());
                        string   paymentId       = row.ItemArray[32].ToString();
                        string   device          = row.ItemArray[33].ToString();
                        DateTime consigningTime  = string.IsNullOrEmpty(row.ItemArray[17].ToString()) ? DateTime.MinValue : DateTime.Parse(row.ItemArray[17].ToString());
                        string   shipmentCompany = row.ItemArray[21].ToString();
                        string   shipmentNumber  = row.ItemArray[22].ToString();

                        DangdangOrder o = new DangdangOrder(
                            orderId, sellerId,
                            recipientName, idNumber, mobile, address,
                            deliveryType, deliveryTime, paymentType, totalMoney,
                            dealTime, payTime, invoice, status, fee, tax, productCode, count, price,
                            paymentId,
                            device,
                            consigningTime, shipmentCompany, shipmentNumber);
                        lvwOrders.Items.Add(new DangdangOrderListViewItem(o));
                    }
                }
                finally
                {
                    if (null != excel && excel.Opened)
                    {
                        excel.Close();
                    }
                }
            }

            Cursor.Current = Cursors.Default;
        }
Beispiel #3
0
        private string GeneratePackingListExcelFile(List <PacketInfo> packetInfos, string folder)
        {
            // Generate list for JHT.
            string destPackingListJHT = CreateOutputFile(
                Directory.GetParent(Application.ExecutablePath).FullName, PACKING_LIST_TEMPLATE,
                folder, string.Format(PACKING_LIST_OUTPUT_JHT, DateTime.Now.ToString("yyyyMMdd")));

            if (string.IsNullOrEmpty(destPackingListJHT))
            {
                #region error message
                MessageBox.Show(
                    this,
                    "Create excel file for shipping list for JHT failed.\nMaybe the template file missed.\nMake sure the template file exists in the same folder with the executable file.",
                    this.Text,
                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                #endregion
                return(string.Empty);
            }

            Excel excelPackingListJHT = new Excel(destPackingListJHT);

            try
            {
                for (int i = 0; i < packetInfos.Count; i++)
                {
                    PacketInfo pi       = packetInfos[i];
                    string[]   products = pi.ProductInfo.Split(new char[] { '\r', '\n' });

                    for (int j = 0; j < products.Length; j++)
                    {
                        if (string.IsNullOrEmpty(products[j].Trim()))
                        {
                            continue;
                        }

                        string[] productDetails = products[j].Split(';');
                        object[] values         = new object[] {
                            j == 0 ? (i + 1).ToString():" ",
                            j == 0 ? pi.RecipientNameCn:" ",
                            j == 0 ? "000000000000":" ",
                            productDetails[0].Trim(), productDetails[1].Trim(),
                            productDetails.Length >= 3 ? productDetails[2].Trim() : string.Empty
                        };

                        excelPackingListJHT.Insert("Sheet1", string.Empty, values);
                    }
                }
            }
            catch (Exception ex)
            {
                #region error message
                MessageBox.Show(
                    this,
                    "Error occured during write data into excel file for packing:" + ex.ToString(),
                    this.Text,
                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                #endregion
            }
            finally
            {
                excelPackingListJHT.Close();
            }

            return(destPackingListJHT);
        }
Beispiel #4
0
        private string GenerateOuhuaFiles(List <PacketInfo> packetInfos, string folder)
        {
            try
            {
                string destExcelFile = CreateOutputFile(
                    Directory.GetParent(Application.ExecutablePath).FullName, OUHUA_TEMPLATE_FILENAME,
                    folder,
                    string.Format(OUHUA_EXCEL_OUTPUT_FILENAME, DateTime.Now.ToString("yyyyMMdd")));
                #region error message
                if (string.IsNullOrEmpty(destExcelFile))
                {
                    MessageBox.Show(
                        this,
                        "Create excel file for Ohua failed.\nMaybe rainbow template file missed.\nMake sure the template file exists in the same folder with the executable file.",
                        this.Text,
                        MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return(string.Empty);
                }
                #endregion

                Excel excel = new Excel(destExcelFile);

                try
                {
                    string packTitle         = string.Empty;
                    string realkk            = string.Empty;
                    string pingzhangEmail    = string.Empty;
                    string weight            = string.Empty;
                    string JHT               = string.Empty;
                    string OttoBrennerStr    = string.Empty;
                    string str4a             = string.Empty;
                    string PLZ47877          = string.Empty;
                    string OrtWillich        = string.Empty;
                    string TelNr021548839989 = string.Empty;
                    string deutschland       = string.Empty;
                    string recipientName     = string.Empty;
                    string address           = string.Empty;
                    string address2          = string.Empty;
                    string address3          = string.Empty;
                    string postCode          = string.Empty;
                    string provinceCity      = string.Empty;
                    string china             = string.Empty;
                    string phoneNumber       = string.Empty;
                    string fullAddressCn     = string.Empty;
                    string milkPowder        = string.Empty;
                    string count             = string.Empty;
                    string moneyAmount       = string.Empty;

                    for (int i = 0; i < packetInfos.Count; i++)
                    {
                        PacketInfo pi = packetInfos[i];
                        packTitle += string.Format("'包裹单{0:00}'" + (i >= packetInfos.Count - 1 ? string.Empty : ","), i + 1);
                        //realkk += "'realkk'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                        //pingzhangEmail += "'*****@*****.**'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                        weight            += string.Format("'{0}'" + (i >= packetInfos.Count - 1 ? string.Empty : ","), ((float)pi.Weight / 1000).ToString("0.0"));
                        JHT               += "'JHT International GmbH'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                        OttoBrennerStr    += "'Otto Brenner Str.'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                        str4a             += "'4a'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                        PLZ47877          += "'47877'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                        OrtWillich        += "'Willich'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                        TelNr021548839989 += "'02154 8839989'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                        deutschland       += "'Germany'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                        recipientName     += string.Format("'{0}'" + (i >= packetInfos.Count - 1 ? string.Empty : ","), pi.RecipientNameEn);
                        address           += string.Format("'{0}'" + (i >= packetInfos.Count - 1 ? string.Empty : ","), pi.AddressEn);
                        address2          += string.Format("'{0}'" + (i >= packetInfos.Count - 1 ? string.Empty : ","), " ");
                        address3          += string.Format("'{0}'" + (i >= packetInfos.Count - 1 ? string.Empty : ","), " ");
                        postCode          += string.Format("'{0}'" + (i >= packetInfos.Count - 1 ? string.Empty : ","), pi.PostCode);
                        provinceCity      += string.Format("'{0}'" + (i >= packetInfos.Count - 1 ? string.Empty : ","), pi.ProvinceCityEn);
                        china             += "'China'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                        phoneNumber       += string.Format("'{0}'" + (i >= packetInfos.Count - 1 ? string.Empty : ","), pi.PhoneNumber);
                        fullAddressCn     += string.Format("'{0}'" + (i >= packetInfos.Count - 1 ? string.Empty : ","), pi.FullAddress);
                        milkPowder        += "'Milk powder'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                        count             += "'10'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                        moneyAmount       += "'115.90'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                    }

                    string endColumn = Excel.GetColumnIndex("D", packetInfos.Count - 1);
                    int    row       = 5;
                    //packTitle = "' ',' ',' '," + packTitle;
                    //excel.Insert("DHL申请表", string.Empty, packTitle);
                    excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), packTitle);
                    excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), JHT);
                    excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), OttoBrennerStr);
                    excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), str4a);
                    excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), PLZ47877);
                    excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), OrtWillich);
                    excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), TelNr021548839989);
                    excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), recipientName);
                    excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), address2);
                    excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), address);
                    excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), address2);
                    excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), postCode);
                    excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), address2);
                    excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), provinceCity);
                    excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), phoneNumber);
                    excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), china);
                    excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), weight);
                    excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), milkPowder);
                    excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), moneyAmount);
                    //excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), realkk);
                    //excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), pingzhangEmail);
                    ////excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), deutschland);
                    ////excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), address);
                    ////excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), address2);
                    ////excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), address3);
                    ////excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), fullAddressCn);
                    ////row++;
                    ////row++;
                    ////row++;
                    ////excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), count);
                    ////excel.Insert("DHL申请表", string.Format("D{0}:{1}{0}", row++, endColumn), weight);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(
                        this,
                        "Error occured during inserting information into excel for dealworthier.\n" + ex.ToString(),
                        this.Text,
                        MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                finally
                {
                    excel.Close();
                }

                return(destExcelFile);
            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    this,
                    "Error occured during generating files for rainbow:" + ex.ToString(),
                    this.Text,
                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return(string.Empty);
            }
        }
Beispiel #5
0
        private string GenerateRainbowFiles(List <PacketInfo> packetInfos, string folder)
        {
            try
            {
                string destExcelFile = CreateOutputFile(
                    Directory.GetParent(Application.ExecutablePath).FullName, RAINBOW_TEMPLATE_FILENAME,
                    folder, RAINBOW_EXCEL_OUTPUT_FILENAME);
                #region error message
                if (string.IsNullOrEmpty(destExcelFile))
                {
                    MessageBox.Show(
                        this,
                        "Create excel file for rainbow failed.\nMaybe rainbow template file missed.\nMake sure the template file exists in the same folder with the executable file.",
                        this.Text,
                        MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return(string.Empty);
                }
                #endregion

                Excel rainbowExcel = new Excel(destExcelFile);

                try
                {
                    string packTitle         = string.Empty;
                    string pingzhangEmail    = string.Empty;
                    string realkk            = string.Empty;
                    string JHT               = string.Empty;
                    string OttoBrennerStr4a  = string.Empty;
                    string PLZ47877          = string.Empty;
                    string OrtWillich        = string.Empty;
                    string TelNr021548839989 = string.Empty;
                    string recipientName     = string.Empty;
                    string address           = string.Empty;
                    string postCode          = string.Empty;
                    string provinceCity      = string.Empty;
                    string phoneNumber       = string.Empty;
                    string china             = string.Empty;
                    string item              = string.Empty;
                    string count             = string.Empty;
                    string weight            = string.Empty;
                    string moneyAmount       = string.Empty;
                    string fullAddressCn     = string.Empty;

                    for (int i = 0; i < packetInfos.Count; i++)
                    {
                        PacketInfo pi = packetInfos[i];
                        packTitle         += string.Format("'包裹单{0}'" + (i >= packetInfos.Count - 1 ? string.Empty : ","), i + 1);
                        pingzhangEmail    += "'*****@*****.**'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                        realkk            += "'realkk'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                        JHT               += "'JHT International GmbH'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                        OttoBrennerStr4a  += "'Otto Brenner Str.4a'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                        PLZ47877          += "'47877'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                        OrtWillich        += "'Willich'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                        TelNr021548839989 += "'02154 8839989'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                        recipientName     += string.Format("'{0}'" + (i >= packetInfos.Count - 1 ? string.Empty : ","), pi.RecipientNameEn);
                        address           += string.Format("'{0}'" + (i >= packetInfos.Count - 1 ? string.Empty : ","), pi.AddressEn);
                        postCode          += string.Format("'{0}'" + (i >= packetInfos.Count - 1 ? string.Empty : ","), pi.PostCode);
                        provinceCity      += string.Format("'{0}'" + (i >= packetInfos.Count - 1 ? string.Empty : ","), pi.ProvinceCityEn);
                        phoneNumber       += string.Format("'{0}'" + (i >= packetInfos.Count - 1 ? string.Empty : ","), pi.PhoneNumber);
                        china             += "'China'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                        item              += "'Milk powder'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                        count             += "'10'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                        weight            += string.Format("'{0}'" + (i >= packetInfos.Count - 1 ? string.Empty : ","), (pi.Weight / 1000).ToString("0"));
                        moneyAmount       += "'115.90'" + (i >= packetInfos.Count - 1 ? string.Empty : ",");
                        fullAddressCn     += string.Format("'{0}'" + (i >= packetInfos.Count - 1 ? string.Empty : ","), pi.FullAddress);
                    }

                    string endColumn = Excel.GetColumnIndex("C", packetInfos.Count - 1);
                    rainbowExcel.Insert("Sheet1", string.Format("C{0}:{1}{0}", 1, endColumn), packTitle);
                    rainbowExcel.Insert("Sheet1", string.Format("C{0}:{1}{0}", 2, endColumn), pingzhangEmail);
                    rainbowExcel.Insert("Sheet1", string.Format("C{0}:{1}{0}", 3, endColumn), realkk);
                    rainbowExcel.Insert("Sheet1", string.Format("C{0}:{1}{0}", 5, endColumn), JHT);
                    rainbowExcel.Insert("Sheet1", string.Format("C{0}:{1}{0}", 6, endColumn), OttoBrennerStr4a);
                    rainbowExcel.Insert("Sheet1", string.Format("C{0}:{1}{0}", 7, endColumn), PLZ47877);
                    rainbowExcel.Insert("Sheet1", string.Format("C{0}:{1}{0}", 8, endColumn), OrtWillich);
                    rainbowExcel.Insert("Sheet1", string.Format("C{0}:{1}{0}", 9, endColumn), TelNr021548839989);
                    rainbowExcel.Insert("Sheet1", string.Format("C{0}:{1}{0}", 10, endColumn), recipientName);
                    rainbowExcel.Insert("Sheet1", string.Format("C{0}:{1}{0}", 11, endColumn), address);
                    rainbowExcel.Insert("Sheet1", string.Format("C{0}:{1}{0}", 13, endColumn), postCode);
                    rainbowExcel.Insert("Sheet1", string.Format("C{0}:{1}{0}", 14, endColumn), provinceCity);
                    rainbowExcel.Insert("Sheet1", string.Format("C{0}:{1}{0}", 15, endColumn), phoneNumber);
                    rainbowExcel.Insert("Sheet1", string.Format("C{0}:{1}{0}", 16, endColumn), china);
                    rainbowExcel.Insert("Sheet1", string.Format("C{0}:{1}{0}", 17, endColumn), item);
                    rainbowExcel.Insert("Sheet1", string.Format("C{0}:{1}{0}", 18, endColumn), count);
                    rainbowExcel.Insert("Sheet1", string.Format("C{0}:{1}{0}", 19, endColumn), weight);
                    rainbowExcel.Insert("Sheet1", string.Format("C{0}:{1}{0}", 20, endColumn), moneyAmount);
                    rainbowExcel.Insert("Sheet1", string.Format("C{0}:{1}{0}", 21, endColumn), fullAddressCn);
                }
                finally
                {
                    rainbowExcel.Close();
                }

                return(destExcelFile);
            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    this,
                    "Error occured during generating files for rainbow:" + ex.ToString(),
                    this.Text,
                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return(string.Empty);
            }
        }
Beispiel #6
0
        private string GenerateSupermarketFiles(List <PacketInfo> packetInfos, string folder)
        {
            try
            {
                string destExcelFile = CreateOutputFile(
                    Directory.GetParent(Application.ExecutablePath).FullName, SUPERMARKET_TEMPLATE_FILENAME,
                    folder, SUPERMARKET_EXCEL_OUTPUT_FILENAME);
                #region error message
                if (string.IsNullOrEmpty(destExcelFile))
                {
                    MessageBox.Show(
                        this,
                        "Create excel file for supermarket failed.\nMaybe supermarket template file missed.\nMake sure the template file exists in the same folder with the executable file.",
                        this.Text,
                        MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return(string.Empty);
                }
                #endregion

                // Write data into excel.
                Excel supermarketExcel = new Excel(destExcelFile);

                try
                {
                    for (int i = 0; i < packetInfos.Count; i++)
                    {
                        PacketInfo pi = packetInfos[i];
                        if (!supermarketExcel.Insert("Sheet1", string.Empty, CreatePacketInfoSupermarketValues(i + 1, pi)))
                        {
                            #region error message
                            MessageBox.Show(
                                this,
                                "Error occured during write data into excel file for supermarket:" + pi.RecipientNameCn,
                                this.Text,
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            #endregion
                            return(string.Empty);
                        }
                    }
                }
                catch (Exception ex)
                {
                    #region error message
                    MessageBox.Show(
                        this,
                        "Error occured during write data into excel file for supermarket:" + ex.ToString(),
                        this.Text,
                        MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    #endregion
                    return(string.Empty);
                }
                finally
                {
                    supermarketExcel.Close();
                }

                return(destExcelFile);
            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    this,
                    "Error occured during generating files for supermarket:" + ex.ToString(),
                    this.Text,
                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return(string.Empty);
            }
        }
        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;
                    }
                    string          recipientNamePinyin = HanZiToPinYin.Convert(recipientNameCn);
                    PdfPacketInfoEx ppi = PdfPacketInfoEx.GetItem(recipientNamePinyin, _packetInfos, true);
                    if (null == ppi)
                    {
                        PdfPacketInfoEx ppi1 = new PdfPacketInfoEx(string.Empty, PacketTypes.Unknown, string.Empty, string.Empty, string.Empty, 0);
                        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;
            }
        }