コード例 #1
0
        /// <summary>
        /// 输出csv文件
        /// </summary>
        /// <param name="allmts"></param>
        /// <param name="timemtMap"></param>
        /// <param name="filename"></param>
        /// <returns></returns>
        public ActionResult DownLoadCsvRunData(IList <string> allmts, IDictionary <string, IDictionary <string, string> > timemtMap, string filename)
        {
            CsvStreamWriter scvWriter = new CsvStreamWriter();

            //输入出到csv文件中的数据列表
            IList <string> dataList = new List <string>();

            //设置抬头行
            dataList.Add("                        " + filename + "                       ");
            //循环设置数据行
            //设置标题行
            allmts.Insert(0, Resources.SunResource.REPORT_TIME);
            dataList.Add(scvWriter.ConvertToSaveLine(allmts));
            //数据行临时list
            IList <string> tempList = new List <string>();

            foreach (string key in timemtMap.Keys)
            {
                dataList.Add(scvWriter.ConvertToSaveCell(key) + "," + scvWriter.ConvertToSaveLine(timemtMap[key].Values));
            }

            scvWriter.AddStrDataList(dataList);
            scvWriter.Save(Server.MapPath("/") + "tempexportfile/" + filename + ".csv");
            return(File(Server.MapPath("/") + "tempexportfile/" + filename + ".csv", "text/csv; charset=UTF-8", urlcode(filename) + ".csv"));
        }
コード例 #2
0
ファイル: DanDanForm.cs プロジェクト: bluntnet/bookAssistant
        private void button6_Click(object sender, EventArgs e)
        {
            //mydt

            foreach (DataRow dr1 in mydt.Rows)
            {
                foreach (DataRow dr2 in rewriteDT.Rows)
                {
                    if (dr1[0].ToString() == dr2[0].ToString())
                    {
                        dr1[40] = dr2[1];
                        dr1[7]  = dr2[2];
                    }
                }
            }

            if (saveCsvFile.ShowDialog() == DialogResult.OK)
            {
                saveCsvFile.Filter = "csv file(*.csv)|*.csv";
                string filename = saveCsvFile.FileName;
                //int[] quoteMark ={ 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1 };
                CsvStreamWriter csw = new CsvStreamWriter(filename, System.Text.Encoding.Unicode);
                csw.QuoteMark(TBCSV.getQuoteMark());
                csw.AddData(mydt, 1);
                //csw.FirstRowQuote = 1;
                csw.Save();
            }
            else
            {
                MessageBox.Show("没保存");
            }
            MessageBox.Show("共生成" + (mydt.Rows.Count - 1) + "条数据");
        }
コード例 #3
0
ファイル: DanDanForm.cs プロジェクト: bluntnet/bookAssistant
        private void button9_Click(object sender, EventArgs e)
        {
            foreach (DataRow dr1 in mydt.Rows)
            {
                // logger.AppendText("==>"+dr1[24].ToString());
                string price = getPriceFromDesc(dr1[24].ToString());
                //logger.AppendText("price==>"+price);
                if (price != "0")
                {
                    dr1[7] = price;
                }
                //logger.AppendText(
            }

            if (saveCsvFile.ShowDialog() == DialogResult.OK)
            {
                saveCsvFile.Filter = "csv file(*.csv)|*.csv";
                string filename = saveCsvFile.FileName;
                //int[] quoteMark ={ 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1 };
                CsvStreamWriter csw = new CsvStreamWriter(filename, System.Text.Encoding.Unicode);
                csw.QuoteMark(TBCSV.getQuoteMark());
                csw.AddData(mydt, 1);
                //csw.FirstRowQuote = 1;
                csw.Save();
            }
            else
            {
                MessageBox.Show("没保存");
            }
            MessageBox.Show("共生成" + (mydt.Rows.Count - 1) + "条数据");
        }
