Пример #1
0
        private void ShowInvInfo()
        {
            string sql = @"select orderid 盘点单号,storageid 仓库代码 ,comparedate 盘点完成日期,checktime 盘点日期,checkstate 盘点状态,checkname 盘点名称 from t_mat_checkouttable";

            DataTable dt = ora.GetDt(sql);

            dataGridView6.DataSource = dt;
        }
Пример #2
0
 private void button4_Click_1(object sender, EventArgs e)
 {
     try
     {
         oraexec ora = new oraexec(connstr);
         int     i   = ora.ExecuteNonQuery("truncate table  jxc_for_sap");
         richTextBox3.AppendText(DateTime.Now.ToString() + "--清除数据结果:" + i.ToString() + " ");
         DataTable dt = new DataTable();
         dt = ora.GetDt("select * from t_mom_outinwmsresultorder where  state=2 ");
         if (dt.Rows.Count > 0)
         {
             richTextBox3.AppendText(DateTime.Now.ToString() + "--查询到" + dt.Rows.Count.ToString() + "条记录 ");
             richTextBox3.Focus();
         }
     }
     catch (Exception er)
     {
         this.Invoke(new Action(() =>
         {
             richTextBox3.AppendText(er.ToString() + " ");
         }));
     }
 }
Пример #3
0
        private void ExpFromorcl()
        {
            this.Invoke(new Action(() =>
            {
                this.button2.Enabled = false;
                this.button5.Enabled = false;
                this.button6.Enabled = false;
                this.button7.Enabled = false;
                this.button8.Enabled = false;
            }));
            this.Invoke(new Action(() =>
            {
                richTextBox4.AppendText(DateTime.Now.ToString() + "--开始导出查询结果... " + "\r\n");
            }));
            if (!Directory.Exists(Application.StartupPath + "\\Excel\\"))
            {
                // Create the directory it does not exist.
                Directory.CreateDirectory(Application.StartupPath + "\\Excel\\");
            }
            DataTable dtrpt = new DataTable();
            oraexec   ora   = new oraexec(connstr);

            dtrpt = ora.GetDt("select * from test");

            string iyear    = Std.Value.Year.ToString();
            string imonth   = Std.Value.Month.ToString();
            string filepath = Application.StartupPath + "\\Excel\\" + iyear + "-" + imonth + "-" + DateTime.Now.ToString().Replace('/', '-').Replace("-", "").Replace(":", "").Replace(" ", "") + ".csv";

            KillSpecialExcel();
            var lines = new List <string>();

            string[] columnNames = dtrpt.Columns
                                   .Cast <DataColumn>()
                                   .Select(column => column.ColumnName)
                                   .ToArray();
            var header = string.Join(",", columnNames);

            lines.Add(header);
            var valueLines = dtrpt.AsEnumerable()
                             .Select(row => string.Join(",", row.ItemArray));

            lines.AddRange(valueLines);
            File.WriteAllLines(filepath, lines, Encoding.GetEncoding("gb2312"));

            Process.Start(filepath);

            //string result = string.Empty;
            //try
            //{
            //    // 实例化流对象,以特定的编码向流中写入字符。
            //    StreamWriter sw = new StreamWriter(filepath, false, Encoding.GetEncoding("gb2312"));

            //    StringBuilder sb = new StringBuilder();
            //    for (int k = 0; k < dtrpt.Columns.Count; k++)
            //    {
            //        // 添加列名称
            //        sb.Append(dtrpt.Columns[k].ColumnName.ToString() + "\t");
            //    }
            //    sb.Append(Environment.NewLine);
            //    // 添加行数据
            //    for (int i = 0; i < dtrpt.Rows.Count; i++)
            //    {
            //        DataRow row = dtrpt.Rows[i];
            //        for (int j = 0; j < dtrpt.Columns.Count; j++)
            //        {
            //            // 根据列数追加行数据
            //            sb.Append(row[j].ToString() + "\t");
            //        }
            //        sb.Append(Environment.NewLine);
            //    }
            //    sw.Write(sb.ToString());
            //    sw.Flush();
            //    sw.Close();
            //    sw.Dispose();

            //    // 导出成功后打开
            //    System.Diagnostics.Process.Start(filepath);

            //XSSFWorkbook excelBook = new XSSFWorkbook(); //创建工作簿Excel

            //NPOI.SS.UserModel.ISheet sheet1 = excelBook.CreateSheet("进销存");//为工作簿创建工作表并命名
            ////定义样式
            //NPOI.XSSF.UserModel.XSSFCellStyle cellStyle = (NPOI.XSSF.UserModel.XSSFCellStyle)excelBook.CreateCellStyle(); //定义一个单元格样式
            //                                                                      // 设置单元格背景色
            //                                                                      //  cellStyle.FillForegroundColor = HSSFColor.White.Index;
            //                                                                      //   cellStyle.FillPattern = FillPattern.SolidForeground;

            ////设置文字对齐方式
            //cellStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left; //水平居中

            ////设置字体格式开始
            //XSSFFont firstFont = (XSSFFont)excelBook.CreateFont();

            ////字体属性
            //firstFont.FontName = "幼圆";
            //firstFont.FontHeightInPoints = (short)11; //设置字体大小
            //cellStyle.SetFont(firstFont);  //设置cellStyle 样式的字体



            ////编写工作表
            //NPOI.SS.UserModel.IRow row0 = sheet1.CreateRow(0);//创建表头

            //row0.CreateCell(0).SetCellValue("大区经理");
            //row0.CreateCell(1).SetCellValue("业务主管");
            //row0.CreateCell(2).SetCellValue("店铺代码");
            //row0.CreateCell(3).SetCellValue("店铺名称");
            //row0.CreateCell(4).SetCellValue("期初数量");
            //row0.CreateCell(5).SetCellValue("入库数量");
            //row0.CreateCell(6).SetCellValue("出库数量");

            //row0.CreateCell(7).SetCellValue("期末数量");
            //row0.CreateCell(8).SetCellValue("期末库存金额");
            //row0.CreateCell(9).SetCellValue("库存成本金额");
            //row0.CreateCell(10).SetCellValue("销售上报数量");
            //row0.CreateCell(11).SetCellValue("销售上报金额");
            //row0.CreateCell(12).SetCellValue("货品编号");
            //row0.CreateCell(13).SetCellValue("货品名称");
            //row0.CreateCell(14).SetCellValue("品牌");
            //row0.CreateCell(15).SetCellValue("条码");
            //row0.CreateCell(16).SetCellValue("零售价格");
            //row0.CreateCell(17).SetCellValue("库存成本");
            //row0.CreateCell(18).SetCellValue("二类品线");
            //int i = 1;
            //dtrpt.AsEnumerable().ToList().ForEach(r =>
            //{
            //    this.Invoke(new Action(() =>
            //    {
            //        richTextBox4.AppendText(DateTime.Now.ToString() + "导出" + dtrpt.Rows.Count.ToString() + "/" + i.ToString() + "条件记录中... " + "\r\n");

            //    }));
            //    NPOI.SS.UserModel.IRow rowTemp = sheet1.CreateRow(i);
            //    rowTemp.CreateCell(0).SetCellValue(r[0].ToString());
            //    rowTemp.CreateCell(1).SetCellValue(r[1].ToString());
            //    rowTemp.CreateCell(2).SetCellValue(r[2].ToString());
            //    rowTemp.CreateCell(3).SetCellValue(r[3].ToString());
            //    rowTemp.CreateCell(4).SetCellValue(r[4].ToString());
            //    rowTemp.CreateCell(5).SetCellValue(r[5].ToString());
            //    rowTemp.CreateCell(6).SetCellValue(r[6].ToString());
            //    rowTemp.CreateCell(7).SetCellValue(r[7].ToString());
            //    rowTemp.CreateCell(8).SetCellValue(r[8].ToString());
            //    rowTemp.CreateCell(9).SetCellValue(r[9].ToString());
            //    rowTemp.CreateCell(10).SetCellValue(r[10].ToString());
            //    rowTemp.CreateCell(11).SetCellValue(r[11].ToString());
            //    rowTemp.CreateCell(12).SetCellValue(r[12].ToString());
            //    rowTemp.CreateCell(13).SetCellValue(r[13].ToString());
            //    rowTemp.CreateCell(14).SetCellValue(r[14].ToString());
            //    rowTemp.CreateCell(15).SetCellValue(r[15].ToString());
            //    rowTemp.CreateCell(16).SetCellValue(r[16].ToString());
            //    rowTemp.CreateCell(17).SetCellValue(r[17].ToString());
            //    rowTemp.CreateCell(18).SetCellValue(r[18].ToString());

            //    i++;
            //}
            //);
            //sheet1.SetColumnWidth(0, 15 * 256);
            //sheet1.SetColumnWidth(1, 15 * 256);
            //sheet1.SetColumnWidth(2, 15 * 256);
            //sheet1.SetColumnWidth(3, 15 * 256);
            //sheet1.SetColumnWidth(4, 15 * 256);
            //sheet1.SetColumnWidth(5, 15 * 256);
            //sheet1.SetColumnWidth(6, 15 * 256);
            //sheet1.SetColumnWidth(7, 15 * 256);
            //sheet1.SetColumnWidth(8, 15 * 256);
            //sheet1.SetColumnWidth(9, 15 * 256);
            //sheet1.SetColumnWidth(10, 15 * 256);
            //sheet1.SetColumnWidth(11, 15 * 256);
            //sheet1.SetColumnWidth(12, 15 * 256);
            //sheet1.SetColumnWidth(13, 50 * 256);
            //sheet1.SetColumnWidth(14, 15 * 256);
            //sheet1.SetColumnWidth(15, 15 * 256);
            //sheet1.SetColumnWidth(16, 15 * 256);
            //sheet1.SetColumnWidth(17, 15 * 256);
            //sheet1.SetColumnWidth(18, 15 * 256);



            //using (FileStream fs = new FileStream(filepath, FileMode.Create, FileAccess.Write))
            //{
            //    excelBook.Write(fs);
            //}
            //object missing = Type.Missing;
            //Microsoft.Office.Interop.Excel.Application ExcelRS;
            //Microsoft.Office.Interop.Excel.Workbook RSbook;
            //Microsoft.Office.Interop.Excel.Worksheet RSsheet;
            //ExcelRS = new Microsoft.Office.Interop.Excel.Application();
            ////打开目标文件filePath
            //RSbook = ExcelRS.Workbooks.Open(filepath, missing, missing, missing, missing, missing,
            //    missing, missing, missing, missing, missing, missing, missing, missing, missing);
            //RSsheet = (Microsoft.Office.Interop.Excel.Worksheet)RSbook.Sheets.get_Item(1);

            //ExcelRS.DisplayAlerts = false;

            //ExcelRS.Visible = true;

            this.Invoke(new Action(() =>
            {
                //  richTextBox3.AppendText(newsql + " ");
                richTextBox4.AppendText(DateTime.Now.ToString() + "--提取结束 \r\n ");

                this.button5.Enabled = true;
                this.button6.Enabled = true;
                this.button7.Enabled = true;
                this.button8.Enabled = true;
                this.button2.Enabled = true;
            }));
        }