Exemple #1
0
        private void export(string synseq, string linenum, string lineno)//lineno打码机编号  linenum区分特异型烟和烟仓
        {
            this.btn_export.Enabled = false;
            panel2.Visible          = true;
            label2.Visible          = true;
            progressBar1.Visible    = true;
            label2.Text             = "数据查询中,准备进行数据导出...";
            label2.Refresh();
            int    taskseq = 0, seq = 1;
            String tasknum = "", cuscode = "", cusname = "", itemno = "", itemname = "", quantity = "", regioncode = "", regionname = "", orderdate = "", cuscodetmp = "";

            //根据类型给打码机编号赋值
            if (linenum == "1")
            {
                lineno = "ZY1002";
            }
            else
            {
                lineno = "ZY1001";
            }

            //取数据
            var result              = sc.Get1stPrjInfo(Convert.ToDecimal(synseq), linenum);
            List <_1stPrjInfo> list = result.Content.ToList();

            if (list.Any())
            {
                //取一号工程批次号
                Business.DZEntities en = new Business.DZEntities();
                String batchcodesql    = "select S_PRODUCE_1STPRJINFO.Nextval from dual";
                string batchcode       = en.ExecuteStoreQuery <decimal>(batchcodesql, null).FirstOrDefault().ToString();

                //创建通讯链接
                InitSocket();
                //创建到处目录
                String folder = "HighSpeedExportData";
                if (!Directory.Exists("D:\\" + folder))
                {
                    Directory.CreateDirectory("D:\\" + folder);
                }
                int    len = list.Count;
                int    count = 0, fileSeq = 1, rowCcount = 0, bz = 0, succCount = 0;
                String fileNameStr = ""; String info = "", tmpInfo = "", tempCode = "", unSuccFile = "";
                //foreach (_1stPrjInfo info in list)
                for (int i = 0; i < len; i++)
                {
                    progressBar1.Value = ((i + 1) * 100 / len);
                    progressBar1.Refresh();

                    _1stPrjInfo prjInfo = list[i];
                    tasknum    = prjInfo.sortNum.ToString();
                    cuscode    = prjInfo.custCode;
                    cusname    = prjInfo.custName;
                    itemno     = prjInfo.cigCode;
                    itemname   = prjInfo.cigName;
                    quantity   = prjInfo.quantity.ToString();
                    regioncode = prjInfo.regionCode;
                    regionname = prjInfo.regionName;
                    orderdate  = prjInfo.orderDate;
                    //lineno = row["SORTNAME"].ToString();
                    //lineno = "1";
                    taskseq++;
                    rowCcount = rowCcount + 1;

                    label2.Text = "正在导出第" + fileSeq + "个文件...";
                    label2.Refresh();
                    //取下条记录比较车组与零售户
                    if (i + 1 < len)
                    {
                        prjInfo    = list[i + 1];
                        cuscodetmp = prjInfo.custCode;
                        tempCode   = prjInfo.regionCode;
                    }
                    else
                    {
                        cuscodetmp = "";
                        tempCode   = "";
                    }
                    //infostr[i] = tasknum + taskseq + "," + tasknum + "," + cuscode + "," + cusname + "," + itemno + "," + itemname + "," + quantity + ",2," + seq + "," + regioncode + "," + regioncode + "," + orderdate + "," + orderdate + ",S1001,1";
                    tmpInfo = tmpInfo + tasknum + "," + tasknum + "," + cuscode + "," + cusname + "," + itemno + "," + itemname + "," + quantity + "," + batchcode + "," + seq + "," + regioncode + "," + regionname + "," + orderdate + "," + orderdate + "," + lineno + ",1;\r\n";
                    if (cuscode != cuscodetmp)
                    {
                        taskseq = 0;
                        seq++;
                    }

                    if (!tempCode.Equals(regioncode))
                    {
                        //判断累计记录数是否大于10000,大于则将之前的记录数导出,否则将记录数合并
                        if (rowCcount + count > 1000000000)
                        {
                            label2.Text = "正在压缩第" + fileSeq + "个文件...";
                            label2.Refresh();
                            //将之前的记录信息导出
                            DateTime dt       = DateTime.Now;
                            String   time     = string.Format("{0:yyyyMMddHHmmssfff}", dt);
                            String   filename = "RetailerOrder-" + time + "-" + synseq + "-" + linenum + "-" + fileSeq;
                            fileNameStr = fileNameStr + "," + filename + ".zip";
                            StreamWriter sw = new StreamWriter("D:\\HighSpeedExportData\\" + filename + ".Order", false, Encoding.UTF8);
                            sw.WriteLine(info.Substring(0, info.Length - 1));
                            sw.Close();//写入
                            //CompressFile("D:\\" + filename + ".Order");
                            GetFileToZip("D:\\HighSpeedExportData\\" + filename + ".Order", "D:\\HighSpeedExportData\\" + filename + ".zip", filename + ".Order");
                            //发送数据
                            label2.Text = "正在发送第" + fileSeq + "个文件";
                            label2.Refresh();
                            bz = sendFile("D:\\HighSpeedExportData\\" + filename + ".zip");
                            //记录发送成功数量和失败文件信息
                            if (bz == 0)
                            {
                                succCount   = succCount + 1;
                                label2.Text = "第" + fileSeq + "个文件发送完毕!";
                            }
                            else
                            {
                                unSuccFile  = unSuccFile + "," + filename + ".zip";
                                label2.Text = "第" + fileSeq + "个文件发送失败!";
                            }

                            label2.Refresh();
                            //记录新车组的信息
                            fileSeq = fileSeq + 1;
                            count   = rowCcount;
                            info    = tmpInfo;
                        }
                        else
                        {
                            count = rowCcount + count;
                            info  = info + tmpInfo;
                        }

                        //判断循环是否完成(是否为最后一条记录),如果是最后一条,则将剩余记录导出
                        if ("".Equals(tempCode))
                        {
                            //fileSeq = fileSeq + 1;
                            label2.Text = "正在压缩第" + fileSeq + "个文件";
                            label2.Refresh();
                            DateTime dt       = DateTime.Now;
                            String   time     = string.Format("{0:yyyyMMddHHmmssfff}", dt);
                            String   filename = "RetailerOrder-" + time + "-" + synseq + "-" + linenum + "-" + fileSeq;
                            fileNameStr = fileNameStr + "," + filename + ".zip";
                            StreamWriter sw = new StreamWriter("D:\\HighSpeedExportData\\" + filename + ".Order", false, Encoding.UTF8);
                            sw.WriteLine(info.Substring(0, info.Length - 1));
                            sw.Close();//写入
                            //CompressFile("D:\\" + filename + ".Order");
                            GetFileToZip("D:\\HighSpeedExportData\\" + filename + ".Order", "D:\\HighSpeedExportData\\" + filename + ".zip", filename + ".Order");
                            //发送数据
                            //sendFile("D:\\HighSpeedExportData\\" + filename + ".zip");
                            label2.Text = "正在发送第" + fileSeq + "个文件";
                            label2.Refresh();
                            bz = sendFile("D:\\HighSpeedExportData\\" + filename + ".zip");
                            //记录发送成功数量和失败文件信息
                            if (bz == 0)
                            {
                                succCount   = succCount + 1;
                                label2.Text = "第" + fileSeq + "个文件发送完毕!";
                            }
                            else
                            {
                                unSuccFile  = unSuccFile + "," + filename + ".zip";
                                label2.Text = "第" + fileSeq + "个文件发送失败!";
                            }

                            label2.Refresh();
                        }
                        tmpInfo   = "";
                        rowCcount = 0;
                    }
                }
                //在弹窗前关闭控件
                panel2.Visible       = false;
                label2.Visible       = false;
                progressBar1.Visible = false;

                String msg = "成功导出" + fileSeq + "个文件,成功发送" + succCount + "个文件!";
                //导出的文件的所有文件名
                if (!"".Equals(fileNameStr))
                {
                    fileNameStr = fileNameStr.Substring(1);
                }
                //发送失败的所有文件名
                if (!"".Equals(unSuccFile))
                {
                    unSuccFile = unSuccFile.Substring(1);
                    msg        = msg + "其中发送失败文件为(" + unSuccFile + ")!";
                }
                else
                {
                    msg = msg + "文件名为(" + fileNameStr + ")!";
                }

                MessageBox.Show(msg, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);


                socketClient.Disconnect(false);
                socketClient.Close();
            }
            this.btn_export.Enabled = true;
        }