679
社区成员
发帖
与我相关
我的任务
分享
public static void ConvertRow()
{
TenantsListWindow TLW = (TenantsListWindow)TL;
for (int i = 0; i < TLW.tenantsDg.Items.Count; i++)
{
Quartecost quarte = TLW.tenantsDg.Items[i] as Quartecost;
string state = quarte.State.Trim();
if (state == "已交")
{
var row = TLW.tenantsDg.ItemContainerGenerator.ContainerFromItem(quarte) as DataGridRow;
row.Background = new SolidColorBrush(Colors.DarkSeaGreen);
}
else
{
var row = TLW.tenantsDg.ItemContainerGenerator.ContainerFromItem(quarte) as DataGridRow;
row.Background = new SolidColorBrush(Colors.IndianRed);
}
}
}
private void jiaofeiquedingBut_Click(object sender, RoutedEventArgs e)
{
ComboBoxItem cbi = (ComboBoxItem)jiaofeizhuangtaiCb.SelectedItem;
string item;
if (cbi != null)
{
item = (string)cbi.Tag;
tenantsDg.ItemsSource = QuartecostDAL.GetAllCommunity(item, community);
update = true;
//我如果在这里执行ConvertRow函数的话,那么ConvertRow函数中变量row就是null;
}
else
MessageBox.Show("请选择一个状态", "提示", MessageBoxButton.OK, MessageBoxImage.Error);
}
DataGridRow row = e.Row;
Quartecost quartecost = (Quartecost)row.DataContext;
if(quartecost.State.Trim() == "已交")
row.Background = new SolidColorBrush(Colors.DarkSeaGreen);
else
row.Background = new SolidColorBrush(Colors.IndianRed);
//放在DataGrid的LoadingRow事件里
我把答案贴出来吧,免得又有新手跟我一样,就这几行代码找了将近一礼拜.
public static List<Quartecost> GetAllCommunity(string filter,string community)
{
string sql = "select * from T_Quartecost", name;
bool state;
DataTable table = CommunityManagerSystemTools.ExecuteDataTable(sql);
List<Quartecost> quartecostlist = new List<Quartecost>();
for (int i = 0; i < table.Rows.Count; i++)
{
DataRow row = table.Rows[i];
Quartecost quartecost = new Quartecost();
quartecost.Id = (long)row["ID"];
quartecost.Tid = (long)row["TID"];
quartecost.Name = (string)row["Name"];
name = quartecost.Name.Trim();
quartecost.Type = (string)row["Type"];
quartecost.Waterdosage = Convert.ToDecimal(row["Waterdosage"]);
quartecost.Watercost = Convert.ToDecimal(row["Watercost"]);
quartecost.Electricitydosage = Convert.ToDecimal(row["Electricitydosage"]);
quartecost.Electricitycost = Convert.ToDecimal(row["Electricitycost"]);
quartecost.Healthcost = Convert.ToDecimal(row["Healthcost"]);
quartecost.Elevatorcost = Convert.ToDecimal(row["Elevatorcost"]);
quartecost.Heatingcost = Convert.ToDecimal(row["Heatingcost"]);
quartecost.Total = Convert.ToDecimal(row["Total"]);
Tenants tenants = TenantsDAL.GetByName(name);
if (tenants.Community.Trim() == community)
{
state = Convert.ToBoolean(row["State"]);
if (state == false)
{
quartecost.State = "未交";
}
else
quartecost.State = "已交";
quartecost.Time = (string)row["Time"];
quartecost.IsDel = Convert.ToBoolean(row["IsDel"]);
quartecost.IsInput = Convert.ToBoolean(row["IsInput"]);
if (quartecost.IsDel == false)
{
if (filter != null)
{
if (quartecost.Type.Trim() == CommunityManagerSystemTools.ConvertDbType(filter))
quartecostlist.Add(quartecost);
else if (quartecost.State == filter)
quartecostlist.Add(quartecost);
}
else
{
quartecostlist.Add(quartecost);
}
}
}
}
return quartecostlist;
}