Esempio n. 1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            DateTime start = this.dtStart.SelectedDate ?? DateTime.Now;
            DateTime end   = this.dtEnd.SelectedDate ?? DateTime.Now;

            System.Windows.Forms.SaveFileDialog sfd = new System.Windows.Forms.SaveFileDialog();
            sfd.DefaultExt = "xls";
            sfd.Filter     = "Excel文件(*.xls)|*.xls";
            sfd.Title      = "导出文件路径";
            if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                DataTable dt      = IEnumerableHelper.ToDataTable <LR.Services.ConsumeDataModel>(this._service.GetExtractList(start, end.AddDays(1)));
                String[]  columns = { "StaffNo", "StaffName", "RoomNo", "RoomName", "Amount", "Admin", "CreateDate", "ModifyDate" };
                String[]  names   = { "员工号", "姓名", "房间号", "房间", "金额", "操作人", "创建时间", "修改时间" };
                DataView  dv      = dt.DefaultView;
                dt = dv.ToTable(true, columns);

                DataRow dr = dt.NewRow();
                dr["RoomName"] = "总计";
                dr["Amount"]   = dt.Compute("sum(Amount)", "");
                dt.Rows.Add(dr);

                for (int i = 0; i < columns.Length; i++)
                {
                    dt.Columns[columns[i]].ColumnName = names[i];
                }

                ExcelHelper.DataTableToExcel(dt, sfd.FileName);
            }
            this.Close();
        }
        private void btnExtract_Click(object sender, EventArgs e)
        {
            if (this.lvwShow.ItemsSource == null)
            {
                Tip p = new Tip("当前账期没有数据 !");
                p.ShowDialog();
                return;
            }
            System.Windows.Forms.SaveFileDialog sfd = new System.Windows.Forms.SaveFileDialog();
            sfd.DefaultExt = "xls";
            sfd.Filter     = "Excel文件(*.xls)|*.xls";
            sfd.Title      = "导出文件路径";
            if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                DataTable dt      = IEnumerableHelper.ToDataTable <RoyaltySettleExpendModel>((IEnumerable <RoyaltySettleExpendModel>) this.lvwShow.ItemsSource);
                String[]  columns = { "StaffNo", "StaffName", "Reservation", "Administration", "Cooperation", "Transcend", "WorkGroup", "Total", "Expend", "Self", "Receiver", "Admin", "ExpandTimeStr" };
                String[]  names   = { "员工号", "姓名", "订房奖励", "管理奖励", "协助奖励", "超越奖励", "工作组管理奖励", "总金额", "是否已发", "是否本人领取", "领取人", "操作人", "领取时间" };


                DataRow dr = dt.NewRow();
                dr["StaffName"]      = "总计";
                dr["Reservation"]    = dt.Compute("sum(Reservation)", "");
                dr["Administration"] = dt.Compute("sum(Administration)", "");
                dr["Cooperation"]    = dt.Compute("sum(Cooperation)", "");
                dr["Transcend"]      = dt.Compute("sum(Transcend)", "");
                dr["WorkGroup"]      = dt.Compute("sum(WorkGroup)", "");
                dr["Total"]          = dt.Compute("sum(Total)", "");
                dt.Rows.Add(dr);

                DataView dv = dt.DefaultView;
                dt = dv.ToTable(true, columns);
                for (int i = 0; i < columns.Length; i++)
                {
                    dt.Columns[columns[i]].ColumnName = names[i];
                }
                ExcelHelper.DataTableToExcel(dt, sfd.FileName);
            }
        }