数据对应状态
“数据库:要用的的那张表中要有状态的字段”
.Xaml页面:
.Cs页面:
将Text Block中的命令写到.Cs属性(没有的话自己加就完事了(#region那一套))中:
别忘记+上实例化数据模型
//临时表
DataTable dataTable;
//全局公共静态变量
public static WrapPanel WP;
public static Button BtnPH;
public static Button BtnInsert;
public static UserControl UC;
这是其中的一个,其他两个也是这样的
private string _txtKZ;
public string txt_KZ
{
get { return _txtKZ; }
set
{
if (_txtKZ != value)
{
_txtKZ = value;
RaisePropertyChanged(() => txt_KZ);
}
}
}
//已付款台数
private string _txtYFK;
public string txt_YFK
{
get { return _txtYFK; }
set
{
if (_txtYFK != value)
{
_txtYFK = value;
RaisePropertyChanged(() => txt_YFK);
}
}
}
//显示待付款台数
private string _txtDFK;
public string txt_DFK
{
get { return _txtDFK; }
set
{
if (_txtDFK != value)
{
_txtDFK = value;
RaisePropertyChanged(() => txt_DFK);
}
}
}
然后就是命令层了:
//页面的加载命令?
public RelayCommand LoadedCommand { get; private set; }
函数层:
public void SelectOrder(UserControl uc)
{
UserControl myUC = (UserControl)uc;//传参传递的是用户空间自身
UC = myUC;
DependencyObject parent = VisualTreeHelper.GetParent(myUC);
//获取Button
List btn = FindVisualChildren.FindVisualChildrens(parent);
BtnPH = btn[2];
BtnInsert = btn[2];
//获取WrapPanel
List wp = FindVisualChildren.FindVisualChildrens(parent);
WP = wp[0];
if (WP != null)
{
WP.Children.Clear();
}
//查询餐桌信息
var TableOrder = (from tbType in myModel.R_TableType
orderby tbType.TableTypeName
select tbType).ToList();
dataTable = ListToDataTable.ListToDataTablen(TableOrder);
if(dataTable != null)
{
for (int i = 0; i < dataTable.Rows.Count; i++)
{
//把餐桌添加到WrapPanel
在给餐桌页面传值时,要用到状态数据页面
KaiTaiNeiRong NeiRong = new KaiTaiNeiRong();
WP.Children.Add(NeiRong);
//给餐桌页面传值
int tableTypeID = Convert.ToInt32(dataTable.Rows[i][“TableTypeID”].ToString());
var homeView = (NeiRong.DataContext as OpenContentViewModel);
homeView.TableTypeID = tableTypeID;
homeView.DiningTable += Item_DiningTable;
}
}
//根据餐桌状态
var dd = (from tbTbale in myModel.R_TableType
where tbTbale.Status == “已付款”
select tbTbale).ToList();
if (dd.Count >= 1)
{
BtnInsert.Opacity = 1;
}
else
{
BtnInsert.Opacity = 0;
}
var KZ = (from tbTable in myModel.R_TableType
where tbTable.Status == "空桌"
select tbTable).ToList();
var DFK = (from tbTable in myModel.R_TableType
where tbTable.Status == "待付款"
select tbTable).ToList();
txt_KZ = KZ.Count.ToString() + " 台";
txt_YFK = dd.Count.ToString() + " 台";
txt_DFK = DFK.Count.ToString() + " 台";
if (KZ.Count > 0)
{
BtnPH.Opacity = 0;
}
else
{
BtnPH.Opacity = 1;
}
}
//刷新座椅状态
private void Item_DiningTable()
{
SelectOrder(UC);
}
上一篇: 自定义-多选框使用