コード例 #4
0
        /// <summary>
        /// 导出csv格式的图表数据
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="serieNo"></param>
        /// <returns></returns>
        public ActionResult ExportCsvChart(string filename, string serieNo)
        {
            CsvStreamWriter scvWriter  = new CsvStreamWriter();
            ChartData       chartData  = TempDataUtil.getChartData(serieNo);
            string          reportname = string.Empty;

            if (chartData != null)
            {
                reportname = (filename.Equals("chart") ? "" : filename) + chartData.name.Replace("/", "").Replace(" ", "");
                IList <string> dataList = new List <string>();
                string         xname    = Resources.SunResource.CUSTOMREPORT_CHART_TIME;
                if (chartData.names.Length > 0 && !string.IsNullOrEmpty(chartData.names[0]))
                {
                    xname = chartData.names[0] + "[" + chartData.units[0] + "]";
                }
                dataList.Add(xname);
                dataList.Add(convertArrtoStr(chartData.categories));
                foreach (YData ydata in chartData.series)
                {
                    dataList.Add(ydata.name);
                    dataList.Add(convertArrtoStr(ydata.data));
                }
                scvWriter.AddStrDataList(dataList);
            }
            string fullFile = Server.MapPath("/") + "tempexportfile\\" + serieNo + ".csv";

            scvWriter.Save(fullFile);
            //转化为csv格式的字符串
            ActionResult tmp = File(fullFile, "text/csv; charset=UTF-8", urlcode(reportname) + ".csv");

            return(tmp);
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: iBiodiversity/PhotoGPS
        public static void SaveToCSV(DataTable dt, string fileName = "GeoInfos.csv")
        {
            CsvStreamWriter csv = new CsvStreamWriter();

            csv.AddData(dt);
            csv.Save(System.Environment.CurrentDirectory + @"\" + fileName, Encoding.UTF8);
        }
コード例 #6
0
ファイル: UnitController.cs プロジェクト: codingsf/loosoft
        public ActionResult Units_Output(int id)
        {
            Plant             plant      = FindPlant(id);
            IList <PlantUnit> plantUnits = PlantUnitService.GetInstance().GetAllPlantUnitsByPlantId(id);
            CsvStreamWriter   writer     = new CsvStreamWriter();
            IList <string>    listData   = new List <string>();

            listData.Add(string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},", Resources.SunResource.PLANT_UNIT_LIST_STATUS, Resources.SunResource.PLANT_UNIT_DATA_SOURCE_CODE
                                       , Resources.SunResource.PLANT_UNIT_LIST_UNIT_NAME,
                                       Resources.SunResource.PLANT_UNIT_LIST_POWER + "(kW)",
                                       Resources.SunResource.PLANT_UNIT_LIST_YEAR_ENERGY + "(kWh)",
                                       Resources.SunResource.PLANT_UNIT_LIST_ENERGY + "(kWh)",
                                       Resources.SunResource.PLANT_UNIT_LIST_MONTH_ENERGY + "(kWh)",
                                       Resources.SunResource.PLANT_UNIT_LIST_MONTH_ENERGY_KWP + "(kWh/kWp)",
                                       Resources.SunResource.PLANT_UNIT_LIST_YEAR_ENERGY_KWP + "(kWh/kWp)"
                                       ));

            CollectorMonthDayData cmData = null;
            CollectorYearData     cyData = null;

            foreach (PlantUnit unit in plantUnits)
            {
                float currentMonthEnergy = 0;
                float currentYearEnergy  = 0;
                cmData             = CollectorMonthDayDataService.GetInstance().GetCollectorMonthDayData(DateTime.Now.Year, unit.collector.id, DateTime.Now.Month);
                currentMonthEnergy = cmData == null ? 0 : cmData.count();
                cyData             = CollectorYearDataService.GetInstance().GetCollectorYearData(unit.collector.id, DateTime.Now.Year);
                currentYearEnergy  = cyData == null ? 0 : cyData.dataValue;
                listData.Add(string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},", unit.isWork(plant.timezone) ? Resources.SunResource.MONITORITEM_WORKING : Resources.SunResource.MONITORITEM_STOPPED, string.Format("\t{0}", unit.collector.code)
                                           , string.Format("\t{0}", unit.displayname),
                                           unit.TodayPower(plant.timezone).ToString(),
                                           currentYearEnergy.ToString(),
                                           unit.displayTotalEnergy.ToString(),
                                           currentMonthEnergy.ToString(),
                                           Math.Round(currentMonthEnergy / unit.chartPower, 2).Equals(double.NaN) ? "0" : Math.Round(currentMonthEnergy / unit.chartPower, 2).ToString(),
                                           Math.Round(currentYearEnergy / unit.chartPower, 2).Equals(double.NaN) ? "0" : Math.Round(currentYearEnergy / unit.chartPower, 2).ToString()
                                           ));
            }

            writer.AddStrDataList(listData);


            string fullFile = Server.MapPath("/") + "tempexportfile\\" + Resources.SunResource.PLANT_UNIT_LIST_FILENAME + ".csv";

            writer.Save(fullFile);
            //转化为csv格式的字符串
            ActionResult tmp = File(fullFile, "text/csv; charset=UTF-8", urlcode(Resources.SunResource.PLANT_UNIT_LIST_FILENAME) + ".csv");

            return(tmp);
        }
コード例 #7
0
 public void Export(DataTable dt, string fpath)
 {
     try
     {
         CsvStreamWriter csv = new CsvStreamWriter();
         csv.AddData(dt, 1);
         csv.Save(fpath);
     }
     catch (System.Exception ex)
     {
         logger.Error(ex.Message);
         throw new System.Exception("保存文件失败", ex);
     }
 }
コード例 #8
0
ファイル: DanDanForm.cs プロジェクト: bluntnet/bookAssistant
        private void button5_Click_1(object sender, EventArgs e)
        {
            //mydt
            if (mydt == null || mydt.Rows.Count == 0)
            {
                MessageBox.Show("请先导入基础csv数据文件!");
                return;
            }
            DataTable exportDT = new DataTable();

            foreach (string head in taobaoCSVHead)
            {
                exportDT.Columns.Add(head);
            }
            DataRow drHead = exportDT.NewRow();

            for (int i = 0; i < taobaoCSVHead.Length; i++)
            {
                drHead[i] = taobaoCSVHead[i];
            }
            exportDT.Rows.Add(drHead);
            for (int i = 0; i < mydt.Rows.Count; i++)
            {
                DataRow dr = exportDT.NewRow();
                for (int j = 0; j < taobaoCSVHead.Length; j++)
                {
                    //mydt.Rows[i][0].ToString();
                    dr[j] = taobaoCSVDefault[j];
                    Debug.WriteLine("dr[" + j + "]===" + dr[j]);
                }
                dr[0]  = mydt.Rows[i][0].ToString();
                dr[40] = mydt.Rows[i][1].ToString();
                exportDT.Rows.Add(dr);
                //Debug.WriteLine("dr[0]+dr[40]" + dr[0] + dr[40]);
            }
            Debug.WriteLine("exportDT.Rows.Count==" + exportDT.Rows.Count);
            if (saveCsvFile.ShowDialog() == DialogResult.OK)
            {
                string filename = saveCsvFile.FileName;
                //int[] quoteMark ={ 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1 };
                CsvStreamWriter csw = new CsvStreamWriter(filename, System.Text.Encoding.Unicode);
                csw.QuoteMark(TBCSV.getQuoteMark());
                csw.AddData(exportDT, 1);
                //csw.FirstRowQuote = 1;
                csw.Save();
            }
        }
