/// <summary> /// 这是把一级货种放到下拉列表里 /// </summary> /// <param name="cells"></param> /// <param name="select"></param> /// <returns></returns> public DataGridViewCell CellToCombox(DataGridViewCell cells) { string id = new BaseService <GoodsTypeUp>().GetRecord(" name='" + cells.Value.ToString() + "'").ID; List <GoodsTypeUp> goods = new BaseService <GoodsTypeUp>().GetRecords(" 1=1 "); goods.Insert(0, new GoodsTypeUp() { ID = "0", Name = "--请选择--" }); DataGridViewComboBoxCell dvcb = new DataGridViewComboBoxCell(); dvcb.DataSource = goods; dvcb.ValueMember = "ID"; dvcb.DisplayMember = "Name"; cells = dvcb; cells.Value = (string.IsNullOrEmpty(id) ? "0" : id); return(cells); }
/// <summary> /// 更改成选择方式 /// </summary> /// <param name="cell"></param> /// <returns></returns> public DataGridViewCell CellToComboBox(DataGridViewCell cell) { DataGridViewComboBoxCell combox = new DataGridViewComboBoxCell(); switch (cell.ColumnIndex) { case 4: //箱子重量 重新录入 if (cell.Value != null) { try { double.Parse(cell.Value.ToString()); cell.Style.BackColor = Color.White; } catch (Exception) { cell.Style.BackColor = Color.Red; } } else { //当为空时候的判断 是否是空箱 cell.Value = "0"; cell.Style.BackColor = Color.Red; } break; case 5: //箱子型 List <BoxSize> bs = new BaseService <BoxSize>().GetRecords(" 1=1"); combox.DataSource = bs; combox.ValueMember = "Name"; combox.DisplayMember = "Name"; combox.Value = cell.Value.ToString(); cell = combox; break; case 7: //船公司 List <Company> cp = new BaseService <Company>().GetRecords(" 1=1"); cp.Insert(0, new Company() { ID = "0", Name = "" }); combox.DataSource = cp; combox.ValueMember = "Name"; combox.DisplayMember = "Name"; combox.Value = cell.Value.ToString(); cell = combox; break; case 8: //目的港 List <Aim> ai = new BaseService <Aim>().GetRecords(" 1=1"); ai.Insert(0, new Aim() { ID = "0", Name = "" }); combox.DataSource = ai; combox.ValueMember = "Name"; combox.DisplayMember = "Name"; combox.Value = cell.Value.ToString(); cell = combox; break; case 9: //货种 List <GoodsType> good = new BaseService <GoodsType>().GetRecords(" 1=1"); good.Insert(0, new GoodsType() { ID = "0", Name = "" }); combox.DataSource = good; combox.ValueMember = "Name"; combox.DisplayMember = "Name"; combox.Value = cell.Value.ToString(); cell = combox; break; case 10: List <WorkPlace> work = new BaseService <WorkPlace>().GetRecords(" 1=1"); work.Insert(0, new WorkPlace() { ID = "0", Name = "" }); combox.DataSource = work; combox.ValueMember = "Name"; combox.DisplayMember = "Name"; combox.Value = cell.Value.ToString(); cell = combox; break; case 11: List <Proxy> proxy = new BaseService <Proxy>().GetRecords(" 1=1"); proxy.Insert(0, new Proxy() { ID = "0", Name = "" }); combox.DataSource = proxy; combox.ValueMember = "Name"; combox.DisplayMember = "Name"; combox.Value = cell.Value.ToString(); cell = combox; break; case 14: List <Source> source = new BaseService <Source>().GetRecords(" 1=1"); source.Insert(0, new Source() { ID = "0", Name = "" }); combox.DataSource = source; combox.ValueMember = "Name"; combox.DisplayMember = "Name"; combox.Value = cell.Value.ToString(); cell = combox; break; case 15: List <Direction> dt = new BaseService <Direction>().GetRecords(" 1=1"); dt.Insert(0, new Direction() { ID = "0", Name = "" }); combox.DataSource = dt; combox.ValueMember = "Name"; combox.DisplayMember = "Name"; combox.Value = cell.Value.ToString(); cell = combox; break; case 16: List <SendPlace> send = new BaseService <SendPlace>().GetRecords(" 1=1"); send.Insert(0, new SendPlace() { ID = "0", Name = "" }); combox.DataSource = send; combox.ValueMember = "Name"; combox.DisplayMember = "Name"; combox.Value = cell.Value.ToString(); cell = combox; break; case 17: foreach (string item in CommValue.BoxVirtual) { combox.Items.Add(item); } combox.Value = cell.Value.ToString(); cell = combox; break; case 6: List <BoxState> state = new BaseService <BoxState>().GetRecords(" 1=1"); combox.DataSource = state; combox.ValueMember = "Name"; combox.DisplayMember = "Name"; combox.Value = cell.Value.ToString(); cell = combox; break; } return(cell); }