Пример #1
0
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            if (dt.Rows.Count <= 1)
            {
                System.Windows.MessageBox.Show("没有数据,无法导出", "提示");
                return;
            }

            SaveFileDialog sfd = new SaveFileDialog();
            string         filename;

            sfd.InitialDirectory = System.Environment.CurrentDirectory;
            filename             = MyDateTimeUtil.Format(Convert.ToDateTime(DatePicker1.Text), "yyyyMMdd");
            //if (DatePicker2.Text == "") { filename = DatePicker1.Text; }
            if (DatePicker2.Text != "")
            {
                filename = filename + "-" + MyDateTimeUtil.Format(Convert.ToDateTime(DatePicker2.Text), "yyyyMMdd");
            }
            sfd.FileName         = filename + "自助入住记录统计";
            sfd.RestoreDirectory = true;
            sfd.Filter           = "Excel文件(*.xlsx)|*.xlsx|Excel文件(*.xls)|*.xls |CSV文件(*.csv) | *.csv";
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                if (sfd.FileName.ToLower().EndsWith("csv"))
                {
                    CsvUtil cu = new CsvUtil();
                    cu.ExportDataToCVS(sfd.FileName, dt);
                    System.Windows.MessageBox.Show("成功导出CSV文件", "成功");
                }
                else
                {
                    Type officeType = Type.GetTypeFromProgID("Excel.Application");
                    if (officeType == null)
                    {
                        Console.WriteLine("没安装!");
                        System.Windows.MessageBox.Show("提示", "请先安装office2007以上版本办公软件");
                        return;
                    }
                    else
                    {
                        Console.WriteLine("已安装!");

                        ExcelUtil eu = new ExcelUtil();
                        eu.DataTabletoExcel(dt, sfd.FileName);
                        System.Windows.MessageBox.Show("成功导出EXCEL文件", "成功");
                    }
                }
            }
            //var dialog = new FolderBrowserDialog();
            //dialog.ShowDialog();
            //folderpathTB.Text = dialog.SelectedPath;
            // excelUtil eu = new excelUtil();
            //eu.DataTabletoExcel(dt, System.Environment.CurrentDirectory + "\\temp.xlsx");
            //eu.DataTabletoExcel(dt, dialog.SelectedPath + "\\temp.xlsx");
        }
Пример #2
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            //只选了主选项不选副选项一律输出整张表内容
            //DataTable displayData = new DataTable();


            String condition = "";

            if (DatePicker1.Text != "")
            {
                condition += "and PAYTIME>='" + MyDateTimeUtil.Format(Convert.ToDateTime(DatePicker1.Text + " 00:00:01"), "yyyy-MM-dd HH:mm:ss") + "'";
            }

            if (DatePicker2.Text != "")
            {
                condition += "and PAYTIME<='" + MyDateTimeUtil.Format(Convert.ToDateTime(DatePicker2.Text + " 23:59:59"), "yyyy-MM-dd HH:mm:ss") + "'";
            }

            if (roomNo.Text != "")
            {
                condition += " and ROOMNO='" + roomNo.Text + "'";
            }

            if (guestName.Text != "")
            {
                condition += " and GUESTNAME like '%" + guestName.Text + "%'";
            }

            //System.Windows.MessageBox.Show(condition);

            if (condition.Equals(""))
            {
                System.Windows.MessageBox.Show("请输入查询条件");
                return;
            }

            dt = dbutil.query(displayColumns, condition);
            SelectDisplayColumns(dt);


            double total = 0;

            foreach (DataRow row in dt.Rows)
            {
                total += double.Parse(row["总价"].ToString());
            }
            dt = UpdateDataTable(dt);
            //dt.Columns[9].DataType = typeof(string);
            //string s = dt.Columns[10].ColumnName;
            DataRow newRow;

            newRow = dt.NewRow();
            //if (dt.Rows.Count == 0)
            // {
            newRow["入住天数"] = "汇总";
            // }
            // else { newRow["单价"] = "   总数:"; }
            //newRow["总价"] = dt.Rows.Count;
            newRow["单价"] = dt.Rows.Count + "个订单";
            newRow["总价"] = "¥" + total;
            dt.Rows.Add(newRow);

            dataGrid.ItemsSource = dt.DefaultView;
            setColumnsWidth();
        }
 static void Main(string[] args)
 {
     DateTime time        = DateTime.Now;
     DateTime newDateTime = MyDateTimeUtil.CreateDateFromTime(2015, 12, 12, time);
 }