コード例 #9
0
ファイル: DanDanForm.cs プロジェクト: bluntnet/bookAssistant
        private void button3_Click(object sender, EventArgs e)
        {
            if (mydt == null || mydt.Rows.Count == 0)
            {
                MessageBox.Show("请先导入需要抓取的内容");
                return;
            }
            DataTable tempDt = mydt.Clone();

            for (int i = 0; i < mydt.Rows.Count; i++)
            {
                DataRow dr = mydt.Rows[i];
                if (dr[24].ToString() == "" || i == 0)
                {
                    tempDt.ImportRow(mydt.Rows[i]);
                }
            }

            //MessageBox.Show(tempDt.Columns.Count+"=="+mydt.Rows[3].ItemArray.Length);

            if (saveCsvFile.ShowDialog() == DialogResult.OK)
            {
                //saveCsvFile.Filter = "csv file|*.csv";
                string filename = saveCsvFile.FileName;

                /*string[] taobaoCSVHead ={ "宝贝名称", "宝贝类目", "店铺类目", "新旧程度", "省", "城市", "出售方式", "宝贝价格", "加价幅度", "宝贝数量",
                 *  "有效期", "运费承担", "平邮", "EMS", "快递", "付款方式","支付宝", "发票", "保修", "自动重发",
                 *  "放入仓库", "橱窗推荐", "开始时间", "心情故事", "宝贝描述","宝贝图片","宝贝属性","团购价","最小团购件数",
                 *  "邮费模版ID","会员打折","修改时间","上传状态","图片状态","返点比例","新图片","视频","销售属性组合","用户输入ID串",
                 *  "用户输入名-值对","商家编码","销售属性别名","宝贝编号"};
                 * // int[] quoteMark ={ 1, 0, 1, 0, 1, 1, 1, 0, 0, 0,
                 *                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                 *                 0, 0, 1, 1, 1, 0, 0, 1, 0, 0,
                 *                 1, 1, 1, 1, 1,1,1,1,1,1,
                 *                 1,1,1,1};
                 */
                CsvStreamWriter csw = new CsvStreamWriter(filename, System.Text.Encoding.Unicode);
                csw.QuoteMark(TBCSV.getQuoteMark());
                csw.AddData(tempDt, 1);
                csw.Save();
                MessageBox.Show("保存成功,生成" + (tempDt.Rows.Count - 1) + "条数据");
            }
            else
            {
                MessageBox.Show("没保存");
            }
        }
コード例 #10
0
ファイル: DanDanForm.cs プロジェクト: bluntnet/bookAssistant
        private void button2_Click(object sender, EventArgs e)
        {
            if (mydt == null || mydt.Rows.Count == 0)
            {
                MessageBox.Show("请先导入需要抓取的内容");
                return;
            }
            DataTable tempDt = mydt.Clone();

            for (int i = 0; i < mydt.Rows.Count; i++)
            {
                DataRow dr = mydt.Rows[i];

                if (dr[24].ToString() != "")
                {
                    tempDt.ImportRow(mydt.Rows[i]);
                }
            }
            //MessageBox.Show(tempDt.Columns.Count+"=="+mydt.Rows[3].ItemArray.Length);


            if (saveCsvFile.ShowDialog() == DialogResult.OK)
            {
                //saveCsvFile.Filter = "csv file|*.csv";
                string filename = saveCsvFile.FileName;
                //int[] quoteMark ={ 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1 };


                CsvStreamWriter csw = new CsvStreamWriter(filename, System.Text.Encoding.Unicode);
                //csw.QuoteMark(quoteMark);
                csw.AddData(tempDt, 1);
                csw.Save();
                MessageBox.Show("保存成功,生成" + (tempDt.Rows.Count - 1) + "条数据");
            }
            else
            {
                MessageBox.Show("没保存");
            }
        }
コード例 #11
0
ファイル: DanDanForm.cs プロジェクト: bluntnet/bookAssistant
        private void button10_Click(object sender, EventArgs e)
        {
            //DataTable dt = new DataTable();
            //DataTable newDt = new DataTable();
            List <String> fileNameList = new List <String>();

            for (int i = 0; i < mydt.Rows.Count; i++)
            {
                DataRow dr1      = mydt.Rows[i];
                string  fileName = (String)dr1[0];

                if (fileNameList.Contains(fileName.Trim()))
                {
                    dr1.Delete();
                    i--;
                }
                else
                {
                    fileNameList.Add(fileName.Trim());
                }
            }

            if (saveCsvFile.ShowDialog() == DialogResult.OK)
            {
                saveCsvFile.Filter = "csv file(*.csv)|*.csv";
                string filename = saveCsvFile.FileName;
                //int[] quoteMark ={ 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1 };
                CsvStreamWriter csw = new CsvStreamWriter(filename, System.Text.Encoding.Unicode);
                csw.QuoteMark(TBCSV.getQuoteMark());
                csw.AddData(mydt, 1);
                //csw.FirstRowQuote = 1;
                csw.Save();
            }
            else
            {
                MessageBox.Show("没保存");
            }
            MessageBox.Show("共生成" + (mydt.Rows.Count) + "条数据");
        }
