using DevExpress.XtraEditors;
using SqlSugar;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using ZJ_BYD.DB;
namespace ZJ_BYD.Common
{
public class BindCombox
{
///
/// 绑定数据类型
///
///
public static void BindDataType(ComboBoxEdit comboBoxEdit)
{
comboBoxEdit.Properties.Items.Add(new ListItem { Text = "bool", Value = "bool" });
comboBoxEdit.Properties.Items.Add(new ListItem { Text = "short", Value = "short" });
comboBoxEdit.Properties.Items.Add(new ListItem { Text = "ushort", Value = "ushort" });
comboBoxEdit.Properties.Items.Add(new ListItem { Text = "int", Value = "int" });
comboBoxEdit.Properties.Items.Add(new ListItem { Text = "float", Value = "float" });
comboBoxEdit.Properties.Items.Add(new ListItem { Text = "double", Value = "double" });
comboBoxEdit.Properties.Items.Add(new ListItem { Text = "string", Value = "string" });
}
///
/// 绑定机型下拉框
///
///
public static void BindMachineType(ComboBoxEdit cmbMachineType)
{
var machineTypes = MskCodeHelper.QueryMskCodes()
.Select(m => new ListItem
{
Value = m.ProductSfcCode,
Text = m.ProductSfcCode
}).Distinct().ToList();
foreach (var item in machineTypes)
{
cmbMachineType.Properties.Items.Add(item);
}
}
///
/// 绑定机型下拉框
///
///
public static void BindMachineTypeForAhead(ComboBoxEdit cmbMachineType)
{
var machineTypes = MskCodeHelper.QueryMskCodes()
.Select(m => new ListItem
{
Value = SqlFunc.MergeString(m.Category, "_", m.ProductSfcCode),
Text = m.ProductSfcCode
}).Distinct().ToList();
foreach (var item in machineTypes)
{
cmbMachineType.Properties.Items.Add(item);
}
}
///
/// 绑定机型下拉框
///
///
public static void MainBindMachineType(LookUpEdit control)
{
var list = MskCodeHelper.QueryMskCodes()
.Select(m => new ListItem
{
Value = m.SortIndex.ToString(),
Text = m.Category
}).Distinct().ToList();
control.Properties.ValueMember = "Value";
control.Properties.DisplayMember = "Text";
control.Properties.DataSource = list;
}
///
/// 手动打印时绑定机型
///
///
public static void BindMachieTypeForLookUp(LookUpEdit control)
{
var list = MskCodeHelper.QueryMskCodes()
.Select(m => new ListItem
{
Value = m.BarCodeChar,
Text = m.ProductSfcCode.Trim('*')
}).ToList();
control.Properties.ValueMember = "Value";
control.Properties.DisplayMember = "Text";
control.Properties.DataSource = list;
}
///
/// 绑定机型-主界面
///
///
public static void BindMachieTypeMainForLookUp(LookUpEdit control)
{
var list = MskCodeHelper.QueryMskCodes()
.Select(m => new ListItem
{
Value = m.Category,
Text = m.Category
}).ToList();
control.Properties.ValueMember = "Value";
control.Properties.DisplayMember = "Text";
control.Properties.DataSource = list;
}
///
/// 绑定使用状态
///
///
public static void BindUseStatusForLookUp(LookUpEdit control)
{
var list = new List();
list.Add(new ListItem() { Value = "false", Text = "未使用" });
list.Add(new ListItem() { Value = "true", Text = "使用中" });
control.Properties.ValueMember = "Value";
control.Properties.DisplayMember = "Text";
control.Properties.DataSource = list;
}
///
/// 根据路线绑定工位下拉框
///
///
///
public static void BindStationByCategory(ComboBoxEdit cmbStation, string category)
{
var defaultItem = new ListItem
{
Value = "",
Text = "--请选择--",
};
var stations = StationHelper.QueryActiveStations()
.WhereIF(!string.IsNullOrWhiteSpace(category), m => m.Category == category)
.OrderBy(m => m.Category).OrderBy(m => m.SortIndex)
.Select(m => new ListItem
{
Value = m.StationCode,
Text = SqlFunc.MergeString(m.Category, "_", m.StationName, "(", m.StationCode, ")")
}).ToList();
stations.Insert(0, defaultItem);
foreach (var item in stations)
{
cmbStation.Properties.Items.Add(item);
}
}
///
/// 绑定工位下拉框
///
///
public static void BindStation(ComboBoxEdit cmbStation)
{
var defaultItem = new ListItem
{
Value = "",
Text = "--请选择--",
};
var stations = StationHelper.QueryActiveStations()
.OrderBy(m => m.Category).OrderBy(m => m.SortIndex)
.Select(m => new ListItem
{
Value = m.StationCode,
Text = SqlFunc.MergeString(m.Category, "-", m.StationName)
}).ToList();
stations.Insert(0, defaultItem);
foreach (var item in stations)
{
cmbStation.Properties.Items.Add(item);
}
}
///
/// 绑定工位
///
///
///
public static void BindStationForLookUp(LookUpEdit control, string defaultVal = "")
{
var list = new List();
var defaultItem = new ListItem
{
Value = "",
Text = "--请选择--",
};
list.Add(defaultItem);
list = StationHelper.QueryActiveStations()
.OrderBy(m => m.Category).OrderBy(m => m.SortIndex)
.Select(m => new ListItem
{
Value = m.StationCode,
Text = SqlFunc.MergeString(m.Category, "-", m.StationName)
}).ToList();
if (!string.IsNullOrWhiteSpace(defaultVal))
{
control.EditValue = defaultVal;
}
control.Properties.ValueMember = "Value";
control.Properties.DisplayMember = "Text";
control.Properties.DataSource = list;
}
///
/// 通过机型绑定工位下拉框
///
///
///
public static void BindStationByMachineType(ComboBoxEdit comboBoxEdit, string machineTypeCode)
{
var list = MskCodeHelper.QueryMaChineTypeStationVM(machineTypeCode).ToList();
if (list.Count > 0)
{
foreach (var item in list)
{
var listItem = new ListItem
{
Value = item.StationCode,
Text = $"{item.Category}-{item.StationName}({item.StationCode})"
};
comboBoxEdit.Properties.Items.Add(listItem);
}
}
}
///
/// 绑定系统模式下拉框
///
///
public static void BindSystemMode(ComboBoxEdit comboBoxEdit)
{
comboBoxEdit.Properties.Items.Add(new ListItem { Text = "MES在线模式", Value = "1" });
comboBoxEdit.Properties.Items.Add(new ListItem { Text = "MES离线模式", Value = "0" });
}
///
/// 绑定是否下拉框
///
///
public static void BindIsOk(ComboBoxEdit comboBoxEdit)
{
comboBoxEdit.Properties.Items.Add(new ListItem { Text = "是", Value = "1" });
comboBoxEdit.Properties.Items.Add(new ListItem { Text = "否", Value = "0" });
}
///
/// 绑定字段
///
///
///
public static void BindResultColumn(ComboBoxEdit comboBoxEdit, string stationCode)
{
comboBoxEdit.Properties.Items.Clear();
var usedCols = PlcPointHelper.GetUsedCol(stationCode);
for (int i = 1; i < 51; i++)
{
var val = string.Format("Column{0}", i);
if (usedCols.Count > 0)
{
if (!usedCols.Contains(val))
{
comboBoxEdit.Properties.Items.Add(new ListItem { Text = val, Value = val });
}
}
else
{
comboBoxEdit.Properties.Items.Add(new ListItem { Text = val, Value = val });
}
}
}
///
/// 绑定地域
///
///
public static void BindAreaForLookUp(LookUpEdit control)
{
var list = new List();
var defaultItem = new ListItem
{
Value = "",
Text = "--请选择--",
};
list = AreaHelper.QueryAreas()
.Select(m => new ListItem
{
Value = m.AreaCode,
Text = m.AreaName,
Selected = m.DefaultSelected
}).ToList();
list.Insert(0, defaultItem);
control.Properties.ValueMember = "Value";
control.Properties.DisplayMember = "Text";
control.Properties.DataSource = list;
}
///
/// 绑定线路
///
///
public static void BindCategoryForLookUp(LookUpEdit control)
{
var list = new List();
var defaultItem = new ListItem
{
Value = "",
Text = "--请选择--",
};
list = MskCodeHelper.QueryMskCodes()
.Select(m => new ListItem
{
Value = m.Category,
Text = m.Category,
Selected = m.IsUsed
}).Distinct().ToList();
list.Insert(0, defaultItem);
control.Properties.DataSource = list;
}
///
/// 绑定工厂
///
///
///
public static void BindDeptForLookUp(LookUpEdit control, string areaCode)
{
var list = new List();
var defaultItem = new ListItem
{
Value = "",
Text = "--请选择--",
};
list = DeptHelper.QueryDeptsByAreaCode(areaCode)
.Select(m => new ListItem
{
Value = m.DeptCode,
Text = m.DeptName,
Selected = m.DefaultSelected
}).ToList();
list.Insert(0, defaultItem);
control.Properties.ValueMember = "Value";
control.Properties.DisplayMember = "Text";
control.Properties.DataSource = list;
}
}
}