Avalonia 資料列表元件 [Avalonia DataGrid 四欄位 範例]
Avalonia 資料列表元件 [Avalonia DataGrid 四欄位 範例]
資料來源: copilot
https://docs.avaloniaui.net/docs/reference/controls/datagrid/
copilot~xaml
<Window xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:YourNamespace" x:Class="YourNamespace.MainWindow" Title="Avalonia DataGrid 範例" Width="600" Height="400"> <DataGrid x:Name="MyDataGrid" AutoGenerateColumns="False" Items="{Binding DataItems}"> <DataGrid.Columns> <DataGridTextColumn Header="Name" Binding="{Binding Name}" Width="*"/> <DataGridTextColumn Header="Value" Binding="{Binding Value}" Width="*"/> <DataGridTextColumn Header="Description" Binding="{Binding Description}" Width="*"/> <DataGridTextColumn Header="Date" Binding="{Binding Date}" Width="*"/> </DataGrid.Columns> </DataGrid> </Window>
copilot~code
using Avalonia; using Avalonia.Controls; using Avalonia.Markup.Xaml; using System; using System.Collections.ObjectModel; namespace YourNamespace { public class MainWindow : Window { public ObservableCollection<DataItem> DataItems { get; set; } public MainWindow() { InitializeComponent(); #if DEBUG this.AttachDevTools(); #endif DataItems = new ObservableCollection<DataItem> { new DataItem { Name = "項目 1", Value = 1, Description = "描述 1", Date = DateTime.Now }, new DataItem { Name = "項目 2", Value = 2, Description = "描述 2", Date = DateTime.Now.AddDays(1) }, new DataItem { Name = "項目 3", Value = 3, Description = "描述 3", Date = DateTime.Now.AddDays(2) } }; DataContext = this; } private void InitializeComponent() { AvaloniaXamlLoader.Load(this); } } public class DataItem { public string Name { get; set; } public int Value { get; set; } public string Description { get; set; } public DateTime Date { get; set; } } }
============
reference~xaml
<DataGrid Margin="20" ItemsSource="{Binding People}" GridLinesVisibility="All" BorderThickness="1" BorderBrush="Gray"> <DataGrid.Columns> <DataGridTextColumn Header="First Name" Binding="{Binding FirstName}"/> <DataGridTextColumn Header="Last Name" Binding="{Binding LastName}" /> <DataGridCheckBoxColumn Header="Fictitious?" Binding="{Binding IsFictitious}" /> </DataGrid.Columns> </DataGrid>
reference~code
public class Person { public string FirstName { get; set; } public string LastName { get; set; } public bool IsFictitious { get; set; } public Person(string firstName , string lastName, bool isFictitious) { FirstName = firstName; LastName = lastName; IsFictitious = isFictitious; } } using AvaloniaControls.Models; using System.Collections.Generic; using System.Collections.ObjectModel; namespace AvaloniaControls.ViewModels { public class MainWindowViewModel : ViewModelBase { public ObservableCollection<Person> People { get; } public MainWindowViewModel() { var people = new List<Person> { new Person("Neil", "Armstrong", false), new Person("Buzz", "Lightyear", true), new Person("James", "Kirk", true) }; People = new ObservableCollection<Person>(people); } } }
============
安裝元件 (Avalonia.Controls.DataGrid ~ NuGet UI 可以安裝)
dotnet add package Avalonia.Controls.DataGrid
實際範例(App.axaml)
<Application xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="VPOS_Avalonia.App" RequestedThemeVariant="Default"> <!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. --> <Application.Styles> <FluentTheme /> <!-- https://github.com/AvaloniaUI/Avalonia/discussions/8424 --> <StyleInclude Source="avares://Avalonia.Controls.DataGrid/Themes/Fluent.xaml"/> </Application.Styles> </Application>
實際範例(OrderStagingListViewModel.cs)
using Avalonia.Media.Imaging; using Avalonia.Platform; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; using VPOS; namespace VPOS_Avalonia.ViewModels; public class OrderStagingListItem : INotifyPropertyChanged //ListBox 程式刷新顯示資料 { public String order_no { get; set; } public String order_open_time { get; set; } public String order_type_name { get; set; } public String table_name { get; set; } public String item_count { get; set; } public String subtotal { get; set; } public String amount { get; set; } public String remarks { get; set; } public String order_type_code { get; set; }//(order_type + "," + order_type_code) public String guests_num { get; set; } public event PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanged(string propertyName) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } } public partial class OrderStagingListViewModel : ViewModelBase { public ObservableCollection<ShopcartItem> m_ShopcartItems { get; set; } = new ObservableCollection<ShopcartItem>(); public ObservableCollection<OrderStagingListItem> m_OrderStagingListItems { get; set; } = new BulkObservableCollection<OrderStagingListItem>(); public string[] m_StrShopcartIcons = new string[5] { "checkbox00.png", "checkbox01.png", "blank.png", "add.png", "up_arrow.png" }; public Bitmap[] m_BmpShopcartIcons = new Bitmap[5]; public OrderStagingListViewModel() { m_ShopcartItems = new ObservableCollection<ShopcartItem>(); m_OrderStagingListItems = new ObservableCollection<OrderStagingListItem>(); for (int i = 0; i < m_StrShopcartIcons.Length; i++) { var stream = AssetLoader.Open(new Uri($"avares://VPOS_Avalonia/Assets/{m_StrShopcartIcons[i]}"));//確定會變化實驗資料 m_BmpShopcartIcons[i] = new Bitmap(stream);//確定會變化實驗資料 } } }
實際範例(OrderStagingList.axaml)
<Window xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" xmlns:avaloniaControls="clr-namespace:Avalonia.Controls;assembly=Avalonia.Controls.DataGrid" xmlns:vm="using:VPOS_Avalonia.ViewModels" x:DataType="vm:OrderStagingListViewModel" x:Class="VPOS_Avalonia.OrderStagingList" Title="VPOS" Loaded="Window_Loaded"> <!-- ViewModels 使用步驟: ▲[固定語法(寫在axaml)] xmlns:vm="using:VPOS_Avalonia.ViewModels" ▲[對應語法(寫在axaml)] x:DataType="vm:OrderStagingListViewModel" ▲[對應語法(寫在axaml)] <Design.DataContext> ▲[對應語法(寫在cs)] DataContext = new OrderStagingListViewModel();//建構子函數中資源檔載入[InitializeComponent();]前必須指定ViewModel --> <Design.DataContext> <vm:OrderStagingListViewModel/> </Design.DataContext> <Window.Styles> <Style Selector="ListBoxItem"> <Setter Property="Height" Value="40"/> </Style> <Style Selector="DataGridColumnHeader"> <Setter Property="FontSize" Value="20" /> </Style> <Style Selector="DataGridCell"> <Setter Property="FontSize" Value="20" /> </Style> </Window.Styles> <Border BorderBrush="LightBlue" BorderThickness="5" CornerRadius="10" Margin="-3"> <Grid x:Name="FullGrid" RowDefinitions="0.6*,10.1*,1.3*" ColumnDefinitions="*" > <Border BorderBrush="Blue" BorderThickness="1" CornerRadius="10" Margin="0" Grid.Row="0" Grid.Column="0"> <Grid x:Name="HeadGrid" RowDefinitions="*" ColumnDefinitions="*"> <TextBlock x:Name="TitleLable" Text="訂單暫存" Foreground="White" FontSize="22" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Center" /> <Button x:Name="CloseBtn" Content="X" Grid.Row="0" Grid.Column="0" FontSize="20" Background="Transparent" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="0,0,10,0" Click="CloseBtn_Clicked"/> </Grid><!--HeadGrid End--> </Border> <Grid x:Name="BodyGrid" Grid.Row="1" RowDefinitions="*" ColumnDefinitions="6*,5*" Margin="5,5,5,5"> <Border BorderBrush="White" BorderThickness="1" CornerRadius="10" Margin="5" Grid.Row="0" Grid.Column="0"> <avaloniaControls:DataGrid x:Name="dgInfo" Margin="5" ItemsSource="{Binding m_OrderStagingListItems}" Background="White" RowHeight="40" IsReadOnly="True" CanUserReorderColumns="False" CanUserResizeColumns="False" CanUserSortColumns="True" GridLinesVisibility="All" BorderThickness="1" BorderBrush="Gray" IsVisible="True" SelectionChanged="dgInfo_SelectionChanged"> <avaloniaControls:DataGrid.Columns> <avaloniaControls:DataGridTextColumn Width="200" Header="訂單編號" Binding="{Binding order_no}" /> <avaloniaControls:DataGridTextColumn Width="250" Header="開單時間" Binding="{Binding order_open_time}" /> <avaloniaControls:DataGridTextColumn Width="125" Header="訂單類型" Binding="{Binding order_type_name}" /> <avaloniaControls:DataGridTextColumn Width="125" Header="桌號" Binding="{Binding table_name}" /> <avaloniaControls:DataGridTextColumn Width="125" Header="數量" Binding="{Binding item_count}" /> <avaloniaControls:DataGridTextColumn Width="125" Header="小計" Binding="{Binding subtotal}" /> <avaloniaControls:DataGridTextColumn Width="125" Header="合計金額" Binding="{Binding amount}" /> <avaloniaControls:DataGridTextColumn Width="125" Header="備註" Binding="{Binding remarks}" /> </avaloniaControls:DataGrid.Columns> </avaloniaControls:DataGrid> </Border> <Grid x:Name="RightBodyGrid" RowDefinitions="14*,3*" ColumnDefinitions="*" Grid.Row="0" Grid.Column="1" Margin="5,5,5,0"> <ScrollViewer Grid.Row="0" Grid.Column="0" VerticalScrollBarVisibility="Visible"> <ListBox x:Name="ShopcartListView" ItemsSource="{Binding m_ShopcartItems}" SelectionMode="Single" Background="White" SelectionChanged="ShopcartListView_ItemSelected"> <ListBox.ItemTemplate> <DataTemplate> <!-- ListView 資料結構標準: ListView.ItemTemplate -> DataTemplate -> ViewCell--> <Grid Height="45" Background="{Binding BColor}" ColumnDefinitions="30,15,4.4*,0.7*,1*,1.2*,7" Margin="-10,0,-10,0"> <Image Source="{Binding Image00}" Width="20" Height="20" Grid.Column="0" PointerPressed="ShopcartListViewImage00_Clicked" /> <Image Source="{Binding Image01}" Width="10" Height="10" Grid.Column="1" PointerPressed="ShopcartListViewImage01_Clicked" /> <TextBlock Text="{Binding Name}" FontSize="{Binding Font_Size}" HorizontalAlignment="Stretch" TextAlignment="{Binding NameTextAlignment}" VerticalAlignment="Center" Foreground="{Binding Font_Color}" Grid.Column="2"/> <TextBlock Text="{Binding Amount}" FontSize="{Binding Font_Size}" HorizontalAlignment="Left" VerticalAlignment="Center" Foreground="{Binding Font_Color}" Grid.Column="3"/> <TextBlock Text="{Binding Price}" FontSize="{Binding Font_Size}" HorizontalAlignment="Left" VerticalAlignment="Center" Foreground="{Binding Font_Color}" Grid.Column="4"/> <TextBlock Text="{Binding Sum}" FontSize="{Binding Font_Size}" HorizontalAlignment="Right" VerticalAlignment="Center" Foreground="{Binding Font_Color}" Grid.Column="5"/> <TextBlock Text="" FontSize="20" Foreground="Transparent"/> </Grid> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </ScrollViewer> <Border x:Name="RightDownBodyBorder" BorderBrush="White" BorderThickness="1" CornerRadius="10" Margin="5,20,5,5" Grid.Row="1" Grid.Column="0"> <TextBox x:Name="remarks" FontSize="20" Foreground="MediumBlue" Background="#FFFFDF" Grid.Column="1" Margin="10,12,10,10" IsReadOnly="True"/> </Border> <TextBlock x:Name="RightDownBodyTextBlock" Background="#194a6e" Foreground="White" FontSize="20" Text="訂單備註" Grid.Row="1" Grid.Column="0" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="25,5,0,0" /> </Grid><!--RightBodyGrid End--> </Grid><!--BodyGrid End--> <Grid x:Name="FooterGrid" RowDefinitions="*" ColumnDefinitions="0.5*,*,*,2*,*,*,0.5*" Margin="30,0,30,20" Grid.Row="2" Grid.Column="0" > <Button x:Name="FooterBtn01" Margin="15,0,15,0" Height="50" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" HorizontalAlignment="Stretch" Content="列印" Foreground="White" Background="#cc6600" Grid.Row="0" Grid.Column="1" Click="FooterBtn01_Clicked"/> <Button x:Name="FooterBtn02" Margin="15,0,15,0" Height="50" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" HorizontalAlignment="Stretch" Content="暫存取回" Foreground="White" Background="#cc6600" Grid.Row="0" Grid.Column="2" Click="FooterBtn02_Clicked"/> <Button x:Name="FooterBtn03" Margin="15,0,15,0" Height="50" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" HorizontalAlignment="Stretch" Content="刪除暫存單" Foreground="White" Background="#cc6600" Grid.Row="0" Grid.Column="4" Click="FooterBtn03_Clicked"/> <Button x:Name="FooterBtn04" Margin="15,0,15,0" Height="50" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" HorizontalAlignment="Stretch" Content="離開" Foreground="White" Background="#cc6600" Grid.Row="0" Grid.Column="5" Click="CloseBtn_Clicked"/> </Grid> </Grid><!--FullGrid End--> </Border> </Window>
實際範例(OrderStagingList.cs)
using Avalonia; using Avalonia.Controls; using Avalonia.Input; using Avalonia.Interactivity; using Avalonia.Markup.Xaml; using Avalonia.Media; using System; using System.Collections.Generic; using System.Data; using System.Text.RegularExpressions; using VPOS; using VPOS_Avalonia.ViewModels; using VPOS_Avalonia.Views; namespace VPOS_Avalonia; public partial class OrderStagingList : Window { public static bool m_blnRun = false; public static string m_StrResult = ""; private DataTable m_orderdataDataTable = new DataTable(); private String m_StrdgvInforSelectOrderNo = ""; private String m_StrdgvInforSelectorder_type = ""; private String m_StrdgvInforSelectguests_num = ""; private ShopCart m_ShopCart = null; private String m_StrTab = " "; private String m_StrHalfTab = " "; private DataTable m_ordercontentdataDataTable = new DataTable(); public OrderStagingListItem m_SelectedOrderStagingListItem { get; set; } = new OrderStagingListItem(); public OrderStagingList() { DataContext = new OrderStagingListViewModel();//建構子函數中資源檔載入[InitializeComponent();]前必須指定ViewModel ExternalPopup.orderStagingList = this; m_blnRun = false; //隱藏工具列 this.ExtendClientAreaToDecorationsHint = true; this.ExtendClientAreaTitleBarHeightHint = -1; this.SystemDecorations = SystemDecorations.None; //---隱藏工具列 WindowStartupLocation = WindowStartupLocation.CenterScreen;//視窗置中 this.Background = new SolidColorBrush(Color.Parse("#ff194a6e"));//設定背景色 this.WindowState = WindowState.Maximized;//視窗最大化非滿版 InitializeComponent(); FullGrid.IsVisible = false; } public void Window_Loaded(object sender, RoutedEventArgs e) { FullGrid.IsVisible = true; orderdataGet(); LoadOrderStagingListItems();//載入清單資料//dgvInforShow(); } public void orderdataGet() { String SQL = "SELECT * FROM order_data WHERE order_state=2"; m_orderdataDataTable = SQLDataTableModel.GetDataTable(SQL); } public void ordercontentdataGet() { String SQL = String.Format("SELECT * FROM order_content_data WHERE order_no='{0}' ORDER BY item_no", m_StrdgvInforSelectOrderNo); m_ordercontentdataDataTable = SQLDataTableModel.GetDataTable(SQL); m_ShopCart = new ShopCart(1); if ((m_ordercontentdataDataTable != null) && (m_ordercontentdataDataTable.Rows.Count > 0)) { double dblSubtotal = 0; for (int i = 0; i < m_ordercontentdataDataTable.Rows.Count; i++) { if (m_ordercontentdataDataTable.Rows[i]["item_type"].ToString() != "C")//主項目 { ShopMainList ShopMainListBuf = new ShopMainList(); ShopMainListBuf.m_intImgId = 1;//選擇 ShopMainListBuf.m_intSID = VP_Convert.ToInt32(m_ordercontentdataDataTable.Rows[i]["item_SID"].ToString());//DB唯一值 ShopMainListBuf.m_StrName = m_ordercontentdataDataTable.Rows[i]["item_name"].ToString();//名稱 ShopMainListBuf.m_dblPrice = VP_Convert.ToInt32(m_ordercontentdataDataTable.Rows[i]["item_cost"].ToString());//價格 ShopMainListBuf.m_intAmount = VP_Convert.ToInt32(m_ordercontentdataDataTable.Rows[i]["item_count"].ToString());//數量 ShopMainListBuf.m_dblSum = VP_Convert.ToDouble(m_ordercontentdataDataTable.Rows[i]["item_subtotal"].ToString());//總和 ShopMainListBuf.m_Stritem_type = m_ordercontentdataDataTable.Rows[i]["item_type"].ToString();//類型 ShopMainListBuf.m_Strproduct_code = m_ordercontentdataDataTable.Rows[i]["item_code"].ToString(); ShopMainListBuf.m_intparent_item_no = VP_Convert.ToInt32(m_ordercontentdataDataTable.Rows[i]["parent_item_no"].ToString()); ShopMainListBuf.m_intitem_no = VP_Convert.ToInt32(m_ordercontentdataDataTable.Rows[i]["item_no"].ToString()); ShopMainListBuf.m_Strdel_flag = m_ordercontentdataDataTable.Rows[i]["del_flag"].ToString(); ShopMainListBuf.m_Strdiscount_type = m_ordercontentdataDataTable.Rows[i]["discount_type"].ToString();// 折扣/折讓 旗標 ShopMainListBuf.m_Strdiscount_name = m_ordercontentdataDataTable.Rows[i]["discount_name"].ToString();// 折扣/折讓 說明文字 ShopMainListBuf.m_Strdiscount_code = m_ordercontentdataDataTable.Rows[i]["discount_code"].ToString(); ShopMainListBuf.m_intdiscount_rate = VP_Convert.ToInt32(m_ordercontentdataDataTable.Rows[i]["discount_rate"].ToString());// 折扣率 ShopMainListBuf.m_intdiscount_fee = VP_Convert.ToInt32(m_ordercontentdataDataTable.Rows[i]["discount_fee"].ToString());// 折讓金額 ShopMainListBuf.m_blnSTOCK_PULL = (VP_Convert.ToInt32(m_ordercontentdataDataTable.Rows[i]["stock_pull_price"].ToString()) > 0) ? true : false; ShopMainListBuf.m_Strsubtotal_flag = m_ordercontentdataDataTable.Rows[i]["subtotal_flag"].ToString(); if (((ShopMainListBuf.m_Stritem_type == "P") || (ShopMainListBuf.m_Stritem_type == "T")) && (ShopMainListBuf.m_Strsubtotal_flag == "Y")) { dblSubtotal += (ShopMainListBuf.m_dblSum - ShopMainListBuf.m_intdiscount_fee); } if (ShopMainListBuf.m_Stritem_type == "S") { ShopMainListBuf.m_dblPrice = dblSubtotal; ShopMainListBuf.m_dblSum = dblSubtotal; dblSubtotal = 0; } m_ShopCart.m_ShopMainList.Add(ShopMainListBuf); m_ShopCart.m_intItemNoCount++; if (ShopMainListBuf.m_blnSTOCK_PULL) { ShopMainList ShopMainListBuf01 = new ShopMainList(); ShopMainListBuf01.m_intImgId = 1;//選擇 ShopMainListBuf01.m_intSID = 0;//DB唯一值 ShopMainListBuf01.m_StrName = "【寄庫取回】";//名稱 ShopMainListBuf01.m_dblPrice = VP_Convert.ToInt32(m_ordercontentdataDataTable.Rows[i]["stock_pull_price"].ToString()) * -1;//價格 ShopMainListBuf01.m_intAmount = VP_Convert.ToInt32(m_ordercontentdataDataTable.Rows[i]["stock_pull_quantity"].ToString());//數量 ShopMainListBuf01.m_dblSum = ShopMainListBuf01.m_dblPrice * ShopMainListBuf01.m_intAmount;//總和 ShopMainListBuf01.m_Stritem_type = "STOCK_PULL";//類型 ShopMainListBuf01.m_Strproduct_code = m_ordercontentdataDataTable.Rows[i]["discount_code"].ToString(); ShopMainListBuf01.m_intparent_item_no = 0; ShopMainListBuf01.m_intitem_no = m_ShopCart.m_intItemNoCount; ShopMainListBuf01.m_Strdel_flag = m_ordercontentdataDataTable.Rows[i]["del_flag"].ToString(); ; ShopMainListBuf01.m_Strdiscount_type = "";// 折扣/折讓 旗標 ShopMainListBuf01.m_Strdiscount_name = "";// 折扣/折讓 說明文字 ShopMainListBuf01.m_Strdiscount_code = ""; ShopMainListBuf01.m_intdiscount_rate = 0;// 折扣率 ShopMainListBuf01.m_intdiscount_fee = 0;// 折讓金額 ShopMainListBuf01.m_inttax_sid = 3; ShopMainListBuf01.m_inttax_rate = 5; ShopMainListBuf01.m_Strtax_type = "A"; ShopMainListBuf01.m_blnSTOCK_PULL = true; m_ShopCart.m_ShopMainList.Add(ShopMainListBuf01); m_ShopCart.m_intItemNoCount++; } } else//調味品 { ShopSubList ShopSubListBuf = new ShopSubList(); ShopSubListBuf.m_intImgId = 3;//收合 ShopSubListBuf.m_intSID = VP_Convert.ToInt32(m_ordercontentdataDataTable.Rows[i]["item_SID"].ToString());//DB唯一值 ShopSubListBuf.m_StrName = m_ordercontentdataDataTable.Rows[i]["item_name"].ToString();//名稱 ShopSubListBuf.m_dblPrice = VP_Convert.ToInt32(m_ordercontentdataDataTable.Rows[i]["item_cost"].ToString());//價格 ShopSubListBuf.m_intAmount = VP_Convert.ToInt32(m_ordercontentdataDataTable.Rows[i]["item_count"].ToString());//數量 ShopSubListBuf.m_dblSum = ShopSubListBuf.m_intAmount * ShopSubListBuf.m_dblPrice;//總和 ShopSubListBuf.m_Stritem_type = m_ordercontentdataDataTable.Rows[i]["item_type"].ToString();//類型 ShopSubListBuf.m_Strcondiment_code = m_ordercontentdataDataTable.Rows[i]["item_code"].ToString(); ShopSubListBuf.m_intitem_no = VP_Convert.ToInt32(m_ordercontentdataDataTable.Rows[i]["item_no"].ToString()); ShopSubListBuf.m_Strdel_flag = m_ordercontentdataDataTable.Rows[i]["del_flag"].ToString(); int parent_item_no = VP_Convert.ToInt32(m_ordercontentdataDataTable.Rows[i]["parent_item_no"].ToString()); ShopSubListBuf.m_intparent_item_no = parent_item_no; for (int j = 0; j < m_ShopCart.m_ShopMainList.Count; j++) { if (m_ShopCart.m_ShopMainList[j].m_intitem_no == parent_item_no) { ShopSubListBuf.m_blnSTOCK_PULL = m_ShopCart.m_ShopMainList[j].m_blnSTOCK_PULL; m_ShopCart.m_ShopMainList[j].m_ShopSubList.Add(ShopSubListBuf); m_ShopCart.m_intItemNoCount++; break; } } } } } } private void LoadOrderStagingListItems()//載入清單資料 { // if ((m_orderdataDataTable != null) && (m_orderdataDataTable.Rows.Count > 0)) { ((OrderStagingListViewModel)DataContext).m_OrderStagingListItems.Clear(); for (int i = 0; i < m_orderdataDataTable.Rows.Count; i++) { OrderStagingListItem OrderStagingListItemBuf = new OrderStagingListItem(); OrderStagingListItemBuf.order_no = m_orderdataDataTable.Rows[i]["order_no"].ToString(); OrderStagingListItemBuf.order_open_time = VP_Convert.ToDateTime(m_orderdataDataTable.Rows[i]["order_open_time"].ToString()).ToString("yyyy-MM-dd HH:mm:ss"); OrderStagingListItemBuf.order_type_name = m_orderdataDataTable.Rows[i]["order_type_name"].ToString(); OrderStagingListItemBuf.table_name = m_orderdataDataTable.Rows[i]["table_name"].ToString(); OrderStagingListItemBuf.item_count = m_orderdataDataTable.Rows[i]["item_count"].ToString(); OrderStagingListItemBuf.subtotal = m_orderdataDataTable.Rows[i]["subtotal"].ToString(); OrderStagingListItemBuf.amount = m_orderdataDataTable.Rows[i]["amount"].ToString(); OrderStagingListItemBuf.remarks = m_orderdataDataTable.Rows[i]["remarks"].ToString(); OrderStagingListItemBuf.guests_num = m_orderdataDataTable.Rows[i]["guests_num"].ToString(); String order_type = m_orderdataDataTable.Rows[i]["order_type"].ToString(); String order_type_code = m_orderdataDataTable.Rows[i]["order_type_code"].ToString(); OrderStagingListItemBuf.order_type_code = (order_type + "," + order_type_code); ((OrderStagingListViewModel)DataContext).m_OrderStagingListItems.Add(OrderStagingListItemBuf); } } else { ((OrderStagingListViewModel)DataContext).m_OrderStagingListItems.Clear(); } } private void ordercontentdataShow() { ((OrderStagingListViewModel)DataContext).m_ShopcartItems.Clear(); for (int i = 0; i < m_ShopCart.m_ShopMainList.Count; i++) { if (m_ShopCart.m_ShopMainList[i].m_Strdel_flag == "N") { if (m_ShopCart.m_ShopMainList[i].m_Stritem_type != "S") { if (m_ShopCart.m_ShopMainList[i].m_Stritem_type == "T") { ShopcartListViewShow(15, i, -1, 14);//主項(套餐)新增 } else { if (m_ShopCart.m_ShopMainList[i].m_intparent_item_no > 0) { ShopcartListViewShow(16, i, -1, 14);//主項(套餐-產品)新增 } else { if (m_ShopCart.m_ShopMainList[i].m_Stritem_type == "U") { ShopcartListViewShow(21, i, -1, 14);//優惠券 } else { if (m_ShopCart.m_ShopMainList[i].m_Stritem_type == "STOCK_PULL") { continue; } ShopcartListViewShow(0, i, -1, 14);//產品 / 包材 if ((m_ShopCart.m_ShopMainList[i].m_Stritem_type == "P") && (m_ShopCart.m_ShopMainList[i].m_blnSTOCK_PULL)) { ShopcartListViewShow(0, (i + 1), -1, 14);//dgvmain001Show } } } } } else { ShopcartListViewShow(9, i, -3, 14);//小計 } if (m_ShopCart.m_ShopMainList[i].m_Strdiscount_type != "N") { ShopcartListViewShow(8, i, -2, 14); ShopcartListView.SelectedItem = ((OrderStagingListViewModel)DataContext).m_ShopcartItems[((OrderStagingListViewModel)DataContext).m_ShopcartItems.Count - 2];//因為載入資料事先產折扣列所以選取必須減一否則配料會顯示異常 } if (m_ShopCart.m_ShopMainList[i].m_intparent_item_no > 0) { if (m_ShopCart.m_ShopMainList[i].m_ShopSubList.Count > 0) { ShopcartListViewShow(17, i, m_ShopCart.m_ShopMainList[i].m_ShopSubList.Count - 1, 12); } } else { int k = 0; for (int j = 0; j < m_ShopCart.m_ShopMainList[i].m_ShopSubList.Count; j++) { if (m_ShopCart.m_ShopMainList[i].m_ShopSubList[j].m_Strdel_flag == "N") { if (k == 0) { ShopcartListViewShow(2, i, 0, 12); } else { ShopcartListViewShow(3, i, j, 12); } k++; } } } } } } private int m_intDelItemType = -1;//0[產品],1[折扣讓],2[小計],4[調味品單一],5[套餐],6[套餐折扣讓] private ShopcartItem m_ShopcartItemSelected = null; private int m_intShopcartSelectedIndex = -1; private async void ShopcartListViewShow(int intAction, int intMainArrayIndex, int intSubArrayIndex, int intFontSize, bool blnOnlyShow = false)//購物車 項目顯示變更函數 { OrderStagingListViewModel MainWindowViewModelBuf = ((OrderStagingListViewModel)DataContext); String SQL = ""; if ((MainWindowViewModelBuf.m_ShopcartItems == null)) { return; } try { //dgvmain001.Columns[0].Visible = true; //陣列ID-[M,S],圖1,圖2,產品名,數量,價格,總價,圖編號,字型大小 switch (intAction) { case 0://主項(產品)新增 if (m_ShopCart.m_ShopMainList[intMainArrayIndex].m_Strdel_flag != "Y") { ShopcartItem ShopcartItemMain00 = new ShopcartItem(); ShopcartItemMain00.id = (m_ShopCart.m_ShopMainList[intMainArrayIndex].m_Stritem_type != "STOCK_PULL") ? (intMainArrayIndex + "," + intSubArrayIndex) : ((intMainArrayIndex - 1) + "," + -99999);//陣列ID-[M,S] ShopcartItemMain00.Image00 = (m_ShopCart.m_ShopMainList[intMainArrayIndex].m_dblSum < 0) ? MainWindowViewModelBuf.m_BmpShopcartIcons[2] : MainWindowViewModelBuf.m_BmpShopcartIcons[0];//"checkbox00.png" ShopcartItemMain00.Image01 = MainWindowViewModelBuf.m_BmpShopcartIcons[2];//"blank.png" ShopcartItemMain00.Name = m_ShopCart.m_ShopMainList[intMainArrayIndex].m_StrName; ShopcartItemMain00.Amount = (m_ShopCart.m_ShopMainList[intMainArrayIndex].m_dblSum < 0) ? "" : m_ShopCart.m_ShopMainList[intMainArrayIndex].m_intAmount.ToString(); ShopcartItemMain00.Price = (m_ShopCart.m_ShopMainList[intMainArrayIndex].m_dblSum < 0) ? "" : m_ShopCart.m_ShopMainList[intMainArrayIndex].m_dblPrice.ToString(); ShopcartItemMain00.Sum = m_ShopCart.m_ShopMainList[intMainArrayIndex].m_dblSum.ToString(); ShopcartItemMain00.image_id = (m_ShopCart.m_ShopMainList[intMainArrayIndex].m_dblSum < 0) ? MainWindowViewModelBuf.m_StrShopcartIcons[2] : MainWindowViewModelBuf.m_StrShopcartIcons[0]; ShopcartItemMain00.Font_Color = (m_ShopCart.m_ShopMainList[intMainArrayIndex].m_dblSum < 0) ? Brushes.Red : Brushes.Black; ShopcartItemMain00.Default_Color = (m_ShopCart.m_ShopMainList[intMainArrayIndex].m_dblSum < 0) ? Brushes.Red : Brushes.Black; ShopcartItemMain00.Font_Size = 20; ShopcartItemMain00.State = "0"; ShopcartItemMain00.BColor = Brushes.Transparent; ShopcartItemMain00.NameTextAlignment = TextAlignment.Left; MainWindowViewModelBuf.m_ShopcartItems.Add(ShopcartItemMain00); ShopcartListView.SelectedItem = MainWindowViewModelBuf.m_ShopcartItems[MainWindowViewModelBuf.m_ShopcartItems.Count - 1];//觸發執行 (購物車 選項 切換事件函數) } break; case 1://產品/套餐 數量修改 String StrBuf01 = intMainArrayIndex + "," + -1; for (int i = 0; i < MainWindowViewModelBuf.m_ShopcartItems.Count; i++) { if ((StrBuf01 == MainWindowViewModelBuf.m_ShopcartItems[i].id) || ((StrBuf01 + ",T") == MainWindowViewModelBuf.m_ShopcartItems[i].id)) { ShopcartItem ShopcartItemMain01 = new ShopcartItem(); ShopcartItemMain01.id = MainWindowViewModelBuf.m_ShopcartItems[i].id;//陣列ID-[M,S] ShopcartItemMain01.Image00 = MainWindowViewModelBuf.m_ShopcartItems[i].Image00;//"checkbox00.png" ShopcartItemMain01.Image01 = MainWindowViewModelBuf.m_ShopcartItems[i].Image01;//"blank.png" ShopcartItemMain01.Name = m_ShopCart.m_ShopMainList[intMainArrayIndex].m_StrName; ShopcartItemMain01.Amount = m_ShopCart.m_ShopMainList[intMainArrayIndex].m_intAmount.ToString(); ShopcartItemMain01.Price = m_ShopCart.m_ShopMainList[intMainArrayIndex].m_dblPrice.ToString(); ShopcartItemMain01.Sum = m_ShopCart.m_ShopMainList[intMainArrayIndex].m_dblSum.ToString(); ShopcartItemMain01.image_id = MainWindowViewModelBuf.m_ShopcartItems[i].image_id; ShopcartItemMain01.Font_Color = MainWindowViewModelBuf.m_ShopcartItems[i].Font_Color; ShopcartItemMain01.Default_Color = MainWindowViewModelBuf.m_ShopcartItems[i].Default_Color; ShopcartItemMain01.Font_Size = MainWindowViewModelBuf.m_ShopcartItems[i].Font_Size; ShopcartItemMain01.State = MainWindowViewModelBuf.m_ShopcartItems[i].State; ShopcartItemMain01.BColor = MainWindowViewModelBuf.m_ShopcartItems[i].BColor; ShopcartItemMain01.NameTextAlignment = TextAlignment.Left; //m_ShopcartItems.Insert(i, ShopcartItemMain01); //m_ShopcartItems.RemoveAt((i + 1)); MainWindowViewModelBuf.m_ShopcartItems[i] = ShopcartItemMain01; ShopcartListView.SelectedItem = MainWindowViewModelBuf.m_ShopcartItems[i];//觸發執行 (購物車 選項 切換事件函數) break; } } break; case 2://調味品[唯一]新增 //--- //計算新增調味品位置 int index = m_intShopcartSelectedIndex; if ((m_ShopCart.m_ShopMainList[intMainArrayIndex].m_Strdiscount_type == "Y") || (m_ShopCart.m_ShopMainList[intMainArrayIndex].m_Stritem_type == "P" && m_ShopCart.m_ShopMainList[intMainArrayIndex].m_blnSTOCK_PULL)) { index += 2;//因為 折扣/折讓 顯示在加1的位置 } else { index += 1;// } //---計算新增調味品位置 ShopcartItem ShopcartItemSub = new ShopcartItem(); ShopcartItemSub.id = intMainArrayIndex + "," + intSubArrayIndex;//陣列ID-[M,S] ShopcartItemSub.Image00 = MainWindowViewModelBuf.m_BmpShopcartIcons[2];//"blank.png" ShopcartItemSub.Image01 = MainWindowViewModelBuf.m_BmpShopcartIcons[2];//"blank.png" ShopcartItemSub.Name = m_StrTab + m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[intSubArrayIndex].m_StrName; ShopcartItemSub.Amount = m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[intSubArrayIndex].m_intAmount.ToString(); ShopcartItemSub.Price = m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[intSubArrayIndex].m_dblPrice.ToString(); ShopcartItemSub.Sum = m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[intSubArrayIndex].m_dblSum.ToString(); ShopcartItemSub.image_id = MainWindowViewModelBuf.m_StrShopcartIcons[2]; ShopcartItemSub.Font_Color = Brushes.Black; ShopcartItemSub.Default_Color = Brushes.Black; ShopcartItemSub.Font_Size = 20 - 1.5;//Device.GetNamedSize(NamedSize.Micro, typeof(Label)); ShopcartItemSub.State = "0"; ShopcartItemSub.BColor = Brushes.Transparent; ShopcartItemSub.NameTextAlignment = TextAlignment.Left; MainWindowViewModelBuf.m_ShopcartItems.Insert(index, ShopcartItemSub); break; case 3://調味品[多筆顯示成一筆]新增 //--- //產生調味品多筆合併一筆的顯示資訊 String StrAllSubName = m_StrTab; int intAllAmount = 0; double dblAllSum = 0; int intStringCount = m_StrTab.Length / 2; int intItemNo = -1; bool blnNew03 = false; bool blnDel03 = false; for (int i = 0; i < MainWindowViewModelBuf.m_ShopcartItems.Count; i++) { string StrId = MainWindowViewModelBuf.m_ShopcartItems[i].id; string[] strs = StrId.Split(","); if ((intMainArrayIndex.ToString() == strs[0]) && (VP_Convert.ToInt32(strs[1]) >= 0)) { blnDel03 = true; break; } } for (int i = 0; i < m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList.Count; i++) { if (m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_Strdel_flag != "Y") { blnNew03 = true; intItemNo = (intItemNo < 0) ? m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_intitem_no : intItemNo; intAllAmount += m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_intAmount; if ((intStringCount + m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_StrName.Length) < 17) { StrAllSubName += m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_StrName + ","; intStringCount += m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_StrName.Length; } else { StrAllSubName += "\n" + m_StrTab + m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_StrName + ","; intStringCount = m_StrTab.Length / 2; intStringCount += m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_StrName.Length; } dblAllSum += m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_dblSum; } } //---產生調味品多筆合併一筆的顯示資訊 //--- //更新對應顯示欄位 int index1 = m_intShopcartSelectedIndex; if ((m_ShopCart.m_ShopMainList[intMainArrayIndex].m_Strdiscount_type == "Y") || (m_ShopCart.m_ShopMainList[intMainArrayIndex].m_Stritem_type == "P" && m_ShopCart.m_ShopMainList[intMainArrayIndex].m_blnSTOCK_PULL)) { index1 += 2;//因為 折扣/折讓 顯示在加1的位置 } else { index1 += 1;// } ShopcartItem ShopcartItemSub01 = new ShopcartItem(); ShopcartItemSub01.id = intMainArrayIndex + "," + intSubArrayIndex;//陣列ID-[M,S] ShopcartItemSub01.Image00 = MainWindowViewModelBuf.m_BmpShopcartIcons[2];//"blank.png" ShopcartItemSub01.Image01 = MainWindowViewModelBuf.m_BmpShopcartIcons[2];//"blank.png" ShopcartItemSub01.Name = StrAllSubName.Substring(0, StrAllSubName.Length - 1); ShopcartItemSub01.Amount = intAllAmount.ToString(); ShopcartItemSub01.Price = ""; ShopcartItemSub01.Sum = dblAllSum.ToString(); ShopcartItemSub01.image_id = MainWindowViewModelBuf.m_StrShopcartIcons[2]; ShopcartItemSub01.Font_Color = Brushes.Black; ShopcartItemSub01.Default_Color = Brushes.Black; ShopcartItemSub01.Font_Size = 20 - 1.5;//Device.GetNamedSize(NamedSize.Micro, typeof(Label)); ShopcartItemSub01.State = "0"; ShopcartItemSub01.BColor = Brushes.Transparent; ShopcartItemSub01.NameTextAlignment = TextAlignment.Left; if (blnNew03) { MainWindowViewModelBuf.m_ShopcartItems.Insert(index1, ShopcartItemSub01); } if (blnDel03) { if (blnNew03) { MainWindowViewModelBuf.m_ShopcartItems.RemoveAt((index1 + 1)); } else { MainWindowViewModelBuf.m_ShopcartItems.RemoveAt(index1); } } //---更新對應顯示欄位 break; case 4://調味品[多筆顯示多筆]新增 //5+6 break; case 5://清除特定產品下既有的調味品相關選項 /*jash stop int intIndexX5 = dgvmain001.SelectedRows[0].Index;//取得被選取的第一列旗標位置 for (int i = dgvmain001.SelectedRows[0].Index; i < dgvmain001.Rows.Count; i++) { String StrBuf = dgvmain001.Rows[i].Cells[0].Value.ToString(); String StrBufName = dgvmain001.Rows[i].Cells[3].Value.ToString(); string[] strs = StrBuf.Split(','); int intMainindex = VP_Convert.ToInt32(strs[0]); int intSubindex = VP_Convert.ToInt32(strs[1]); if ((intMainArrayIndex == intMainindex) && (intSubindex >= 0)) { dgvmain001.Rows.Remove(dgvmain001.Rows[i]); i--; } } */ break; case 6://產生調味品多筆合併一筆 轉 多筆顯示資訊 [展開] /*jash stop //--- //修改主項(產品)總金額 MainTotalSumCalculate(intMainArrayIndex); ShopcartListViewMainTotalSumChange(intMainArrayIndex); //---修改主項(產品)總金額 int intInsertX6 = dgvmain001.SelectedRows[0].Index;//取得被選取的第一列旗標位置 int intShiftX6 = 0; if (m_ShopCart.m_ShopMainList[intMainArrayIndex].m_Strdiscount_type == "Y") { intShiftX6 += 2;//因為 折扣/折讓 顯示在加1的位置 } else { intShiftX6 += 1;// } for (int i = 0; i < m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList.Count; i++) { if (m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_Strdel_flag != "Y")//if(m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_Strdel_time!="Y") { intSubArrayIndex = i; if (((m_ShopCart.m_ShopMainList[intMainArrayIndex].m_Strdiscount_type == "N") && (intShiftX6 == 1)) || ((m_ShopCart.m_ShopMainList[intMainArrayIndex].m_Strdiscount_type == "Y") && (intShiftX6 == 2)))//if (i == 0)// { // 陣列ID-[M,S], 圖1, 圖2, 產品名, 數量, 價格, 總價, 圖編號, 字型大小, 顏色,狀態 - 無,小計,折讓/折扣 [State] 0,1,2 dgvmain001.Rows.Insert((intInsertX6 + intShiftX6), intMainArrayIndex + "," + intSubArrayIndex, null, imlmain001.Images[m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_intImgId], m_StrTab + m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_StrName, m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_intAmount, m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_dblPrice, m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_dblSum, m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_intImgId, intFontSize, "Black", 0); } else { // 陣列ID-[M,S], 圖1, 圖2, 產品名, 數量, 價格, 總價, 圖編號, 字型大小, 顏色,狀態 - 無,小計,折讓/折扣 [State] 0,1,2 dgvmain001.Rows.Insert((intInsertX6 + intShiftX6), intMainArrayIndex + "," + intSubArrayIndex, null, null, m_StrTab + m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_StrName, m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_intAmount, m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_dblPrice, m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_dblSum, m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_intImgId, intFontSize, "Black", 0); } //jash stop dgvmainSetRow(intInsertX6 + intShiftX6); intShiftX6++; } } //--- //產生調味品多筆合併一筆的顯示資訊 String StrAllSubName06 = m_StrTab; int intAllAmount06 = 0; double dblAllSum06 = 0; int intStringCount06 = m_StrTab.Length / 2; int intItemNo06 = -1; for (int i = 0; i < m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList.Count; i++) { if (m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_Strdel_flag != "Y") { intItemNo06 = (intItemNo06 < 0) ? m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_intitem_no : intItemNo06; intAllAmount06 += m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_intAmount; if ((intStringCount06 + m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_StrName.Length) < 17) { StrAllSubName06 += m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_StrName + ","; intStringCount06 += m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_StrName.Length; } else { StrAllSubName06 += "\n" + m_StrTab + m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_StrName + ","; intStringCount06 = m_StrTab.Length / 2; intStringCount06 += m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_StrName.Length; } dblAllSum06 += m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_dblSum; } } //---產生調味品多筆合併一筆的顯示資訊 //--- //UDP購物車商品異動資訊 CustomerDisplayUDP.m_CustomerDisplay = new CustomerDisplay(); CustomerDisplayUDP.m_CustomerDisplay.ItemInfo.ITEMSTATE = "U";//N:新增 U:修改 D:刪除 CustomerDisplayUDP.m_CustomerDisplay.ItemInfo.ProductName = StrAllSubName06.Substring(0, StrAllSubName06.Length - 1); CustomerDisplayUDP.m_CustomerDisplay.ItemInfo.ItemNo = intItemNo06; CustomerDisplayUDP.m_CustomerDisplay.ItemInfo.ParentItemNo = m_ShopCart.m_ShopMainList[intMainArrayIndex].m_intitem_no; CustomerDisplayUDP.m_CustomerDisplay.ItemInfo.ItemType = "C"; CustomerDisplayUDP.m_CustomerDisplay.ItemInfo.Count = intAllAmount06; CustomerDisplayUDP.m_CustomerDisplay.ItemInfo.Cost = 0; CustomerDisplayUDP.m_CustomerDisplay.ItemInfo.SubTotal = (int)(dblAllSum06); CustomerDisplayUDP.m_CustomerDisplay.ItemInfo.Amount = (int)(dblAllSum06); CustomerDisplayUDP.m_intApiState = 0;//更新客顯示訊0;結帳完成時1;清除客顯2 //---UDP購物車商品異動資訊 */ break; case 7://產生調味品多筆 轉 多筆合併一筆顯示資訊 /*jash stop if (!blnOnlyShow) { //--- //修改主項(產品)總金額 MainTotalSumCalculate(intMainArrayIndex); ShopcartListViewMainTotalSumChange(intMainArrayIndex); //---修改主項(產品)總金額 } int intInsertX7 = dgvmain001.SelectedRows[0].Index;//取得被選取的第一列旗標位置 int intShiftX7 = 0; if (m_ShopCart.m_ShopMainList[intMainArrayIndex].m_Strdiscount_type == "Y") { intShiftX7 += 2;//因為 折扣/折讓 顯示在加1的位置 } else { intShiftX7 += 1;// } //--- //產生調味品多筆合併一筆的顯示資訊 String StrAllSubNameX7 = m_StrTab; int intAllAmountX7 = 0; double dblAllSumX7 = 0; int intStringCountX7 = m_StrTab.Length / 2; for (int i = 0; i < m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList.Count; i++) { if (m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_Strdel_flag != "Y")//if (m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_Strdel_time != "Y") { intAllAmountX7 += m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_intAmount; dblAllSumX7 += m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_dblSum; String StrPrice = (m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_dblSum > 0) ? $"(${m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_dblSum})" : ""; if ((intStringCountX7 + m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_StrName.Length) < 17) { StrAllSubNameX7 += m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_StrName + StrPrice + ","; intStringCountX7 += m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_StrName.Length; } else { StrAllSubNameX7 += "\n" + m_StrTab + m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_StrName + StrPrice + ","; intStringCountX7 = m_StrTab.Length / 2; intStringCountX7 += m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_StrName.Length; } } } //---產生調味品多筆合併一筆的顯示資訊 // 陣列ID-[M,S], 圖1, 圖2, 產品名, 數量, 價格, 總價, 圖編號, 字型大小, 顏色, 狀態 - 無,小計,折讓/折扣 [State] 0,1,2 dgvmain001.Rows.Insert((intInsertX7 + intShiftX7), intMainArrayIndex + "," + intSubArrayIndex, null, imlmain001.Images[m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[0].m_intImgId], StrAllSubNameX7.Substring(0, StrAllSubNameX7.Length - 1), intAllAmountX7, "", dblAllSumX7, m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[0].m_intImgId, intFontSize, "Black", 0); //jash stop dgvmainSetRow(intInsertX7 + intShiftX7); */ break; case 8://新增 折扣/折讓的資料列 顯示 intMainArrayIndex + ","+ -2 int intInsertX8 = 0;//取得被選取的第一列旗標位置 int intShiftX8 = 1; int intitem_no = m_ShopCart.m_ShopMainList[intMainArrayIndex].m_intitem_no; m_ShopCart.m_ShopMainList[intMainArrayIndex].m_Strdiscount_type = "Y"; SQL = String.Format("SELECT discount_name,discount_fee,discount_type,discount_rate FROM order_content_data WHERE order_no='{0}' AND item_no='{1}';", m_StrdgvInforSelectOrderNo, intitem_no); DataTable order_content_dataDataTable = SQLDataTableModel.GetDataTable(SQL); if (((order_content_dataDataTable != null) && (order_content_dataDataTable.Rows.Count > 0))) { for (int i = 0; i < MainWindowViewModelBuf.m_ShopcartItems.Count; i++) { String StrBuf001 = intMainArrayIndex + ",-1";//產品折扣/折讓判斷式 String StrBuf002 = intMainArrayIndex + ",-3";//小計折扣/折讓判斷式 if ((MainWindowViewModelBuf.m_ShopcartItems[i].id == StrBuf001) || (MainWindowViewModelBuf.m_ShopcartItems[i].id == StrBuf002)) { intInsertX8 = i; break; } } ShopcartItem ShopcartItem08 = new ShopcartItem(); ShopcartItem08.id = intMainArrayIndex + "," + intSubArrayIndex;//陣列ID-[M,S] ShopcartItem08.Image00 = MainWindowViewModelBuf.m_BmpShopcartIcons[2];//"blank.png" ShopcartItem08.Image01 = MainWindowViewModelBuf.m_BmpShopcartIcons[2];//"blank.png" ShopcartItem08.Name = order_content_dataDataTable.Rows[0][0].ToString(); ShopcartItem08.Amount = ""; ShopcartItem08.Price = ""; ShopcartItem08.Sum = "" + VP_Convert.ToInt32(order_content_dataDataTable.Rows[0][1].ToString()) * -1; ShopcartItem08.image_id = MainWindowViewModelBuf.m_StrShopcartIcons[2]; ShopcartItem08.Font_Color = Brushes.Red; ShopcartItem08.Default_Color = Brushes.Red; ShopcartItem08.Font_Size = 20; ShopcartItem08.State = "1"; //狀態 - 無,折讓 / 折扣,小計[State] 0,1,2 ShopcartItem08.NameTextAlignment = TextAlignment.Left; MainWindowViewModelBuf.m_ShopcartItems.Insert((intInsertX8 + intShiftX8), ShopcartItem08); ShopcartListView.SelectedItem = MainWindowViewModelBuf.m_ShopcartItems[(intInsertX8 + intShiftX8)];//觸發執行 (購物車 選項 切換事件函數) } break; case 9://新增 小計資料列 if (m_ShopCart.m_ShopMainList[intMainArrayIndex].m_Strdel_flag != "Y") { ShopcartItem ShopcartItem09 = new ShopcartItem(); ShopcartItem09.id = intMainArrayIndex + "," + intSubArrayIndex;//陣列ID-[M,S] ShopcartItem09.Image00 = MainWindowViewModelBuf.m_BmpShopcartIcons[2];//"blank.png" ShopcartItem09.Image01 = MainWindowViewModelBuf.m_BmpShopcartIcons[2];//"blank.png" ShopcartItem09.Name = m_ShopCart.m_ShopMainList[intMainArrayIndex].m_StrName; ShopcartItem09.Amount = ""; ShopcartItem09.Price = ""; ShopcartItem09.Sum = "" + m_ShopCart.m_ShopMainList[intMainArrayIndex].m_dblSum; ShopcartItem09.image_id = MainWindowViewModelBuf.m_StrShopcartIcons[2]; ShopcartItem09.Font_Color = Brushes.Blue; ShopcartItem09.Default_Color = Brushes.Blue; ShopcartItem09.Font_Size = 20; ShopcartItem09.State = "2"; //狀態 - 無,折讓 / 折扣,小計[State] 0,1,2 ShopcartItem09.NameTextAlignment = TextAlignment.Left; MainWindowViewModelBuf.m_ShopcartItems.Add(ShopcartItem09); //ShopcartListView.ScrollTo(m_ShopcartItems[m_ShopcartItems.Count - 1], ScrollToPosition.End, false); ShopcartListView.SelectedItem = MainWindowViewModelBuf.m_ShopcartItems[MainWindowViewModelBuf.m_ShopcartItems.Count - 1];//觸發執行 (購物車 選項 切換事件函數) } break; case 10://主項(產品)+折扣讓+調味品 UI刪除 int intIndex10 = -1; for (int i = 0; i < MainWindowViewModelBuf.m_ShopcartItems.Count; i++) { String StrBuf = MainWindowViewModelBuf.m_ShopcartItems[i].id; String StrBufName = MainWindowViewModelBuf.m_ShopcartItems[i].Name; string[] strs = StrBuf.Split(','); int intMainindex = VP_Convert.ToInt32(strs[0]); int intSubindex = VP_Convert.ToInt32(strs[1]); if (intMainArrayIndex == intMainindex) { MainWindowViewModelBuf.m_ShopcartItems.Remove(MainWindowViewModelBuf.m_ShopcartItems[i]); intIndex10 = i; i = -1;//從頭開始檢查 } if ((intSubindex == 0) && (m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList.Count > 0)) { SQL = String.Format("SELECT promotion_value,promotion_fee,discount_fee, item_count, amount, order_type_name, class_name, call_num, table_name, meal_num, paid_info, change_fee,remarks,order_state,service_fee,guests_num FROM order_data WHERE order_no = '{0}' LIMIT 0,1", m_StrdgvInforSelectOrderNo); DataTable order_dataDataTable01 = SQLDataTableModel.GetDataTable(SQL); } } if (MainWindowViewModelBuf.m_ShopcartItems.Count > 0) { if ((intIndex10 - 1) > 0) { for (int i = (intIndex10 - 1); i >= 0; i--) { if (MainWindowViewModelBuf.m_ShopcartItems[i].image_id != "blank.png") { m_intShopcartSelectedIndex = -1;//購物車選取項目旗標清空 ShopcartListView.SelectedItem = MainWindowViewModelBuf.m_ShopcartItems[i];//觸發執行 (購物車 選項 切換事件函數) break; } } } else { m_intShopcartSelectedIndex = -1;//購物車選取項目旗標清空 ShopcartListView.SelectedItem = MainWindowViewModelBuf.m_ShopcartItems[0];//觸發執行 (購物車 選項 切換事件函數) } } break; case 11://折扣讓 UI刪除 int intIndex11 = -1; for (int i = 0; i < MainWindowViewModelBuf.m_ShopcartItems.Count; i++) { String StrBuf = MainWindowViewModelBuf.m_ShopcartItems[i].id; String StrBufName = MainWindowViewModelBuf.m_ShopcartItems[i].Name; string[] strs = StrBuf.Split(','); int intMainindex = VP_Convert.ToInt32(strs[0]); int intSubindex = VP_Convert.ToInt32(strs[1]); if ((intMainArrayIndex == intMainindex) && (intSubindex == -2)) { MainWindowViewModelBuf.m_ShopcartItems.Remove(MainWindowViewModelBuf.m_ShopcartItems[i]); intIndex11 = i; i = -1;//從頭開始檢查 } } if (MainWindowViewModelBuf.m_ShopcartItems.Count > 0) { if ((intIndex11 - 1) > 0) { for (int i = (intIndex11 - 1); i >= 0; i--) { if (MainWindowViewModelBuf.m_ShopcartItems[i].image_id != "blank.png") { m_intShopcartSelectedIndex = -1;//購物車選取項目旗標清空 ShopcartListView.SelectedItem = MainWindowViewModelBuf.m_ShopcartItems[i];//觸發執行 (購物車 選項 切換事件函數) break; } } } else { m_intShopcartSelectedIndex = -1;//購物車選取項目旗標清空 ShopcartListView.SelectedItem = MainWindowViewModelBuf.m_ShopcartItems[0];//觸發執行 (購物車 選項 切換事件函數) } } break; case 12://小計 UI刪除 int intIndex12 = -1; for (int i = 0; i < MainWindowViewModelBuf.m_ShopcartItems.Count; i++) { String StrBuf = MainWindowViewModelBuf.m_ShopcartItems[i].id; String StrBufName = MainWindowViewModelBuf.m_ShopcartItems[i].Name; string[] strs = StrBuf.Split(','); int intMainindex = VP_Convert.ToInt32(strs[0]); int intSubindex = VP_Convert.ToInt32(strs[1]); if (intMainArrayIndex == intMainindex) { MainWindowViewModelBuf.m_ShopcartItems.Remove(MainWindowViewModelBuf.m_ShopcartItems[i]); intIndex12 = i; i = -1;//從頭開始檢查 //--- //UDP購物車商品異動資訊 CustomerDisplayUDP.m_CustomerDisplay = new CustomerDisplay(); CustomerDisplayUDP.m_CustomerDisplay.ItemInfo.ITEMSTATE = "D";//N:新增 U:修改 D:刪除 CustomerDisplayUDP.m_CustomerDisplay.ItemInfo.ProductName = m_ShopCart.m_ShopMainList[intMainArrayIndex].m_StrName; CustomerDisplayUDP.m_CustomerDisplay.ItemInfo.ItemNo = m_ShopCart.m_ShopMainList[intMainArrayIndex].m_intitem_no; CustomerDisplayUDP.m_CustomerDisplay.ItemInfo.ParentItemNo = 0; CustomerDisplayUDP.m_CustomerDisplay.ItemInfo.ItemType = m_ShopCart.m_ShopMainList[intMainArrayIndex].m_Stritem_type; CustomerDisplayUDP.m_CustomerDisplay.ItemInfo.SubTotal = (int)(m_ShopCart.m_ShopMainList[intMainArrayIndex].m_dblSum); CustomerDisplayUDP.m_CustomerDisplay.ItemInfo.Amount = (int)(m_ShopCart.m_ShopMainList[intMainArrayIndex].m_dblSum); CustomerDisplayUDP.m_intApiState = 0;//更新客顯示訊0;結帳完成時1;清除客顯2 //---UDP購物車商品異動資訊 } } if (MainWindowViewModelBuf.m_ShopcartItems.Count > 0) { if ((intIndex12 - 1) > 0) { for (int i = (intIndex12 - 1); i >= 0; i--) { if (MainWindowViewModelBuf.m_ShopcartItems[i].image_id != "blank.png") { m_intShopcartSelectedIndex = -1;//購物車選取項目旗標清空 ShopcartListView.SelectedItem = MainWindowViewModelBuf.m_ShopcartItems[i];//觸發執行 (購物車 選項 切換事件函數) break; } } } else { m_intShopcartSelectedIndex = -1;//購物車選取項目旗標清空 ShopcartListView.SelectedItem = MainWindowViewModelBuf.m_ShopcartItems[0];//觸發執行 (購物車 選項 切換事件函數) } } break; case 13://單一調味品 UI刪除 for (int i = 0; i < MainWindowViewModelBuf.m_ShopcartItems.Count; i++) { String StrBuf = MainWindowViewModelBuf.m_ShopcartItems[i].id; String StrBufName = MainWindowViewModelBuf.m_ShopcartItems[i].Name; string[] strs = StrBuf.Split(','); int intMainindex = VP_Convert.ToInt32(strs[0]); int intSubindex = VP_Convert.ToInt32(strs[1]); if ((intMainArrayIndex == intMainindex) && (intSubindex == intSubArrayIndex)) { MainWindowViewModelBuf.m_ShopcartItems.Remove(MainWindowViewModelBuf.m_ShopcartItems[i]); //--- //產生調味品多筆合併一筆的顯示資訊 String StrAllSubName01 = m_StrTab; int intAllAmount01 = 0; double dblAllSum01 = 0; int intStringCount01 = m_StrTab.Length / 2; int intItemNo01 = -1; for (int j = 0; j < m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList.Count; j++) { if (m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[j].m_Strdel_flag != "Y") { intItemNo01 = (intItemNo01 < 0) ? m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[j].m_intitem_no : intItemNo01; intAllAmount01 += m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[j].m_intAmount; if ((intStringCount01 + m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[j].m_StrName.Length) < 17) { StrAllSubName01 += m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[j].m_StrName + ","; intStringCount01 += m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[j].m_StrName.Length; } else { StrAllSubName01 += "\n" + m_StrTab + m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[j].m_StrName + ","; intStringCount01 = m_StrTab.Length / 2; intStringCount01 += m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[j].m_StrName.Length; } dblAllSum01 += m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[j].m_dblSum; } } //---產生調味品多筆合併一筆的顯示資訊 //--- //UDP購物車商品異動資訊 CustomerDisplayUDP.m_CustomerDisplay = new CustomerDisplay(); CustomerDisplayUDP.m_CustomerDisplay.ItemInfo.ITEMSTATE = "U";//N:新增 U:修改 D:刪除 CustomerDisplayUDP.m_CustomerDisplay.ItemInfo.ProductName = StrAllSubName01.Substring(0, StrAllSubName01.Length - 1); CustomerDisplayUDP.m_CustomerDisplay.ItemInfo.ItemNo = intItemNo01; CustomerDisplayUDP.m_CustomerDisplay.ItemInfo.ParentItemNo = m_ShopCart.m_ShopMainList[intMainArrayIndex].m_intitem_no; CustomerDisplayUDP.m_CustomerDisplay.ItemInfo.ItemType = "C"; CustomerDisplayUDP.m_CustomerDisplay.ItemInfo.Count = intAllAmount01; CustomerDisplayUDP.m_CustomerDisplay.ItemInfo.Cost = 0; CustomerDisplayUDP.m_CustomerDisplay.ItemInfo.SubTotal = (int)(dblAllSum01); CustomerDisplayUDP.m_CustomerDisplay.ItemInfo.Amount = (int)(dblAllSum01); CustomerDisplayUDP.m_intApiState = 0;//更新客顯示訊0;結帳完成時1;清除客顯2 //---UDP購物車商品異動資訊 break; } } break; case 14://新增結帳完成資訊 ShopcartItem ShopcartItem14 = new ShopcartItem(); ShopcartItem14.id = intMainArrayIndex + "," + intSubArrayIndex;//陣列ID-[M,S] ShopcartItem14.Image00 = MainWindowViewModelBuf.m_BmpShopcartIcons[2];//"blank.png" ShopcartItem14.Image01 = MainWindowViewModelBuf.m_BmpShopcartIcons[2];//"blank.png" ShopcartItem14.Name = "訂單已結帳"; ShopcartItem14.Amount = ""; ShopcartItem14.Price = ""; ShopcartItem14.Sum = ""; ShopcartItem14.image_id = MainWindowViewModelBuf.m_StrShopcartIcons[2]; ; ShopcartItem14.Font_Color = Brushes.Red; ShopcartItem14.Default_Color = Brushes.Red; ShopcartItem14.Font_Size = 20; ShopcartItem14.State = "0"; //狀態 - 無,折讓 / 折扣,小計[State] 0,1,2 ShopcartItem14.NameTextAlignment = TextAlignment.End; MainWindowViewModelBuf.m_ShopcartItems.Add(ShopcartItem14); //ShopcartListView.ScrollTo(m_ShopcartItems[m_ShopcartItems.Count - 1], ScrollToPosition.End, false); ShopcartListView.SelectedItem = MainWindowViewModelBuf.m_ShopcartItems[MainWindowViewModelBuf.m_ShopcartItems.Count - 1];//觸發執行 (購物車 選項 切換事件函數) break; case 15://主項(套餐)新增 if (m_ShopCart.m_ShopMainList[intMainArrayIndex].m_Strdel_flag != "Y") { ShopcartItem ShopcartItemMain15 = new ShopcartItem(); ShopcartItemMain15.id = intMainArrayIndex + "," + intSubArrayIndex + ",T"; ShopcartItemMain15.Image00 = MainWindowViewModelBuf.m_BmpShopcartIcons[0];//"checkbox00.png" ShopcartItemMain15.Image01 = MainWindowViewModelBuf.m_BmpShopcartIcons[2];//"blank.png" ShopcartItemMain15.Name = m_ShopCart.m_ShopMainList[intMainArrayIndex].m_StrName; ShopcartItemMain15.Amount = m_ShopCart.m_ShopMainList[intMainArrayIndex].m_intAmount.ToString(); ShopcartItemMain15.Price = m_ShopCart.m_ShopMainList[intMainArrayIndex].m_dblPrice.ToString(); ShopcartItemMain15.Sum = m_ShopCart.m_ShopMainList[intMainArrayIndex].m_dblSum.ToString(); ShopcartItemMain15.image_id = MainWindowViewModelBuf.m_StrShopcartIcons[0]; ShopcartItemMain15.Font_Color = Brushes.Black; ShopcartItemMain15.Default_Color = Brushes.Black; ShopcartItemMain15.Font_Size = 20; ShopcartItemMain15.State = "0"; ShopcartItemMain15.BColor = Brushes.Transparent; ShopcartItemMain15.NameTextAlignment = TextAlignment.Left; MainWindowViewModelBuf.m_ShopcartItems.Add(ShopcartItemMain15); //ShopcartListView.ScrollTo(m_ShopcartItems[m_ShopcartItems.Count - 1], ScrollToPosition.End, false); ShopcartListView.SelectedItem = MainWindowViewModelBuf.m_ShopcartItems[MainWindowViewModelBuf.m_ShopcartItems.Count - 1];//觸發執行 (購物車 選項 切換事件函數) } break; case 16://主項(套餐-產品)新增 if (m_ShopCart.m_ShopMainList[intMainArrayIndex].m_Strdel_flag != "Y") { ShopcartItem ShopcartItemMain16 = new ShopcartItem(); ShopcartItemMain16.id = intMainArrayIndex + "," + intSubArrayIndex + ",TP"; ShopcartItemMain16.Image00 = MainWindowViewModelBuf.m_BmpShopcartIcons[2];//"blank.png" ShopcartItemMain16.Image01 = MainWindowViewModelBuf.m_BmpShopcartIcons[2];//"blank.png" ShopcartItemMain16.Name = m_StrHalfTab + m_ShopCart.m_ShopMainList[intMainArrayIndex].m_StrName; ShopcartItemMain16.Amount = m_ShopCart.m_ShopMainList[intMainArrayIndex].m_intAmount.ToString(); ShopcartItemMain16.Price = m_ShopCart.m_ShopMainList[intMainArrayIndex].m_dblPrice.ToString(); ShopcartItemMain16.Sum = m_ShopCart.m_ShopMainList[intMainArrayIndex].m_dblSum.ToString(); ShopcartItemMain16.image_id = MainWindowViewModelBuf.m_StrShopcartIcons[2]; ShopcartItemMain16.Font_Color = Brushes.Black; ShopcartItemMain16.Default_Color = Brushes.Black; ShopcartItemMain16.Font_Size = 20; ShopcartItemMain16.State = "0"; ShopcartItemMain16.BColor = Brushes.Transparent; ShopcartItemMain16.NameTextAlignment = TextAlignment.Left; MainWindowViewModelBuf.m_ShopcartItems.Add(ShopcartItemMain16); //ShopcartListView.ScrollTo(m_ShopcartItems[m_ShopcartItems.Count - 1], ScrollToPosition.End, false); ShopcartListView.SelectedItem = MainWindowViewModelBuf.m_ShopcartItems[MainWindowViewModelBuf.m_ShopcartItems.Count - 1];//觸發執行 (購物車 選項 切換事件函數) } break; case 17://(套餐-產品)的調味品[多筆顯示成一筆]新增 int intInsertX17 = m_intShopcartSelectedIndex;//取得被選取的第一列旗標位置 int intShiftX17 = 0; if (m_ShopCart.m_ShopMainList[intMainArrayIndex].m_Strdiscount_type == "Y") { intShiftX17 += 2;//因為 折扣/折讓 顯示在加1的位置 } else { intShiftX17 += 1;// } //--- //產生調味品多筆合併一筆的顯示資訊 String StrAllSubNameX17 = m_StrTab; int intAllAmountX17 = 0; double dblAllSumX17 = 0; int intStringCountX17 = m_StrTab.Length / 2; for (int i = 0; i < m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList.Count; i++) { if (m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_Strdel_flag != "Y")//if (m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_Strdel_time != "Y") { intAllAmountX17 += m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_intAmount; dblAllSumX17 += m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_dblSum; String StrPrice = (m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_dblSum > 0) ? $"(${m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_dblSum})" : ""; if ((intStringCountX17 + m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_StrName.Length) < 17) { StrAllSubNameX17 += m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_StrName + StrPrice + ","; intStringCountX17 += m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_StrName.Length; } else { StrAllSubNameX17 += "\n" + m_StrTab + m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_StrName + StrPrice + ","; intStringCountX17 = m_StrTab.Length / 2; intStringCountX17 += m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_StrName.Length; } } } //---產生調味品多筆合併一筆的顯示資訊 ShopcartItem ShopcartItemMain17 = new ShopcartItem(); ShopcartItemMain17.id = intMainArrayIndex + "," + intSubArrayIndex + ",TPC"; ShopcartItemMain17.Image00 = MainWindowViewModelBuf.m_BmpShopcartIcons[2];//"blank.png" ShopcartItemMain17.Image01 = MainWindowViewModelBuf.m_BmpShopcartIcons[2];//"blank.png" ShopcartItemMain17.Name = StrAllSubNameX17.Substring(0, StrAllSubNameX17.Length - 1); ShopcartItemMain17.Amount = intAllAmountX17.ToString(); ShopcartItemMain17.Price = ""; ShopcartItemMain17.Sum = dblAllSumX17.ToString(); ShopcartItemMain17.image_id = MainWindowViewModelBuf.m_StrShopcartIcons[2]; ShopcartItemMain17.Font_Color = Brushes.Black; ShopcartItemMain17.Default_Color = Brushes.Black; ShopcartItemMain17.Font_Size = 20 - 1.5;//Device.GetNamedSize(NamedSize.Micro, typeof(Label)); ShopcartItemMain17.State = "0"; ShopcartItemMain17.BColor = Brushes.Transparent; ShopcartItemMain17.NameTextAlignment = TextAlignment.Left; MainWindowViewModelBuf.m_ShopcartItems.Add(ShopcartItemMain17); ShopcartListView.SelectedItem = MainWindowViewModelBuf.m_ShopcartItems[MainWindowViewModelBuf.m_ShopcartItems.Count - 1];//觸發執行 (購物車 選項 切換事件函數) break; case 18://主項(套餐)修改 ShopcartItem ShopcartItemMain18 = new ShopcartItem(); ShopcartItemMain18.id = MainWindowViewModelBuf.m_ShopcartItems[intSubArrayIndex].id;//陣列ID-[M,S] ShopcartItemMain18.Image00 = MainWindowViewModelBuf.m_BmpShopcartIcons[0];//"checkbox00.png" ShopcartItemMain18.Image01 = MainWindowViewModelBuf.m_BmpShopcartIcons[2];//"blank.png" ShopcartItemMain18.Name = m_ShopCart.m_ShopMainList[intMainArrayIndex].m_StrName; ShopcartItemMain18.Amount = m_ShopCart.m_ShopMainList[intMainArrayIndex].m_intAmount.ToString(); ShopcartItemMain18.Price = m_ShopCart.m_ShopMainList[intMainArrayIndex].m_dblPrice.ToString(); ShopcartItemMain18.Sum = m_ShopCart.m_ShopMainList[intMainArrayIndex].m_dblSum.ToString(); ShopcartItemMain18.image_id = MainWindowViewModelBuf.m_StrShopcartIcons[0]; ShopcartItemMain18.Font_Color = MainWindowViewModelBuf.m_ShopcartItems[intSubArrayIndex].Font_Color; ShopcartItemMain18.Default_Color = MainWindowViewModelBuf.m_ShopcartItems[intSubArrayIndex].Default_Color; ShopcartItemMain18.Font_Size = MainWindowViewModelBuf.m_ShopcartItems[intSubArrayIndex].Font_Size; ShopcartItemMain18.State = MainWindowViewModelBuf.m_ShopcartItems[intSubArrayIndex].State; ShopcartItemMain18.BColor = MainWindowViewModelBuf.m_ShopcartItems[intSubArrayIndex].BColor; ShopcartItemMain18.NameTextAlignment = TextAlignment.Left; //m_ShopcartItems.Insert(intSubArrayIndex, ShopcartItemMain18); //m_ShopcartItems.RemoveAt((intSubArrayIndex + 1)); MainWindowViewModelBuf.m_ShopcartItems[intSubArrayIndex] = ShopcartItemMain18; ShopcartListView.SelectedItem = MainWindowViewModelBuf.m_ShopcartItems[intSubArrayIndex];//觸發執行 (購物車 選項 切換事件函數) break; case 19://主項(套餐-產品)插入 if (m_ShopCart.m_ShopMainList[intMainArrayIndex].m_Strdel_flag != "Y") { ShopcartItem ShopcartItemMain19 = new ShopcartItem(); ShopcartItemMain19.id = intMainArrayIndex + "," + -1 + ",TP";//陣列ID-[M,S] ShopcartItemMain19.Image00 = MainWindowViewModelBuf.m_BmpShopcartIcons[2];//"blank.png" ShopcartItemMain19.Image01 = MainWindowViewModelBuf.m_BmpShopcartIcons[2];//"blank.png" ShopcartItemMain19.Name = m_StrHalfTab + m_ShopCart.m_ShopMainList[intMainArrayIndex].m_StrName; ShopcartItemMain19.Amount = m_ShopCart.m_ShopMainList[intMainArrayIndex].m_intAmount.ToString().ToString(); ShopcartItemMain19.Price = m_ShopCart.m_ShopMainList[intMainArrayIndex].m_dblPrice.ToString(); ShopcartItemMain19.Sum = m_ShopCart.m_ShopMainList[intMainArrayIndex].m_dblSum.ToString(); ShopcartItemMain19.image_id = MainWindowViewModelBuf.m_StrShopcartIcons[2]; ShopcartItemMain19.Font_Color = Brushes.Black; ShopcartItemMain19.Default_Color = Brushes.Black; ShopcartItemMain19.Font_Size = 20; ShopcartItemMain19.State = "0"; ShopcartItemMain19.BColor = Brushes.Transparent; ShopcartItemMain19.NameTextAlignment = TextAlignment.Left; MainWindowViewModelBuf.m_ShopcartItems.Insert(intSubArrayIndex, ShopcartItemMain19); ShopcartListView.SelectedItem = MainWindowViewModelBuf.m_ShopcartItems[intSubArrayIndex];//觸發執行 (購物車 選項 切換事件函數) } break; case 20://(套餐-產品)的調味品[多筆顯示成一筆]新增 int intInsertX20 = intSubArrayIndex; //--- //產生調味品多筆合併一筆的顯示資訊 String StrAllSubNameX20 = m_StrTab; int intAllAmountX20 = 0; double dblAllSumX20 = 0; int intStringCountX20 = m_StrTab.Length / 2; for (int i = 0; i < m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList.Count; i++) { if (m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_Strdel_flag != "Y")//if (m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_Strdel_time != "Y") { intAllAmountX20 += m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_intAmount; dblAllSumX20 += m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_dblSum; String StrPrice = (m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_dblSum > 0) ? $"(${m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_dblSum})" : ""; if ((intStringCountX20 + m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_StrName.Length) < 17) { StrAllSubNameX20 += m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_StrName + StrPrice + ","; intStringCountX20 += m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_StrName.Length; } else { StrAllSubNameX20 += "\n" + m_StrTab + m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_StrName + StrPrice + ","; intStringCountX20 = m_StrTab.Length / 2; intStringCountX20 += m_ShopCart.m_ShopMainList[intMainArrayIndex].m_ShopSubList[i].m_StrName.Length; } } } //---產生調味品多筆合併一筆的顯示資訊 ShopcartItem ShopcartItemMain20 = new ShopcartItem(); ShopcartItemMain20.id = intMainArrayIndex + "," + intSubArrayIndex + ",TPC"; ShopcartItemMain20.Image00 = MainWindowViewModelBuf.m_BmpShopcartIcons[2];//"blank.png" ShopcartItemMain20.Image01 = MainWindowViewModelBuf.m_BmpShopcartIcons[2];//"blank.png" ShopcartItemMain20.Name = StrAllSubNameX20.Substring(0, StrAllSubNameX20.Length - 1); ShopcartItemMain20.Amount = intAllAmountX20.ToString(); ShopcartItemMain20.Price = ""; ShopcartItemMain20.Sum = dblAllSumX20.ToString(); ShopcartItemMain20.image_id = MainWindowViewModelBuf.m_StrShopcartIcons[2]; ShopcartItemMain20.Font_Color = Brushes.Black; ShopcartItemMain20.Default_Color = Brushes.Black; ShopcartItemMain20.Font_Size = 20 - 1.5;//Device.GetNamedSize(NamedSize.Micro, typeof(Label)); ShopcartItemMain20.State = "0"; ShopcartItemMain20.BColor = Brushes.Transparent; ShopcartItemMain20.NameTextAlignment = TextAlignment.Left; MainWindowViewModelBuf.m_ShopcartItems.Insert((intInsertX20 + 0), ShopcartItemMain20); ShopcartListView.SelectedItem = MainWindowViewModelBuf.m_ShopcartItems[(intInsertX20 + 0)];//觸發執行 (購物車 選項 切換事件函數) break; case 21://coupon ~ 折價券 if (m_ShopCart.m_ShopMainList[intMainArrayIndex].m_Strdel_flag != "Y") { ShopcartItem ShopcartItemMain00 = new ShopcartItem(); ShopcartItemMain00.id = intMainArrayIndex + "," + intSubArrayIndex;//陣列ID-[M,S] ShopcartItemMain00.Image00 = MainWindowViewModelBuf.m_BmpShopcartIcons[2];//"blank.png" ShopcartItemMain00.Image01 = MainWindowViewModelBuf.m_BmpShopcartIcons[2];//"blank.png" ShopcartItemMain00.Name = m_ShopCart.m_ShopMainList[intMainArrayIndex].m_StrName; ShopcartItemMain00.Amount = "";//m_ShopCart.m_ShopMainList[intMainArrayIndex].m_intAmount.ToString(); ShopcartItemMain00.Price = "-" + m_ShopCart.m_ShopMainList[intMainArrayIndex].m_dblPrice.ToString(); ShopcartItemMain00.Sum = "-" + m_ShopCart.m_ShopMainList[intMainArrayIndex].m_dblPrice.ToString(); ShopcartItemMain00.image_id = MainWindowViewModelBuf.m_StrShopcartIcons[2]; ShopcartItemMain00.Font_Color = Brushes.Red; ShopcartItemMain00.Default_Color = Brushes.Red; ShopcartItemMain00.Font_Size = 20; ShopcartItemMain00.State = "1"; //狀態 - 無,折讓 / 折扣,小計[State] 0,1,2 ShopcartItemMain00.BColor = Brushes.Transparent; ShopcartItemMain00.NameTextAlignment = TextAlignment.Left; MainWindowViewModelBuf.m_ShopcartItems.Add(ShopcartItemMain00); //ShopcartListView.ScrollTo(m_ShopcartItems[m_ShopcartItems.Count - 1], ScrollToPosition.End, false); ShopcartListView.SelectedItem = MainWindowViewModelBuf.m_ShopcartItems[MainWindowViewModelBuf.m_ShopcartItems.Count - 1];//觸發執行 (購物車 選項 切換事件函數) } break; } } catch (Exception ex) { LogFile.Write("ShopcartListViewShowError ; " + ex.Message); } } private void CloseBtn_Clicked(object sender, RoutedEventArgs e) { m_blnRun = false; Close(); } private async void FooterBtn01_Clicked(object sender, RoutedEventArgs e) { if (!MainWindow.funcMainSet("temp_bill_print")) { await ExternalPopup.MessageBox(21,"您無[暫存訂單印表]的權限"); } else { if (m_StrdgvInforSelectOrderNo.Length > 0) { await ExternalPopup.OrderPrint(21, m_StrdgvInforSelectOrderNo, false, true); ExternalPopup.orderPrint = null; } } } private void FooterBtn02_Clicked(object sender, RoutedEventArgs e) { String SQL = String.Format("UPDATE order_data SET order_state='0', updated_time='{1}' WHERE order_no='{0}';", m_StrdgvInforSelectOrderNo, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")); SQLDataTableModel.SQLiteInsertUpdateDelete(SQL); m_blnRun = true; m_StrResult = m_StrdgvInforSelectOrderNo + ";" + m_StrdgvInforSelectorder_type + ";" + m_StrdgvInforSelectguests_num; Close(); } private async void FooterBtn03_Clicked(object sender, RoutedEventArgs e) { if (m_StrdgvInforSelectOrderNo.Length == 0) { return; } if (!MainWindow.funcMainSet("temp_product_modify")) { await ExternalPopup.MessageBox(21,"您無[暫存商品異動]的權限"); } else { String StrMsg = String.Format("你確定取消此訂單?\n訂單號 : {0}", m_StrdgvInforSelectOrderNo); await ExternalPopup.QuesMessageBox(21,StrMsg); if (QuesMessageBox.m_blnResult) { /* 把order_data的對應資料的del_flag設為Y 畫面初始化 */ String SQL = String.Format("UPDATE order_data SET order_state='0', del_flag='Y',updated_time='{1}' WHERE order_no='{0}';", m_StrdgvInforSelectOrderNo, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")); SQLDataTableModel.SQLiteInsertUpdateDelete(SQL); SyncDBFun.dataInsert("DOD", m_StrdgvInforSelectOrderNo); //--- //電子發票做廢 DataTable order_invoice_dataDataTable = new DataTable(); SQL = $"SELECT order_no FROM order_invoice_data WHERE inv_no='{m_StrdgvInforSelectOrderNo}'"; order_invoice_dataDataTable = SQLDataTableModel.GetDataTable(SQL); if (order_invoice_dataDataTable != null && order_invoice_dataDataTable.Rows.Count > 0) { SyncDBFun.dataInsert("INV_B2C_CANCEL", m_StrdgvInforSelectOrderNo); } //---電子發票做廢 orderdataGet(); LoadOrderStagingListItems();//載入清單資料 } } } private void dgInfo_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (dgInfo.SelectedItem!=null) { m_SelectedOrderStagingListItem=(OrderStagingListItem)dgInfo.SelectedItem; if ((m_SelectedOrderStagingListItem != null) && (m_SelectedOrderStagingListItem.order_no != null) && (m_SelectedOrderStagingListItem.order_no.Length > 0)) { m_StrdgvInforSelectOrderNo = m_SelectedOrderStagingListItem.order_no; m_StrdgvInforSelectorder_type = m_SelectedOrderStagingListItem.order_type_code; m_StrdgvInforSelectguests_num = m_SelectedOrderStagingListItem.guests_num; remarks.Text = m_SelectedOrderStagingListItem.remarks; ordercontentdataGet(); ordercontentdataShow(); ShopcartListView.ScrollIntoView(((OrderStagingListViewModel)DataContext).m_ShopcartItems.Count - 1); } } } private void ShopcartListView_ItemSelected(object sender, SelectionChangedEventArgs e) { int intLastSelectedIndex = -1; if (ShopcartListView.SelectedItem != null) { intLastSelectedIndex = m_intShopcartSelectedIndex; m_ShopcartItemSelected = (ShopcartItem)ShopcartListView.SelectedItem; m_intShopcartSelectedIndex = ShopcartListView.SelectedIndex; if ((m_intShopcartSelectedIndex < 0) || (m_ShopcartItemSelected == null)) { return; } if (intLastSelectedIndex == m_intShopcartSelectedIndex) { return; } //--- //改變選擇列顏色 ((OrderStagingListViewModel)DataContext).m_ShopcartItems[m_intShopcartSelectedIndex].Font_Color = Brushes.White; ((OrderStagingListViewModel)DataContext).m_ShopcartItems[m_intShopcartSelectedIndex].BColor = Brushes.Blue; if ((intLastSelectedIndex >= 0) && ((((OrderStagingListViewModel)DataContext).m_ShopcartItems.Count - 1) >= intLastSelectedIndex)) { ((OrderStagingListViewModel)DataContext).m_ShopcartItems[intLastSelectedIndex].Font_Color = ((OrderStagingListViewModel)DataContext).m_ShopcartItems[intLastSelectedIndex].Default_Color; ((OrderStagingListViewModel)DataContext).m_ShopcartItems[intLastSelectedIndex].BColor = Brushes.White; } //---改變選擇列顏色 } else { m_ShopcartItemSelected = null; m_intShopcartSelectedIndex = -1; return; } } private void ShopcartListViewImage00_Clicked(object sender, PointerPressedEventArgs e) { OrderStagingListViewModel MainWindowViewModelBuf = (OrderStagingListViewModel)DataContext; if (m_ShopcartItemSelected != null) { String StrBuf = m_ShopcartItemSelected.id; string[] strs = StrBuf.Split(','); int intMain = VP_Convert.ToInt32(strs[0]); int intSub = VP_Convert.ToInt32(strs[1]); if (intSub < 0) { if (m_ShopcartItemSelected.image_id == "checkbox00.png") { m_ShopcartItemSelected.image_id = "checkbox01.png";//not check m_ShopcartItemSelected.Image00 = MainWindowViewModelBuf.m_BmpShopcartIcons[1];//"checkbox01.png" } else { m_ShopcartItemSelected.image_id = "checkbox00.png";//checked m_ShopcartItemSelected.Image00 = MainWindowViewModelBuf.m_BmpShopcartIcons[0];//"checkbox00.png" } } } } private void ShopcartListViewImage01_Clicked(object sender, PointerPressedEventArgs e) { if (m_ShopcartItemSelected != null) { String StrBuf = m_ShopcartItemSelected.id; string[] strs = StrBuf.Split(','); int intIndex = VP_Convert.ToInt32(strs[0]); int intBuf = VP_Convert.ToInt32(strs[1]); } } }
One thought on “Avalonia 資料列表元件 [Avalonia DataGrid 四欄位 範例]”
avalonia datagrid odd rows color set red 使用程式碼實現
XAML
C#
private void dgInfo_LoadingRow(object sender, DataGridRowEventArgs e)
{
// 設置奇數行的背景顏色為紅色
if (e.Row.Index % 2 != 0)
{
e.Row.Background = Brushes.LightGray;
}
}