コード例 #12
0
        private void downloadTask()
        {
            //Console.Write(webBrowser1.DocumentText);

            //string htmlString = webBrowser1.DocumentText;

            string htmlString = wbHtml;
            string formString = "";
            string formStart  = "<form method=\"POST\" action=\"searchfull.asp?plu_title=";

            if (htmlString.IndexOf(formStart) == -1)
            {
                logger("没有找到Form起点!");
                return;
            }
            formString = htmlString.Substring(htmlString.IndexOf(formStart));
            if (formString.IndexOf("</form>") == -1)
            {
                logger("没有找到Form终点!");
                return;
            }
            formString = formString.Substring(0, formString.IndexOf("</form>"));
            Console.WriteLine("formString========" + formString);
            string searchString    = "";
            string totalPageString = "";

            if (formString.IndexOf("共") == -1)
            {
                logger("没有找到总页数!");
                return;
            }
            totalPageString = formString.Substring(formString.IndexOf("共") + 1);
            if (formString.IndexOf("页") == -1)
            {
                logger("没有找到总页数!");
                return;
            }
            totalPageString = totalPageString.Substring(0, totalPageString.IndexOf("页")).Trim();
            loggerLine("共 " + totalPageString + "页 ");
            int totalPage = Convert.ToInt32(totalPageString);

            Console.WriteLine("totalPage====" + totalPage);
            if (formString.IndexOf("searchfull.asp") == -1)
            {
                logger("关键字没找到");
                return;
            }
            searchString = formString.Substring(formString.IndexOf("searchfull.asp"));
            if (formString.IndexOf(QUERY_SEPARATE + "page=") == -1)
            {
                logger("关键字没找到!");
                return;
            }
            searchString = searchString.Substring(0, searchString.IndexOf(QUERY_SEPARATE + "page="));
            Console.WriteLine("searchString====" + searchString);
            string orderString = "";

            if (formString.IndexOf("order=") == -1)
            {
                logger("Order没有找到!");
                return;
            }
            orderString = formString.Substring(formString.IndexOf("order=") + 6);
            if (formString.IndexOf("\">") == -1)
            {
                logger("关键字没找到!");
                return;
            }
            orderString = orderString.Substring(0, orderString.IndexOf("\">"));

            Console.WriteLine("orderString====" + orderString);

            string        pageHtml = "";
            List <string> urlList  = new List <string>();

            int[]  pageArray  = new int[] { 1, totalPage };
            string pageNumber = pageRange.Text;

            if (pageNumber != "")
            {
                string[] tempArray = pageNumber.Split('-');
                if (tempArray.Length == 1)
                {
                    pageArray[0] = Convert.ToInt32(tempArray[0]);
                    pageArray[1] = Convert.ToInt32(tempArray[0]);
                }
                else
                {
                    pageArray[0] = Convert.ToInt32(tempArray[0]);
                    pageArray[1] = Convert.ToInt32(tempArray[1]);
                }
            }
            for (int i = Math.Max(pageArray[0], 1); i <= Math.Min(pageArray[1], totalPage); i++)
            {
                logger("查找第" + i + "页的图书...");
                pageHtml = getPageContent(searchString, i, orderString);
                string detailPage = "href=\"views.asp";

                while (pageHtml.IndexOf(detailPage) != -1)
                {
                    pageHtml = pageHtml.Substring(pageHtml.IndexOf(detailPage) + detailPage.Length);
                    string url = pageHtml.Substring(0, pageHtml.IndexOf("\" target="));
                    urlList.Add(webViewUrl + url);
                }


                loggerLine("完成!");
            }


            /////////////
            TBCSV     csv  = new TBCSV();
            DataTable mydt = csv.getDefaultDataTable();


            string[] values = TBCSV.getTaobaoDefaultValue();

            // WebUtil client = new WebUtil();
            string htmlTemp = "";
            int    m        = 1;

            foreach (string urlstring in urlList)
            {
                logger(urlstring + "第[" + m + "]本书..");
                try {
                    htmlTemp = HttpRequestUtil.requestURL(urlstring, "utf-8");
                    if (htmlTemp == null || htmlTemp == "")
                    {
                        logger("出错,请手动下载!!");
                        continue;
                    }
                    m++;
                    DataRow dr = mydt.NewRow();
                    for (int j = 0; j < values.Length; j++)
                    {
                        dr[j] = values[j];
                    }
                    string bookName = getBookNameFromHtml(htmlTemp);//书名
                    dr["title"] = bookName;
                    //logger(dr[0]+">>");
                    //Console.WriteLine("name==" + dr[0]);

                    dr["price"] = getBookPriceFromHtml(htmlTemp);

                    string author = getAuthorFromHtml(htmlTemp);
                    //Console.WriteLine("price==" + dr[7]);
                    string ISBN = getBookISBNFromHtml(htmlTemp);
                    dr["outer_id"] = ISBN;                           //商家编吗isbn
                    string publishHouse = getPublishHouse(htmlTemp); //出版社
                    //下面两行的赋值顺序不能改动
                    //dr["inputPids"] = "1636953,2043183,2043189,122216620";
                    dr["inputPids"]   = "1636953,2043183,2043189,122216620";
                    dr["inputValues"] = ISBN.Replace("-", "") + "," + bookName + "," + author + "," + publishHouse;

                    //dr["inputValues"] = ISBN.Replace("-", "");

                    string desc         = getBookInfo(htmlTemp); //描述
                    string bookNameHtml = "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\" bgcolor=\"#ccccff\">\r\n<tr bgcolor=#ccccff>\r\n<td>" + bookName + "</td></tr></table>";
                    dr["description"] = bookNameHtml + desc;     //描述

                    //Console.WriteLine("isbn==" + dr[40]);
                    string bookImage = getBookImageFromHtml(htmlTemp);
                    if (bookImage != "")
                    {
                        bookImage = bookImage.Substring(0, bookImage.Length - 4) + ":1:0:|;";
                        logger("图片下载成功...");
                    }
                    else
                    {
                        logger("图片下载失败...");
                    }
                    dr["picture_status"] = "1;";
                    dr["picture"]        = bookImage;
                    mydt.Rows.Add(dr);
                } catch (Exception e) {
                    loggerLine(e.ToString());
                }
                loggerLine("下载完成!");
            }

            CsvStreamWriter csw = new CsvStreamWriter(CsvFileName, System.Text.Encoding.Unicode);

            csw.QuoteMark(TBCSV.getQuoteMark());
            csw.AddData(mydt, 1);
            csw.FirstRowQuote = 2;
            csw.Save();
            MessageBox.Show("保存成功,生成" + (mydt.Rows.Count - 1) + "条数据");
            button3.Enabled = true;
        }
