# Nuntio Inquiry_CELL_INST 功能增加及加入page grid頁面 [TOC] ## Page Grid 增加User Control name `GridPager.xaml` ```xaml <UserControl x:Class="ares.client.module.View.GridPager" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:ares.client.module.View" xmlns:ig="http://schemas.infragistics.com/xaml" xmlns:Custom="http://infragistics.com/Editors" mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800"> <Grid> <!--<Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="*"/> </Grid.RowDefinitions>--> <ig:XamGrid x:Name="TestDataGrid1" ItemsSource="{Binding DataGrid_IS, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" HeaderRowHeight="35" RowHeight="30" VerticalContentAlignment="Center" BorderBrush="Black" Margin="10,0,10,0" > <ig:XamGrid.PagerSettings > <ig:PagerSettings AllowPaging="Top" PageSize="{Binding Source={x:Reference Pagersize}, Path=SelectedItem}"/> </ig:XamGrid.PagerSettings> <ig:XamGrid.RowSelectorSettings> <ig:RowSelectorSettings Visibility="Visible" /> </ig:XamGrid.RowSelectorSettings> </ig:XamGrid> <Label Content="Page size:" HorizontalAlignment="Left" Margin="10,0,0,0" VerticalAlignment="Top" /> <Custom:XamComboEditor x:Name="Pagersize" HorizontalAlignment="Left" Margin="70,3,0,0" VerticalAlignment="Top" Width="45" Height="22" Text="10" ItemsSource="{Binding itemkind}" SelectedItem="{Binding selecteditemkind, UpdateSourceTrigger=PropertyChanged}" SelectedIndex="{Binding selecteditemkindindex}"/> </Grid> </UserControl> ``` ## Inquiry_CELL_INST (View) 增加User Control name `Inquiry_Cell_Instance.xaml` ```xaml <UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:testView="clr-namespace:ares.client.module.xls.view.testView" xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:mvvmlight="clr-namespace:ares.utilities.wpf.command.mvvmlight;assembly=ares.utilities.wpf" xmlns:ig="http://schemas.infragistics.com/xaml" xmlns:view="clr-namespace:ares.client.module.View" x:Class="ares.client.module.View.Inquiry_Cell_Instance"> <UserControl.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="..\xls\..\style\IG.xamGrid.xaml"/> <ResourceDictionary Source="..\xls\..\style\StyleButton.xaml"/> <ResourceDictionary Source="..\xls\..\style\StylePropertyExpander.xaml"/> <ResourceDictionary Source="..\xls\..\style\StyleCommon.xaml"/> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </UserControl.Resources> <!--<ScrollViewer Background="Transparent" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled">--> <Grid> <GroupBox IsEnabled="{Binding inputinfo_isenable}" Header="" HorizontalAlignment="Left" Margin="0,38,0,0" VerticalAlignment="Top" Height="47" Width="740" BorderBrush="{x:Null}"> <Grid> <Label Content="Data Date:" HorizontalAlignment="Left" Margin="5,0,0,0" VerticalAlignment="Top" /> <DatePicker x:Name="DatePicker1" Text="{Binding date_t, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="75,0,0,0" Width="150" VerticalAlignment="Center" HorizontalAlignment="Left" /> <Button Content="Report ID:" HorizontalAlignment="Left" Margin="232,0,0,0" VerticalAlignment="Top" Width="70" Height="22" Command="{Binding ServiceCommand_ReportID}"/> <TextBox HorizontalAlignment="Left" Margin="310,0,0,0" VerticalAlignment="Top" Width="158" Height="22" Text="{Binding reportid_t, UpdateSourceTrigger=PropertyChanged}"/> <Button Content="Cell ID:" HorizontalAlignment="Left" Margin="484,0,0,0" VerticalAlignment="Top" Height="22" Width="58" Command="{Binding ServiceCommand_CellID}"/> <TextBox HorizontalAlignment="Left" Height="22" Margin="549,0,0,0" VerticalAlignment="Top" Width="138" Text="{Binding cellid_t, UpdateSourceTrigger=PropertyChanged}"/> </Grid> </GroupBox> <!--<ScrollViewer Background="Transparent" HorizontalContentAlignment="Stretch" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled" VerticalAlignment="Top" VerticalContentAlignment="Stretch" Margin="10,90,10,0" >--> <Grid> <Grid.RowDefinitions> <RowDefinition Height="90"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <view:GridPager Grid.Row="1" x:Name="GridPagerViewControl" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/> </Grid> <!--</ScrollViewer>--> <testView:Toolbar x:Name="toolbar2" HorizontalAlignment="Left" VerticalAlignment="Top"> <i:Interaction.Triggers> <i:EventTrigger EventName="InquiryClick"> <mvvmlight:EventToCommand Command="{Binding ServiceCommand_Open}" /> </i:EventTrigger> <i:EventTrigger EventName="PrintClick"> <mvvmlight:EventToCommand Command="{Binding ServiceCommand_Print}" CommandParameter="{Binding ElementName=TestDataGrid1, Mode=OneWay}"/> </i:EventTrigger> <i:EventTrigger EventName="CancelClick"> <mvvmlight:EventToCommand Command="{Binding ServiceCommand_Cancel}" /> </i:EventTrigger> </i:Interaction.Triggers> </testView:Toolbar> </Grid> <!--</ScrollViewer>--> </UserControl> ``` 並且在 `Inquiry_Cell_Instance.xaml.cs` 中加入 GridePage 所要用的欄位 ```C# private void generate_columns() { GridPagerViewControl.TestDataGrid1.Columns.Add(new TextColumn() { Key = "CELL_INST_ID", HeaderText = "CELL_INST_ID" }); GridPagerViewControl.TestDataGrid1.Columns.Add(new TextColumn() { Key = "CELL_ORG_INST_VALUE", HeaderText = "CELL_ORG_INST_VALUE" }); GridPagerViewControl.TestDataGrid1.Columns.Add(new TextColumn() { Key = "CELL_INST_VALUE", HeaderText = "CELL_INST_VALUE" }); GridPagerViewControl.TestDataGrid1.Columns.Add(new TextColumn() { Key = "CELL_INST_EXPRESSION", HeaderText = "CELL_INST_EXPRESSION" }); GridPagerViewControl.TestDataGrid1.Columns.Add(new TextColumn() { Key = "CELL_INST_DETAIL_EXPRESSION", HeaderText = "CELL_INST_DETAIL_EXPRESSION" }); GridPagerViewControl.TestDataGrid1.Columns.Add(new TextColumn() { Key = "CELL_VALUE_UNIT", HeaderText = "CELL_VALUE_UNIT" }); GridPagerViewControl.TestDataGrid1.Columns.Add(new TextColumn() { Key = "CELL_VALUE_DECIMAL_PLACE", HeaderText = "CELL_VALUE_DECIMAL_PLACE" }); GridPagerViewControl.TestDataGrid1.Columns.Add(new TextColumn() { Key = "CREATE_MODE", HeaderText = "CREATE_MODE" }); GridPagerViewControl.TestDataGrid1.Columns.Add(new TextColumn() { Key = "SHEET_NO", HeaderText = "SHEET_NO" }); GridPagerViewControl.TestDataGrid1.Columns.Add(new TextColumn() { Key = "ROW_NO", HeaderText = "ROW_NO" }); GridPagerViewControl.TestDataGrid1.Columns.Add(new TextColumn() { Key = "COL_NO", HeaderText = "COL_NO" }); GridPagerViewControl.TestDataGrid1.Columns.Add(new TextColumn() { Key = "CELL_DEF_ID", HeaderText = "CELL_DEF_ID" }); GridPagerViewControl.TestDataGrid1.Columns.Add(new TextColumn() { Key = "RPT_INST_ID", HeaderText = "RPT_INST_ID" }); GridPagerViewControl.TestDataGrid1.Columns.Add(new TextColumn() { Key = "CELL_TYPE", HeaderText = "CELL_TYPE" }); GridPagerViewControl.TestDataGrid1.Columns.Add(new TextColumn() { Key = "LAST_UPDATE_TIME", HeaderText = "LAST_UPDATE_TIME" }); GridPagerViewControl.TestDataGrid1.Columns.Add(new TextColumn() { Key = "LAST_UPDATE_USERID", HeaderText = "LAST_UPDATE_USERID" }); GridPagerViewControl.TestDataGrid1.Columns.Add(new TextColumn() { Key = "FORMULA", HeaderText = "FORMULA" }); GridPagerViewControl.TestDataGrid1.Columns.Add(new TextColumn() { Key = "COMMENT", HeaderText = "COMMENT" }); } ``` 在 Initialize 時就執行 `generate_columns();` ```C# public Inquiry_Cell_Instance(Inquiry_Cell_Instance_VM viewModel) { InitializeComponent(); generate_columns(); DataContext = viewModel; toolbar2.DataContext = viewModel; // note } ``` ## Inquiry_CELL_INST (ViewModel) 新增一個class `Inquiry_CELL_INST_VM.cs ```C# using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Data; using System.Globalization; using System.Linq; using System.Windows.Forms; using System.Windows.Input; using ares.client.module.SharedMethod; using ares.client.module.View.childView; using ares.client.module.ViewModel.childViewModel; using ares.nuntio.share.service; using ares.utilities.authentication; using ares.utilities.wpf.common; using System.Windows; using System.Windows.Documents; using Common.Logging; using MessageBox = System.Windows.Forms.MessageBox; namespace ares.client.module.ViewModel { public class Inquiry_Cell_Instance_VM : ViewModelBase { #region Global Parameter private readonly ISampleService _proxy;//service client private static ILog Log = LogManager.GetLogger("Inquiry_Cell_Instance_VM"); public string cellid_t { get; set; } public string reportid_t { get; set; } public string textdata_t { get; set; } public bool inputinfo_isenable { get; set; } public List<int> itemkind { get; set; } public int selecteditemkind { get; set; } public int selecteditemkindindex { get; set; } public string date_t { get => _dateT; set { _dateT = value; OnPropertyChanged("date_t"); } } public ObservableCollection<ReportCellInstList> DataGrid_IS { get; set; } DataTable _dt = new DataTable(); readonly InquiryCellIdView_VM _inquiryCellIdViewVm; readonly InquiryReportIdView_VM _inquiryReportIdViewVm; #endregion public Inquiry_Cell_Instance_VM(IUser user, IApplicationFactory applicationFactory, ISampleService proxy) : base(user, applicationFactory) { _inquiryCellIdViewVm = new InquiryCellIdView_VM(user, applicationFactory, proxy); _inquiryReportIdViewVm = new InquiryReportIdView_VM(user, applicationFactory, proxy); _proxy = proxy; cellid_t = ""; reportid_t = ""; inputinfo_isenable = true; //date_t = DateTime.Now.ToString(CultureInfo.InvariantCulture); date_t = ""; itemkind = new List<int> { 10, 20, 30, 40, 50 }; selecteditemkindindex = -1; InquiryIsEnable = true; PrintIsEnable = false; CancelIsEnable = true; UpdateVisibility = Visibility.Collapsed; DeleteVisibility = Visibility.Collapsed; ExecuteVisibility = Visibility.Collapsed; CheckVisibility = Visibility.Collapsed; RejectVisibility = Visibility.Collapsed; ExportVisibility = Visibility.Collapsed; } #region Button_Visibility_IsEnable public Visibility InquiryVisibility { get; set; } public Visibility UpdateVisibility { get; set; } public Visibility DeleteVisibility { get; set; } public Visibility ExecuteVisibility { get; set; } public Visibility CheckVisibility { get; set; } public Visibility RejectVisibility { get; set; } public Visibility PrintVisibility { get; set; } public Visibility ExportVisibility { get; set; } public Visibility CancelVisibility { get; set; } public bool InquiryIsEnable { get; set; } public bool UpdateIsEnable { get; set; } public bool DeleteIsEnable { get; set; } public bool ExecuteIsEnable { get; set; } public bool CheckIsEnable { get; set; } public bool RejectIsEnable { get; set; } public bool PrintIsEnable { get; set; } public bool ExportIsEnable { get; set; } public bool CancelIsEnable { get; set; } #endregion #region ServiceCommand_Open private ICommand _serviceCommand_Open; public ICommand ServiceCommand_Open { get { return _serviceCommand_Open ?? (_serviceCommand_Open = CommandFactory.CreateCommand<object>(ServiceMethod_Open)); } } private void ServiceMethod_Open(object parameter) { Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait; try { DataGrid_IS = new ObservableCollection<ReportCellInstList>(); if (date_t != "") { if (string.IsNullOrEmpty(cellid_t.Trim(' '))) { #region date cell rpt blank O X X if (string.IsNullOrEmpty(reportid_t.Trim(' '))) { MessageBox.Show("Please input Cell ID or Report ID!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } #endregion #region else { //QUERY var date = DateTime.ParseExact(DateTime.Parse(date_t).ToString("yyyyMMdd"), "yyyyMMdd", CultureInfo.CurrentCulture); var dt_rpt = _proxy.GetArReportInst_NHibernate(reportid_t.Trim(' '), date.Date.ToString("yyyyMMdd")); var dt_rptLength = dt_rpt.Rows.Count; if (dt_rptLength > 0) { var _rptinstid = dt_rpt.Rows[0][0].ToString(); var dt = _proxy.GetArCellInst_NHibernate(_rptinstid.Trim(' ')); var dtLength = dt.Rows.Count; if (dtLength > 0) { for (int i = 0; i < dtLength; i++) { string cellinstid = dt.Rows[i][0].ToString(); string cellorginstvalue = dt.Rows[i][1].ToString(); string cellinstvalue = dt.Rows[i][2].ToString(); string cellinstexpression = dt.Rows[i][3].ToString(); string cellinstdetailexpression = dt.Rows[i][4].ToString(); string cellvalueunit = dt.Rows[i][5].ToString(); string cellvaluedecimalplace = dt.Rows[i][6].ToString(); string createmode = dt.Rows[i][7].ToString(); string sheetno = dt.Rows[i][8].ToString(); string rowno = dt.Rows[i][9].ToString(); string colno = dt.Rows[i][10].ToString(); string celldefid = dt.Rows[i][11].ToString(); string rptinstid = dt.Rows[i][12].ToString(); string celltype = dt.Rows[i][13].ToString(); string lastupdatetime = dt.Rows[i][14].ToString(); string lastupdateuserid = dt.Rows[i][15].ToString(); string formula = dt.Rows[i][16].ToString(); string comment = dt.Rows[i][17].ToString(); DataGrid_IS.Add(new ReportCellInstList(cellinstid, cellorginstvalue, cellinstvalue, cellinstexpression, cellinstdetailexpression, cellvalueunit, cellvaluedecimalplace, createmode, sheetno, rowno, colno, celldefid, rptinstid, celltype, lastupdatetime, lastupdateuserid, formula, comment)); } _dt = dt; OnPropertyChanged("DataGrid_IS"); InquiryIsEnable = false; PrintIsEnable = true; OnPropertyChanged("InquiryIsEnable"); OnPropertyChanged("PrintIsEnable"); } } else { MessageBox.Show("Report ID doesn't exist", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } #endregion inputinfo_isenable = false; OnPropertyChanged("inputinfo_isenable"); } #region else { var date = DateTime.ParseExact(DateTime.Parse(date_t).ToString("yyyyMMdd"), "yyyyMMdd", CultureInfo.CurrentCulture); //var dt = _proxy.GetArCellInst_NHibernate(cellid_t.Trim(' '), date.Date.ToString("yyyyMMdd")); //var dtLength = dt.Rows.Count; var dt_cellidandrptid = _proxy.GetCell_NHibernate("Query_for_CellID" + cellid_t.Trim(' ')); var rptdefid = dt_cellidandrptid.Rows[0][13].ToString(); reportid_t = rptdefid; OnPropertyChanged("reportid_t"); var dt_rpt = _proxy.GetArReportInst_NHibernate(reportid_t.Trim(' '), date.Date.ToString("yyyyMMdd")); var dt_rptLength = dt_rpt.Rows.Count; if (dt_rptLength > 0) { var _rptinstid = dt_rpt.Rows[0][0].ToString(); var dt = _proxy.GetArCellInst_NHibernate(_rptinstid.Trim(' ')); var dtLength = dt.Rows.Count; DataTable dtnew = dt.Clone(); for (int i = 0; i < dtLength; i++) { if (dt.Rows[i][11].ToString() == cellid_t.Trim(' ')) { string cellinstid = dt.Rows[i][0].ToString(); string cellorginstvalue = dt.Rows[i][1].ToString(); string cellinstvalue = dt.Rows[i][2].ToString(); string cellinstexpression = dt.Rows[i][3].ToString(); string cellinstdetailexpression = dt.Rows[i][4].ToString(); string cellvalueunit = dt.Rows[i][5].ToString(); string cellvaluedecimalplace = dt.Rows[i][6].ToString(); string createmode = dt.Rows[i][7].ToString(); string sheetno = dt.Rows[i][8].ToString(); string rowno = dt.Rows[i][9].ToString(); string colno = dt.Rows[i][10].ToString(); string celldefid = dt.Rows[i][11].ToString(); string rptinstid = dt.Rows[i][12].ToString(); string celltype = dt.Rows[i][13].ToString(); string lastupdatetime = dt.Rows[i][14].ToString(); string lastupdateuserid = dt.Rows[i][15].ToString(); string formula = dt.Rows[i][16].ToString(); string comment = dt.Rows[i][17].ToString(); DataGrid_IS.Add(new ReportCellInstList(cellinstid, cellorginstvalue, cellinstvalue, cellinstexpression, cellinstdetailexpression, cellvalueunit, cellvaluedecimalplace, createmode, sheetno, rowno, colno, celldefid, rptinstid, celltype, lastupdatetime, lastupdateuserid, formula, comment)); dtnew.ImportRow(dt.Rows[i]); } } OnPropertyChanged("DataGrid_IS"); _dt = dtnew; InquiryIsEnable = false; PrintIsEnable = true; OnPropertyChanged("InquiryIsEnable"); OnPropertyChanged("PrintIsEnable"); inputinfo_isenable = false; OnPropertyChanged("inputinfo_isenable"); } else if (dt_rptLength == 0) { MessageBox.Show("Cell ID doesn't exist", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } #endregion } #region else { MessageBox.Show("Please select a date!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } #endregion } catch (Exception ex) { Log.Error(ex); MessageBox.Show(ex.ToString()); } finally { Log.Info("OK"); Mouse.OverrideCursor = System.Windows.Input.Cursors.Arrow; } } #endregion ServiceCommand_Open #region ServiceCommand_Cancel private ICommand _serviceCommand_Cancel; public ICommand ServiceCommand_Cancel { get { return _serviceCommand_Cancel ?? (_serviceCommand_Cancel = CommandFactory.CreateCommand<object>(ServiceMethod_Cancel)); } } private void ServiceMethod_Cancel(object parameter) { Cancel_All(); } #endregion ServiceCommand_Cancel private string _dateT; private void Cancel_All() { inputinfo_isenable = true; OnPropertyChanged("inputinfo_isenable"); cellid_t = ""; reportid_t = ""; date_t = ""; OnPropertyChanged("cellid_t"); OnPropertyChanged("reportid_t"); OnPropertyChanged("date_t"); DataGrid_IS = new ObservableCollection<ReportCellInstList>(); InquiryIsEnable = true; PrintIsEnable = false; UpdateVisibility = Visibility.Collapsed; DeleteVisibility = Visibility.Collapsed; PrintVisibility = Visibility.Visible; OnPropertyChanged("DataGrid_IS"); OnPropertyChanged("InquiryIsEnable"); OnPropertyChanged("PrintIsEnable"); OnPropertyChanged("UpdateVisibility"); OnPropertyChanged("DeleteVisibility"); OnPropertyChanged("PrintVisibility"); } #region ServiceCommand_CellID private ICommand _serviceCommand_CellID; public ICommand ServiceCommand_CellID { get { return _serviceCommand_CellID ?? (_serviceCommand_CellID = CommandFactory.CreateCommand<object>(ServiceMethod_CellID)); } } private void ServiceMethod_CellID(object parameter) { try { //Inquiry_CellID_Form icForm = new Inquiry_CellID_Form(_proxy); //var result = icForm.ShowDialog(); //if (result == DialogResult.OK) //{ // string cellid = icForm.cellId; // cellid_t = cellid; // OnPropertyChanged("cellid_t"); //} var inquiryCellId = new Window { Content = new InquiryCellIdView(_inquiryCellIdViewVm), Title = "Inquiry Cell Def ID", Width = 540, Height = 300, MinWidth = 540, MinHeight = 300 }; inquiryCellId.ShowDialog(); if (_inquiryCellIdViewVm.IsDoubleClick) { cellid_t = _inquiryCellIdViewVm.GetCellId; reportid_t = _inquiryCellIdViewVm.GetRptDefId; OnPropertyChanged("cellid_t"); OnPropertyChanged("reportid_t"); } _inquiryCellIdViewVm.CancelAll(); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.ToString()); } } #endregion ServiceCommand_CellID #region ServiceCommand_ReportID private ICommand _serviceCommand_ReportID; public ICommand ServiceCommand_ReportID { get { return _serviceCommand_ReportID ?? (_serviceCommand_ReportID = CommandFactory.CreateCommand<object>(ServiceMethod_ReportID)); } } private void ServiceMethod_ReportID(object parameter) { try { //Inquiry_ReportID_Form irForm = new Inquiry_ReportID_Form(_proxy); //var result = irForm.ShowDialog(); //if (result == DialogResult.OK) //{ // string reportid = irForm.reportId; // reportid_t = reportid; // OnPropertyChanged("reportid_t"); //} var inquiryReportId = new Window { Content = new InquiryReportIdView(_inquiryReportIdViewVm), Title = "Inquiry Report Cell ID", Width = 540, Height = 300, MinWidth = 540, MinHeight = 300 }; inquiryReportId.ShowDialog(); if (_inquiryReportIdViewVm.IsDoubleClick) { reportid_t = _inquiryReportIdViewVm.GetReportId; OnPropertyChanged("reportid_t"); } _inquiryReportIdViewVm.CancelAll(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } #endregion ServiceCommand_ReportID #region ServiceCommand_Print private ICommand _serviceCommand_Print; public ICommand ServiceCommand_Print { get { return _serviceCommand_Print ?? (_serviceCommand_Print = CommandFactory.CreateCommand<object>(ServiceMethod_Print)); } } private void ServiceMethod_Print(object parameter) { //PrintDialog printDialog = new PrintDialog(); //if (printDialog.ShowDialog() == false) // return; //string documentTitle = "Test Document"; //System.Windows.Size pageSize = new System.Windows.Size(printDialog.PrintableAreaWidth, printDialog.PrintableAreaHeight); //CustomDataGridDocumentPaginator paginator = new CustomDataGridDocumentPaginator(parameter as System.Windows.Controls.DataGrid, documentTitle, pageSize, new Thickness(10, 10, 10, 10)); //printDialog.PrintDocument(paginator, "Grid"); try { var forcezipSetting = _proxy.GetAppSettings("ForceZip") ?? "N"; var forcezip = forcezipSetting.ToUpper() == "Y"; var prefixzip = _proxy.GetAppSettings("PrefixZip") ?? ""; var p2E = new PrintToExcel(_dt, "ReportCellDefinition_" + DateTime.Now.ToString("yyyyMMdd"), forcezip, prefixzip); p2E.Print(); //var lists = new ReportCellLists(); //foreach (var temp in DataGrid_IS.Select(t => new ReportCellList(t.CELL_ID, t.CELL_EXPRESSION, // t.CELL_Detail_EXPRESSION, t.CELL_Description, // t.Cell_Value_Unit, t.Cell_Value_Decimal_Place, // t.External_Ref_ID, t.RPT_ID, t.Sheet_No, // t.Row_No, // t.Col_No, t.Last_Update_Time, t.Last_Update_Userid))) //{ // lists.Add(temp); //} //var s = new ExportToExcel<ReportCellList>(); //var view = CollectionViewSource.GetDefaultView(lists); //s.dataToPrint = (ReportCellLists)view.SourceCollection; //s.GenerateReport(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } #endregion ServiceCommand_Print } public class ReportCellInstList : INotifyPropertyChanged { public string CELL_INST_ID { get; set; } public string CELL_ORG_INST_VALUE { get; set; } public string CELL_INST_VALUE { get; set; } public string CELL_INST_EXPRESSION { get; set; } public string CELL_INST_DETAIL_EXPRESSION { get; set; } public string CELL_VALUE_UNIT { get; set; } public string CELL_VALUE_DECIMAL_PLACE { get; set; } public string CREATE_MODE { get; set; } public string SHEET_NO { get; set; } public string ROW_NO { get; set; } public string COL_NO { get; set; } public string CELL_DEF_ID { get; set; } public string RPT_INST_ID { get; set; } public string CELL_TYPE { get; set; } public string LAST_UPDATE_TIME { get; set; } public string LAST_UPDATE_USERID { get; set; } public string FORMULA { get; set; } public string COMMENT { get; set; } public ReportCellInstList(string cellinstid, string cellorginstvalue, string cellinstvalue, string cellinstexpression, string cellinstdetailexpression, string cellvalueunit, string cellvaluedecimalplace, string createmode, string sheetno, string rowno, string colno, string celldefid, string rptinstid, string celltype, string lastupdatetime, string lastupdateuserid, string formula, string comment) { CELL_INST_ID = cellinstid; CELL_ORG_INST_VALUE = cellorginstvalue; CELL_INST_VALUE = cellinstvalue; CELL_INST_EXPRESSION = cellinstexpression; CELL_INST_DETAIL_EXPRESSION = cellinstdetailexpression; CELL_VALUE_UNIT = cellvalueunit; CELL_VALUE_DECIMAL_PLACE = cellvaluedecimalplace; CREATE_MODE = createmode; SHEET_NO = sheetno; ROW_NO = rowno; COL_NO = colno; CELL_DEF_ID = celldefid; RPT_INST_ID = rptinstid; CELL_TYPE = celltype; LAST_UPDATE_TIME = Sm.DateTimeConvert(DateTime.Parse(lastupdatetime)).ToString(CultureInfo.CurrentCulture); LAST_UPDATE_USERID = lastupdateuserid; FORMULA = formula; COMMENT = comment; } #region INotifyPropertyChanged Members //20210831 Dead Code: Unused Method, to public public void NotifyPropertyChanged(string info) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(info)); } } public event PropertyChangedEventHandler PropertyChanged; #endregion } } ``` ## (child view)InquiryCellIdView頁面增加欄位 (ViewModel) 在`InquiryCellIdView_VM.cs` 增加reportid欄位 `var rptdefid = dt.Rows[i][13].ToString();` ```C# private void ServiceMethod_CellID(object parameter) { try { DataGridIs = new ObservableCollection<InquiyCellColumn>(); var dt = new DataTable(); if (string.IsNullOrEmpty(Input_t) || string.IsNullOrWhiteSpace(Input_t)) dt = _proxy.GetCell_NHibernate(""); else { if (QueryType == 0) { dt = _proxy.GetCell_NHibernate("Query_for_CellID" + Input_t.Trim(' ')); } else if (QueryType == 1) { dt = _proxy.GetCell_NHibernate("Query_for_CellName" + Input_t.Trim(' ')); } } var dtLength = dt.Rows.Count; for (var i = 0; i < dtLength; i++) { var cellid = dt.Rows[i][0].ToString(); var cellname = dt.Rows[i][1].ToString(); var rptdefid = dt.Rows[i][13].ToString(); DataGridIs.Add(new InquiyCellColumn(cellid, cellname, rptdefid)); } OnPropertyChanged("DataGridIs"); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } ``` ## (child view)InquiryCellIdView頁面增加欄位 (View) 在`InquiryCellIdView.xaml.cs` 增加 `_InquiryCellIdView_VM.GetRptDefId = RptDefId;` 使拿到的值可以回傳到 Inquiry_Cell_Instance 的頁面並自動填入 ```C# private void DataGridRow_MouseDoubleClick(object sender, MouseButtonEventArgs e) { if (DataGrid.SelectedItem == null) return; var selectedItem = DataGrid.SelectedItem as InquiyCellColumn; if (selectedItem != null) { CellId = selectedItem.CellId; RptDefId = selectedItem.RptDefId; } _InquiryCellIdView_VM.GetCellId = CellId; _InquiryCellIdView_VM.GetRptDefId = RptDefId; _InquiryCellIdView_VM.IsDoubleClick = true; Window.GetWindow(this).Close(); } ``` ## NHibernate servive method - `SampleService.cs` 增加 GetArCellInst_NHibernate ```c# public DataTable GetArCellInst_NHibernate(string parameter) { DataTable dt = new DataTable(); dt.Columns.Add("CELL_INST_ID"); dt.Columns.Add("CELL_ORG_INST_VALUE"); dt.Columns.Add("CELL_INST_VALUE"); dt.Columns.Add("CELL_INST_EXPRESSION"); dt.Columns.Add("CELL_INST_DETAIL_EXPRESSION"); dt.Columns.Add("CELL_VALUE_UNIT"); dt.Columns.Add("CELL_VALUE_DECIMAL_PLACE"); dt.Columns.Add("CREATE_MODE"); dt.Columns.Add("SHEET_NO"); dt.Columns.Add("ROW_NO"); dt.Columns.Add("COL_NO"); dt.Columns.Add("CELL_DEF_ID"); dt.Columns.Add("RPT_INST_ID"); dt.Columns.Add("CELL_TYPE"); dt.Columns.Add("LAST_UPDATE_TIME"); dt.Columns.Add("LAST_UPDATE_USERID"); dt.Columns.Add("FORMULA"); dt.Columns.Add("COMMENT"); dt.TableName = "DataTableName"; using (var _session = _databaseFactory.CreateDatabaseSession()) { var arcellinst = _session.GetRepository<ArCellInst>(); if (string.IsNullOrEmpty(parameter)) //Query All { //Expression<Func<ArCellInst, bool>> expr = item => item.LastUpdateTime.Date.ToString("yyyyMMdd") == date; //var basicquery = arcellinst.FilterBy(expr); var basicquery = (from reportCtrl in arcellinst.All() select reportCtrl); foreach (var reportCtrl in basicquery) { DataRow row = dt.NewRow(); row["CELL_INST_ID"] = reportCtrl.CellInstId; row["CELL_ORG_INST_VALUE"] = reportCtrl.CellOrgInstValue; row["CELL_INST_VALUE"] = reportCtrl.CellInstValue; row["CELL_INST_EXPRESSION"] = reportCtrl.CellInstExpression; row["CELL_INST_DETAIL_EXPRESSION"] = reportCtrl.CellInstDetailExpression; row["CELL_VALUE_UNIT"] = reportCtrl.CellValueUnit; row["CELL_VALUE_DECIMAL_PLACE"] = reportCtrl.CellValueDecimalPlace; row["CREATE_MODE"] = reportCtrl.CreateMode; row["SHEET_NO"] = reportCtrl.SheetNo; row["ROW_NO"] = reportCtrl.RowNo; row["COL_NO"] = reportCtrl.ColNo; row["CELL_DEF_ID"] = reportCtrl.CellDefId; row["RPT_INST_ID"] = reportCtrl.RptInstId; row["CELL_TYPE"] = reportCtrl.CellType; row["LAST_UPDATE_TIME"] = reportCtrl.LastUpdateTime; row["LAST_UPDATE_USERID"] = reportCtrl.LastUpdateUserid; row["FORMULA"] = reportCtrl.Formula; row["COMMENT"] = reportCtrl.Comment; dt.Rows.Add(row); //break; } } //else if (parameter.Contains("Query_for_CellID")) //{ // Expression<Func<ArCellInst, bool>> expr = // item => item.AttrId.StartsWith(parameter.Replace("Query_for_AttrID", "")); // var basicquery = attribute.FilterBy(expr); //} else //Query Parameter { Expression<Func<ArCellInst, bool>> filter = item => item.RptInstId.ToString() == parameter; //Expression<Func<ArCellInst, bool>> filter2 = item => item.LastUpdateTime.Date.ToString("yyyyMMdd") == date; //filter = CombineExpressionAndAlso(filter, filter2); var basicquery = arcellinst.FilterBy(filter); foreach (var reportCtrl in basicquery) { DataRow row = dt.NewRow(); row["CELL_INST_ID"] = reportCtrl.CellInstId; row["CELL_ORG_INST_VALUE"] = reportCtrl.CellOrgInstValue; row["CELL_INST_VALUE"] = reportCtrl.CellInstValue; row["CELL_INST_EXPRESSION"] = reportCtrl.CellInstExpression; row["CELL_INST_DETAIL_EXPRESSION"] = reportCtrl.CellInstDetailExpression; row["CELL_VALUE_UNIT"] = reportCtrl.CellValueUnit; row["CELL_VALUE_DECIMAL_PLACE"] = reportCtrl.CellValueDecimalPlace; row["CREATE_MODE"] = reportCtrl.CreateMode; row["SHEET_NO"] = reportCtrl.SheetNo; row["ROW_NO"] = reportCtrl.RowNo; row["COL_NO"] = reportCtrl.ColNo; row["CELL_DEF_ID"] = reportCtrl.CellDefId; row["RPT_INST_ID"] = reportCtrl.RptInstId; row["CELL_TYPE"] = reportCtrl.CellType; row["LAST_UPDATE_TIME"] = reportCtrl.LastUpdateTime; row["LAST_UPDATE_USERID"] = reportCtrl.LastUpdateUserid; row["FORMULA"] = reportCtrl.Formula; row["COMMENT"] = reportCtrl.Comment; dt.Rows.Add(row); //break; } } _session.Dispose(); } return dt; } ``` 增加 GetArReportInst_NHibernate ```C# public DataTable GetArReportInst_NHibernate(string parameter, string date) { DataTable dt = new DataTable(); dt.Columns.Add("RPT_INST_ID"); dt.Columns.Add("BRANCH"); dt.Columns.Add("HANDLE_DATE"); dt.Columns.Add("DATA_VERSION"); dt.Columns.Add("CREATE_MODE"); dt.Columns.Add("RPT_DEF_ID"); dt.Columns.Add("CURRENT_VERSION"); dt.Columns.Add("STATUS"); dt.Columns.Add("CREATED_BY"); dt.Columns.Add("VERIFIED_BY"); dt.Columns.Add("CREATED_TIME"); dt.Columns.Add("LAST_UPDATE_TIME"); dt.Columns.Add("LAST_UPDATE_USERID"); dt.TableName = "DataTableName"; using (var _session = _databaseFactory.CreateDatabaseSession()) { var arreportinst = _session.GetRepository<ArReportInst>(); if (string.IsNullOrEmpty(parameter)) //Query All { //Expression<Func<ArReportInst, bool>> expr = item => item.LastUpdateTime.Date == date.Date; Expression<Func<ArReportInst, bool>> expr = item => item.LastUpdateTime.Date.ToString("yyyyMMdd") == date; var basicquery = arreportinst.FilterBy(expr); foreach (var reportCtrl in basicquery) { DataRow row = dt.NewRow(); row["RPT_INST_ID"] = reportCtrl.ReportInstanceId; row["BRANCH"] = reportCtrl.Branch; row["HANDLE_DATE"] = reportCtrl.HandleDate; row["DATA_VERSION"] = reportCtrl.DataVersion; row["CREATE_MODE"] = reportCtrl.CreateMode; row["RPT_DEF_ID"] = reportCtrl.RptDefId; row["CURRENT_VERSION"] = reportCtrl.CurrentVersion; row["STATUS"] = reportCtrl.Status; row["CREATED_BY"] = reportCtrl.CreatedBy; row["VERIFIED_BY"] = reportCtrl.VerifiedBy; row["CREATED_TIME"] = reportCtrl.CreatedTime; row["LAST_UPDATE_TIME"] = reportCtrl.LastUpdateTime; row["LAST_UPDATE_USERID"] = reportCtrl.LastUpdateUserid; dt.Rows.Add(row); //break; } } else //Query Parameter { Expression<Func<ArReportInst, bool>> filter = item => item.ArReportCtrl.ReportDefinitionId == parameter; Expression<Func<ArReportInst, bool>> filter2 = item => item.ArReportCtrl.HandleDate == date; filter = CombineExpressionAndAlso(filter, filter2); var basicquery = arreportinst.FilterBy(filter); foreach (var reportCtrl in basicquery) { DataRow row = dt.NewRow(); row["RPT_INST_ID"] = reportCtrl.ReportInstanceId; row["BRANCH"] = reportCtrl.Branch; row["HANDLE_DATE"] = reportCtrl.HandleDate; row["DATA_VERSION"] = reportCtrl.DataVersion; row["CREATE_MODE"] = reportCtrl.CreateMode; row["RPT_DEF_ID"] = reportCtrl.RptDefId; row["CURRENT_VERSION"] = reportCtrl.CurrentVersion; row["STATUS"] = reportCtrl.Status; row["CREATED_BY"] = reportCtrl.CreatedBy; row["VERIFIED_BY"] = reportCtrl.VerifiedBy; row["CREATED_TIME"] = reportCtrl.CreatedTime; row["LAST_UPDATE_TIME"] = reportCtrl.LastUpdateTime; row["LAST_UPDATE_USERID"] = reportCtrl.LastUpdateUserid; dt.Rows.Add(row); //break; } } _session.Dispose(); } return dt; } ``` - `ISampleService.cs` ```c# [OperationContract] [FaultContract(typeof(ServiceFault))] DataTable GetArReportInst_NHibernate(string parameter, string date); [OperationContract] [FaultContract(typeof(ServiceFault))] DataTable GetArCellInst_NHibernate(string parameter); ``` - `SampleServiceClient.cs` ```C# public DataTable GetArReportInst_NHibernate(string parameter, string date) { return Channel.GetArReportInst_NHibernate(parameter, date); } public DataTable GetArCellInst_NHibernate(string parameter) { return Channel.GetArCellInst_NHibernate(parameter); } ``` ## DB access and page setting ```sql INSERT INTO [TBBHK_Nuntio].[dbo].[ARITEM] VALUES ('AP0007', 'A', 'Inquiry Cell Instance', 'APForm6', '', 'SampleModule', 'ares.client.module.View.Inquiry_Cell_Instance, ares.client.module', '','','0002') INSERT INTO [TBBHK_Nuntio].[dbo].[ARITRO] VALUES ('ARES', 'AP0007', 'V', '2017-12-06 19:44:14.503', 'DaN') ``` ``` <StackPanel Grid.Row="1" Orientation="Horizontal" Margin="11,101,10,0"> <editors:XamComboEditor x:Name="Pagersize" HorizontalAlignment="Left" VerticalAlignment="Top" Width="50" HorizontalContentAlignment="Center" Text="10" FontWeight="Bold"> <editors:XamComboEditor.ItemsProvider> <editors:ComboBoxItemsProvider> <editors:ComboBoxItemsProvider.Items> <editors:ComboBoxDataItem DisplayText="10" Value="10" /> <editors:ComboBoxDataItem DisplayText="20" Value="20" /> <editors:ComboBoxDataItem DisplayText="30" Value="30"/> </editors:ComboBoxItemsProvider.Items> </editors:ComboBoxItemsProvider> </editors:XamComboEditor.ItemsProvider> </editors:XamComboEditor> <Label Content="records per page" HorizontalAlignment="Left" VerticalAlignment="Top" FontWeight="Bold"/> </StackPanel> ```