Exemple #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;
            }
        }
Exemple #2
0
        private void btnExport_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;

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

                    foreach (NingboOrder o in NingboOrder.Orders)
                    {
                        for (int i = 0; i < o.SoldProducts.Count; i++)
                        {
                            //object[] args = new object[]{
                            //    "SAL06", "NBBLK", o.LogisticsCompany, o.TaobaoOrderId,
                            //    string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty,
                            //    "否",
                            //    string.Empty, string.Empty,
                            //    string.Empty,
                            //    o.RecipientName, o.Mobile,
                            //    string.Empty,
                            //    o.Province, o.City, o.District, o.StreetAddr,
                            //    o.SoldProducts[i].NingboId,
                            //    string.Empty, string.Empty,
                            //    o.SoldProducts[i].Count,
                            //    string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty,
                            //    "否",
                            //    string.Empty, string.Empty,
                            //    o.IdInfo,
                            //    string.Format("支付宝,{0}", o.AlipayNumber),
                            //    o.SoldProducts.Count > 1 ? string.Format("合并发货:{0}", o.RecipientName) : string.Empty,
                            //    string.Empty, string.Empty, string.Empty, string.Empty, string.Empty};
                            //excel.Insert("合作代发订单导入模板", string.Empty, args);

                            // 根据实际支付金额计算单价、运费.
                            Order taobaoOrder = MainForm.Instance.GetOrder(o.TaobaoOrderId);
                            System.Diagnostics.Trace.Assert(null != taobaoOrder);

                            // v20151228.
                            object[] args = new object[] {
                                "SAL06", "NBBLK", o.LogisticsCompany, o.TaobaoOrderId,
                                string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty,
                                "否",
                                string.Empty,                             // 运费
                                string.Empty,
                                o.RecipientName,                          // 客户
                                o.RecipientName, o.Mobile,
                                string.Empty,                             // 邮编
                                o.Province, o.City, o.District, o.StreetAddr,
                                o.SoldProducts[i].NingboId,
                                string.Empty, string.Empty,
                                o.SoldProducts[i].Count,
                                "盒",                             //单位
                                "0.00",                          //单价
                                "00.00",                         // 总价
                                string.Empty, string.Empty, string.Empty,
                                "否",
                                string.Empty, string.Empty,
                                o.IdInfo,
                                string.Empty,                            // string.Format("支付宝,{0}", o.AlipayNumber),
                                o.SoldProducts.Count > 1 ? string.Format("合并发货:{0}", o.RecipientName) : string.Empty,
                                string.Empty, string.Empty, string.Empty,
                                "支付宝",                             // 支付方式
                                o.AlipayNumber,                    // 支付流水号
                                taobaoOrder.TotalMoney.ToString("0.00")
                            };                                     // 支付金额

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

                    excel.Close();

                    DialogResult dr = MessageBox.Show(this, "导出数据成功.\n确认数据无误后点击Yes同步订单状态至服务器, 否则点击No退出.", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                    if (DialogResult.Yes == dr)
                    {
                        UpdateStatusToServer(NingboOrder.Orders);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, this.Text, MessageBoxButtons.OK);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
Exemple #3
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;
            }
        }
Exemple #4
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);
        }
Exemple #5
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);
            }
        }
Exemple #6
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);
            }
        }
Exemple #7
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);
            }
        }