コード例 #13
0
ファイル: DanDanForm.cs プロジェクト: bluntnet/bookAssistant
        private void button4_Click(object sender, EventArgs e)
        {
            if (mydt == null || mydt.Rows.Count == 0)
            {
                MessageBox.Show("请先导入基础csv数据文件!");
                return;
            }
            if (duplicateDt == null || duplicateDt.Rows.Count == 0)
            {
                MessageBox.Show("请导入需要去除的重复的csv文件!");
            }

            DataTable tempDt = duplicateDt.Clone();

            for (int i = 0; i < duplicateDt.Rows.Count; i++)
            {
                DataRow dr = duplicateDt.Rows[i];

                if (chkName.Checked && chkPrice.Checked)
                {
                    DataColumn[] dc = new DataColumn[] { mydt.Columns[0], mydt.Columns[7] };
                    mydt.PrimaryKey = dc;
                    if (!isSameRecord(mydt, new Object[] { dr[0].ToString(), dr[1].ToString() }))
                    {
                        tempDt.ImportRow(dr);
                    }
                }
                else if (chkName.Checked)
                {
                    //mydt
                    mydt.PrimaryKey = new DataColumn[1] {
                        mydt.Columns[0]
                    };
                    if (!isSameRecord(mydt, new Object[] { dr[0].ToString() }))
                    {
                        tempDt.ImportRow(dr);
                    }
                }
                else if (chkPrice.Checked)
                {
                    mydt.PrimaryKey = new DataColumn[1] {
                        mydt.Columns[7]
                    };
                    if (!isSameRecord(mydt, new Object[] { dr[7].ToString() }))
                    {
                        tempDt.ImportRow(dr);
                    }
                }
            }

            //MessageBox.Show(tempDt.Columns.Count+"=="+mydt.Rows[3].ItemArray.Length);

            if (saveCsvFile.ShowDialog() == DialogResult.OK)
            {
                //saveCsvFile.Filter = "csv file|*.csv";
                string filename = saveCsvFile.FileName;
                // int[] quoteMark ={ 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1 };
                CsvStreamWriter csw = new CsvStreamWriter(filename, System.Text.Encoding.Unicode);
                csw.QuoteMark(TBCSV.getQuoteMark());
                csw.AddData(tempDt, 1);
                csw.FirstRowQuote = 2;
                csw.Save();
            }
            else
            {
                MessageBox.Show("没保存");
            }
            MessageBox.Show("共生成" + (tempDt.Rows.Count - 1) + "条数据");
        }
コード例 #14
0
ファイル: DanDanForm.cs プロジェクト: bluntnet/bookAssistant
        private void button8_Click(object sender, EventArgs e)
        {
            try
            {
                if (mydt == null || mydt.Rows.Count == 0)
                {
                    MessageBox.Show("请先导入基础csv数据文件!");
                    return;
                }
                if (duplicateDt == null || duplicateDt.Rows.Count == 0)
                {
                    MessageBox.Show("请导入需要去除的重复的csv文件!");
                }

                DataTable tempDt = duplicateDt.Clone();

                //DataTable exportDT = new DataTable();

                /*
                 * foreach (string head in taobaoCSVHead)
                 * {
                 *  tempDt.Columns.Add(head);
                 * }
                 */
                DataRow drHead = tempDt.NewRow();


                for (int i = 0; i < duplicateDt.Columns.Count; i++)
                {
                    DataRow dr = duplicateDt.Rows[0];
                    drHead[i] = dr[i];
                }
                tempDt.Rows.Add(drHead);
                //tempDt.Rows.Add(
                for (int i = 0; i < duplicateDt.Rows.Count; i++)
                {
                    DataRow dr = duplicateDt.Rows[i];

                    if (chkName.Checked && chkPrice.Checked)
                    {
                        DataColumn[] dc = new DataColumn[] { mydt.Columns[0], mydt.Columns[7] };
                        mydt.PrimaryKey = dc;
                        if (!isSameRecord(mydt, new Object[] { dr[0].ToString(), dr[1].ToString() }))
                        {
                            tempDt.ImportRow(dr);
                        }
                    }
                    else if (chkName.Checked)
                    {
                        //mydt

                        bool isFind = false;
                        foreach (DataRow mydr in mydt.Rows)
                        {
                            if (dr[0].ToString() == mydr[0].ToString())
                            {
                                isFind = true;
                                break;
                            }
                        }
                        if (!isFind)
                        {
                            tempDt.ImportRow(dr);
                        }

                        /*
                         * mydt.PrimaryKey = new DataColumn[1] { mydt.Columns[0] };
                         * if (!isSameRecord(mydt, new Object[] { dr[0].ToString() }))
                         * {
                         *  tempDt.ImportRow(dr);
                         * }
                         */
                    }
                    else if (chkPrice.Checked)
                    {
                        mydt.PrimaryKey = new DataColumn[1] {
                            mydt.Columns[7]
                        };
                        if (!isSameRecord(mydt, new Object[] { dr[7].ToString() }))
                        {
                            tempDt.ImportRow(dr);
                        }
                    }
                }


                //MessageBox.Show(tempDt.Columns.Count+"=="+mydt.Rows[3].ItemArray.Length);

                if (saveCsvFile.ShowDialog() == DialogResult.OK)
                {
                    //saveCsvFile.Filter = "csv file|*.csv";
                    string filename = saveCsvFile.FileName;
                    //int[] quoteMark ={ 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1 };
                    CsvStreamWriter csw = new CsvStreamWriter(filename, System.Text.Encoding.Unicode);
                    csw.QuoteMark(TBCSV.getQuoteMark());
                    csw.AddData(tempDt, 1);
                    csw.FirstRowQuote = 2;
                    csw.Save();
                }
                else
                {
                    MessageBox.Show("没保存");
                }
                MessageBox.Show("共生成" + (tempDt.Rows.Count - 1) + "条数据");
            }
            catch (Exception e1)
            {
                MessageBox.Show(e1.Message);
            }
        }
コード例 #15
0
        public ActionResult DownLoadAllPlantsReport(string id, string reportId, string cTime)
        {
            DefineReport report   = reportService.GetRunReportById(reportId);
            int          tId      = report.ReportType;
            string       weekTime = string.Empty;

            if (tId == DataReportType.TOTAL_REPORT_CODE)
            {
                IList <int> workYears = null;
                if (!(string.IsNullOrEmpty(id)))
                {
                    workYears = collectorYearDataService.GetWorkYears(report.plant);
                }
                else
                {
                    workYears = collectorYearDataService.GetWorkYears(report.user.plants);
                }
                if (workYears.Count > 0)
                {
                    cTime = workYears[0] + "-" + workYears[workYears.Count - 1];
                }
            }
            else if (tId == DataReportType.WEEK_REPORT_CODE)
            {
                string[] wTime = reportService.convertToDateArr(tId, cTime);
                int      year1 = int.Parse(wTime[0].Substring(0, 4));
                int      mm1   = int.Parse(wTime[0].Substring(4, 2));
                int      dd1   = int.Parse(wTime[0].Substring(6, 2));
                int      year2 = int.Parse(wTime[1].Substring(0, 4));
                int      mm2   = int.Parse(wTime[1].Substring(4, 2));
                int      dd2   = int.Parse(wTime[1].Substring(6, 2));
                weekTime = year1 + "/" + mm1 + "/" + dd1 + "-" + year2 + "/" + mm2 + "/" + dd2;
            }
            IList <string>  dataList       = new List <string>();
            IList <object>  obj            = reportService.getDatabyItemCodes(report, cTime);
            IList <int>     itemCode       = addIntNumtoList(obj[0] as List <int>);
            Hashtable       plantDataHash  = obj[1] as Hashtable;
            Hashtable       deviceDataHash = obj[2] as Hashtable;
            CsvStreamWriter csv            = new CsvStreamWriter();

            dataList.Add("                        " + report.ReportName + "                       ");

            ArrayList list2 = new ArrayList();

            list2.Add("                                         " + Resources.SunResource.REPORT_VIEW_TIME);
            if (tId == 2)
            {
                list2.Add(weekTime);
            }
            else
            {
                list2.Add(cTime);
            }
            dataList.Add(csv.ConvertToSaveLine(list2));
            dataList.Add(Resources.SunResource.REPORT_PLANT_COUNT_DATA);
            ArrayList list3 = new ArrayList();

            int i = 1;

            foreach (int code in itemCode)
            {
                int    tmpcode = code;
                string keystr = " ", keyvalue = " ";

                if (i == 5)
                {
                    i = 1;
                }
                else
                {
                    i++;
                }

                if (tmpcode != 0)
                {
                    keystr   = DataItem.getNameByCode(tmpcode);
                    keyvalue = plantDataHash[tmpcode].ToString();
                    list3.Add(keystr);
                    list3.Add(keyvalue);
                }
            }
            dataList.Add(csv.ConvertToSaveLine(list3));
            CsvStreamWriter scvWriter = new CsvStreamWriter();

            scvWriter.AddStrDataList(dataList);
            scvWriter.Save(Server.MapPath("/") + "tempexportfile/" + (report.ReportName + "-" + cTime) + ".csv");
            //转化为csv格式的字符串
            //string res="dsfdsf";
            //byte[] bytes = Encoding.Default.GetBytes(res);

            return(File(Server.MapPath("/") + "tempexportfile/" + (report.ReportName + "-" + cTime) + ".csv", "text/csv; charset=UTF-8", urlcode(report.ReportName.Replace(" ", "") + "-" + cTime) + ".csv"));
        }
コード例 #16
0
        public ActionResult DownLoadDayReport(string id, string reportId, string cTime)
        {
            DefineReport    report         = reportService.GetRunReportById(reportId);
            int             tId            = report.ReportType;
            IList <string>  dataList       = new List <string>();
            IList <object>  obj            = reportService.getDatabyItemCodes(report, cTime);
            IList <int>     itemCode       = addIntNumtoList(obj[0] as List <int>);
            Hashtable       plantDataHash  = obj[1] as Hashtable;
            Hashtable       deviceDataHash = obj[2] as Hashtable;
            CsvStreamWriter csv            = new CsvStreamWriter();

            dataList.Add("                        " + report.ReportName + "                       ");
            ArrayList list2 = new ArrayList();

            list2.Add("                                         " + Resources.SunResource.REPORT_VIEW_TIME);
            list2.Add(cTime);
            dataList.Add(csv.ConvertToSaveLine(list2));
            dataList.Add(Resources.SunResource.REPORT_PLANT_COUNT_DATA);
            ArrayList list3 = new ArrayList();
            ArrayList list4 = new ArrayList();
            int       i     = 1;

            foreach (int code in itemCode)
            {
                int    tmpcode = code;
                string keystr = " ", keyvalue = " ";

                if (i == 5)
                {
                    i = 1;
                }
                else
                {
                    i++;
                }
                if (tmpcode != 0)
                {
                    keystr   = DataItem.getNameByCode(tmpcode);
                    keyvalue = plantDataHash[tmpcode].ToString();
                    list3.Add(keystr);
                    list3.Add(keyvalue);
                }
            }
            dataList.Add(csv.ConvertToSaveLine(list3));
            dataList.Add(Resources.SunResource.REPORT_DEVICE_COUNT_DATA);


            list4.Add(Resources.SunResource.REPORT_COUNT_ITEM);
            list4.Add(Resources.SunResource.REPORT_COUNT_DEVICE);
            list4.Add("7:00");
            list4.Add("8:00");
            list4.Add("9:00");
            list4.Add("10:00");
            list4.Add("11:00");
            list4.Add("12:00");
            list4.Add("13:00");
            list4.Add("14:00");
            list4.Add("15:00");
            list4.Add("16:00");
            list4.Add("17:00");
            list4.Add("18:00");
            list4.Add("19:00");
            list4.Add(Resources.SunResource.REPORT_COUNT_TODAYSUN);
            dataList.Add(csv.ConvertToSaveLine(list4));

            foreach (DictionaryEntry de in deviceDataHash)
            {
                i = 1;
                string tmpcode = de.Key.ToString();
                string keystr = "", unit = "";
                if (!tmpcode.StartsWith(" "))
                {
                    keystr = DataItem.getNameByCode(int.Parse(tmpcode));
                    unit   = MonitorType.getMonitorTypeByCode(int.Parse(tmpcode)).unit;
                }
                IList <string[]> dataArrList = (IList <string[]>)de.Value;
                for (int k = 1; k < dataArrList.Count; k++)
                {
                    ArrayList list5   = new ArrayList();
                    string[]  dataArr = dataArrList[k];
                    if (i == 1)
                    {
                        i++;
                        list5.Add(keystr + " " + unit);

                        list5.Add(dataArr[1]);
                        list5.Add(dataArr[2]);
                        list5.Add(dataArr[3]);
                        list5.Add(dataArr[4]);
                        list5.Add(dataArr[5]);
                        list5.Add(dataArr[6]);
                        list5.Add(dataArr[7]);
                        list5.Add(dataArr[8]);
                        list5.Add(dataArr[9]);
                        list5.Add(dataArr[10]);
                        list5.Add(dataArr[11]);
                        list5.Add(dataArr[12]);
                        list5.Add(dataArr[13]);
                        list5.Add(dataArr[14]);
                        list5.Add(dataArr[15]);
                    }
                    else
                    {
                        list5.Add(" ");
                        list5.Add(dataArr[1]);
                        list5.Add(dataArr[2]);
                        list5.Add(dataArr[3]);
                        list5.Add(dataArr[4]);
                        list5.Add(dataArr[5]);
                        list5.Add(dataArr[6]);
                        list5.Add(dataArr[7]);
                        list5.Add(dataArr[8]);
                        list5.Add(dataArr[9]);
                        list5.Add(dataArr[10]);
                        list5.Add(dataArr[11]);
                        list5.Add(dataArr[12]);
                        list5.Add(dataArr[13]);
                        list5.Add(dataArr[14]);
                        list5.Add(dataArr[15]);
                    }
                    dataList.Add(csv.ConvertToSaveLine(list5));
                }
            }
            CsvStreamWriter scvWriter = new CsvStreamWriter();

            scvWriter.AddStrDataList(dataList);
            scvWriter.Save(Server.MapPath("/") + "tempexportfile/" + (report.ReportName + "-" + cTime) + ".csv");
            //转化为csv格式的字符串
            //string res="dsfdsf";
            //byte[] bytes = Encoding.Default.GetBytes(res);
            return(File(Server.MapPath("/") + "tempexportfile/" + (report.ReportName + "-" + cTime) + ".csv", "text/csv; charset=UTF-8", urlcode(report.ReportName.Replace(" ", "") + "-" + cTime) + ".csv"));
        }
コード例 #17
0
        public ActionResult DownLoadNotDayReport(string id, string reportId, string cTime)
        {
            DefineReport report   = reportService.GetRunReportById(reportId);
            int          tId      = report.ReportType;
            string       weekTime = string.Empty;

            if (tId == DataReportType.TOTAL_REPORT_CODE)
            {
                IList <int> workYears = null;
                if (!(string.IsNullOrEmpty(id)))
                {
                    workYears = collectorYearDataService.GetWorkYears(report.plant);
                }
                else
                {
                    workYears = collectorYearDataService.GetWorkYears(report.user.plants);
                }
                if (workYears.Count > 0)
                {
                    cTime = workYears[0] + "-" + workYears[workYears.Count - 1];
                }
            }
            else if (tId == DataReportType.WEEK_REPORT_CODE)
            {
                string[] wTime = reportService.convertToDateArr(tId, cTime);
                int      year1 = int.Parse(wTime[0].Substring(0, 4));
                int      mm1   = int.Parse(wTime[0].Substring(4, 2));
                int      dd1   = int.Parse(wTime[0].Substring(6, 2));
                int      year2 = int.Parse(wTime[1].Substring(0, 4));
                int      mm2   = int.Parse(wTime[1].Substring(4, 2));
                int      dd2   = int.Parse(wTime[1].Substring(6, 2));
                weekTime = year1 + "/" + mm1 + "/" + dd1 + "-" + year2 + "/" + mm2 + "/" + dd2;
            }
            IList <string>  dataList       = new List <string>();
            IList <object>  obj            = reportService.getDatabyItemCodes(report, cTime);
            IList <int>     itemCode       = addIntNumtoList(obj[0] as List <int>);
            Hashtable       plantDataHash  = obj[1] as Hashtable;
            Hashtable       deviceDataHash = obj[2] as Hashtable;
            CsvStreamWriter csv            = new CsvStreamWriter();

            dataList.Add("                        " + report.ReportName + "                       ");
            ArrayList list2 = new ArrayList();

            list2.Add("                                         " + Resources.SunResource.REPORT_VIEW_TIME);
            if (tId == DataReportType.WEEK_REPORT_CODE)
            {
                list2.Add(weekTime);
            }
            else
            {
                list2.Add(cTime);
            }
            dataList.Add(csv.ConvertToSaveLine(list2));
            dataList.Add(Resources.SunResource.REPORT_PLANT_COUNT_DATA);
            ArrayList list3 = new ArrayList();
            ArrayList list4 = new ArrayList();
            int       i     = 1;

            foreach (int code in itemCode)
            {
                int    tmpcode = code;
                string keystr = " ", keyvalue = " ";

                if (i == 5)
                {
                    i = 1;
                }
                else
                {
                    i++;
                }
                if (tmpcode != 0)
                {
                    keystr   = DataItem.getNameByCode(tmpcode);
                    keyvalue = plantDataHash[tmpcode].ToString();
                    list3.Add(keystr);
                    list3.Add(keyvalue);
                }
            }
            dataList.Add(csv.ConvertToSaveLine(list3));
            dataList.Add(Resources.SunResource.REPORT_DEVICE_COUNT_DATA);

            foreach (DictionaryEntry de in  deviceDataHash)
            {
                i = 1;
                string tmpcode = de.Key.ToString();
                string keystr = "", unit = "";
                if (!tmpcode.StartsWith(" "))
                {
                    keystr = MonitorType.getMonitorTypeByCode(MonitorType.PLANT_MONITORITEM_ENERGY_CODE).name;
                    unit   = MonitorType.getMonitorTypeByCode(MonitorType.PLANT_MONITORITEM_ENERGY_CODE).unit;
                }
                IList <string[]> dataArrList = (IList <string[]>)de.Value;
                for (int k = 0; k < dataArrList.Count; k++)
                {
                    ArrayList list5   = new ArrayList();
                    string[]  dataArr = dataArrList[k];
                    if (i == 1)
                    {
                        i++;
                        foreach (string v in dataArr)
                        {
                            list5.Add(v);
                        }
                    }
                    else if (i == 2)
                    {
                        i++;
                        list5.Add(keystr + " " + unit);
                        for (int n = 1; n < dataArr.Length; n++)
                        {
                            list5.Add(dataArr[n]);
                        }
                    }
                    else
                    {
                        for (int m = 0; m < dataArr.Length; m++)
                        {
                            list5.Add(dataArr[m] == null?" ":dataArr[m]);
                        }
                    }
                    dataList.Add(csv.ConvertToSaveLine(list5));
                }
            }
            CsvStreamWriter scvWriter = new CsvStreamWriter();

            scvWriter.AddStrDataList(dataList);
            scvWriter.Save(Server.MapPath("/") + "tempexportfile/" + (report.ReportName + "-" + cTime) + ".csv");
            //转化为csv格式的字符串
            //string res="dsfdsf";
            //byte[] bytes = Encoding.Default.GetBytes(res);
            return(File(Server.MapPath("/") + "tempexportfile/" + (report.ReportName + "-" + cTime) + ".csv", "text/csv; charset=UTF-8", urlcode(report.ReportName.Replace(" ", "") + "-" + cTime) + ".csv"));
        }