/// <summary> /// 获取功能类型 /// </summary> /// <param name="baseType"></param> /// <returns></returns> private string[] GetFuncType(string baseType) { int number = GoodsDictionarys.Instance().GoodsBaseType[baseType]; var funcType = GoodsDictionarys.Instance().GoodsFuncType(number); return(funcType.Values.ToArray()); }
/// <summary> /// 物品名称管理类单例获取 /// </summary> /// <returns></returns> public static GoodsDictionarys Instance() { if (instance == null) { instance = new GoodsDictionarys(); } return(instance); }
/// <summary> /// 控件初始化 /// </summary> private void Init() { var baseType = GoodsDictionarys.Instance().GoodsBaseType.Keys.ToList(); this.GoodsBaseTypeColumn.Items.Clear(); this.baseType = baseType.ToArray(); this.GoodsBaseTypeColumn.Items.AddRange(baseType.ToArray()); }
private void DataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex >= 4 && e.ColumnIndex <= 6) { DataGridViewComboBoxCell cell4x = dataGridView1[4, e.RowIndex] as DataGridViewComboBoxCell; DataGridViewComboBoxCell cell5x = dataGridView1[5, e.RowIndex] as DataGridViewComboBoxCell; DataGridViewComboBoxCell cell6x = dataGridView1[6, e.RowIndex] as DataGridViewComboBoxCell; if (e.ColumnIndex == 4 && cell4x.Value != null) { RefreshFuncTypeComboxItems(e.RowIndex); RefreshSpecialTypeComboxItems(e.RowIndex); } if (e.ColumnIndex == 5 && cell5x.Value != null) { RefreshSpecialTypeComboxItems(e.RowIndex); } if (cell4x.Value != null && cell5x.Value != null && cell6x.Value != null) { int baseType = GoodsDictionarys.Instance().GoodsBaseType[cell4x.Value.ToString()]; var funcTypes = GoodsDictionarys.Instance().GoodsFuncType(baseType); int funcNumber = funcTypes.ToDictionary(kv => kv.Value, kv => kv.Key)[cell5x.Value.ToString()]; var specialComboxItems = GoodsDictionarys.Instance().GoodSpecialType(funcNumber); int specialNumer = specialComboxItems.ToDictionary(kv => kv.Value, kv => kv.Key)[cell6x.Value.ToString()]; string idHeader = specialNumer.ToString(); //产生id List <int> ids = new List <int>(); for (int i = 0; i < dataGridView1.RowCount; i++) { if (i != dataGridView1.CurrentCell.RowIndex) { if (dataGridView1[0, i].Value == null) { continue; } int id = int.Parse(dataGridView1[0, i].Value.ToString()); ids.Add(id); } } var SameKindId = ids.Where(id => id.ToString().Substring(0, 4).Equals(idHeader)).Select(id => Convert.ToInt32(id.ToString().Substring(4))).ToArray(); Array.Sort(SameKindId); string generateID = string.Empty; if (SameKindId.Length == 0) { generateID = idHeader + "001"; } else { generateID = idHeader + (SameKindId.Last() + 1).ToString().PadLeft(3, '0'); } dataGridView1[0, dataGridView1.CurrentCell.RowIndex].Value = generateID; } } }
/// <summary> /// 获取特殊类型列表 /// </summary> /// <param name="funcType"></param> /// <param name="baseType"></param> /// <returns></returns> private string[] GetSpecialType(string funcType, string baseType) { int baseTypeNumber = GoodsDictionarys.Instance().GoodsBaseType[baseType]; var funcTypes = GoodsDictionarys.Instance().GoodsFuncType(baseTypeNumber); int funcNumber = funcTypes.ToDictionary(kv => kv.Value, kv => kv.Key)[funcType]; var specialComboxItems = GoodsDictionarys.Instance().GoodSpecialType(funcNumber); return(specialComboxItems.Values.ToArray()); }
/// <summary> /// 刷新功能类型选择框 /// </summary> /// <param name="row"></param> private void RefreshFuncTypeComboxItems(int row) { DataGridViewComboBoxCell cell4x = dataGridView1[4, row] as DataGridViewComboBoxCell; DataGridViewComboBoxCell cell5x = dataGridView1[5, row] as DataGridViewComboBoxCell; int number = GoodsDictionarys.Instance().GoodsBaseType[cell4x.Value.ToString()]; var funcType = GoodsDictionarys.Instance().GoodsFuncType(number); cell5x.DataSource = funcType.Values.ToArray(); cell5x.Value = funcType.Values.ToArray()[0]; }
/// <summary> /// 刷新具体类型选择框 /// </summary> /// <param name="rowIndex"></param> private void RefreshSpecialTypeComboxItems(int rowIndex) { DataGridViewComboBoxCell cell4x = dataGridView1[4, rowIndex] as DataGridViewComboBoxCell; DataGridViewComboBoxCell cell5x = dataGridView1[5, rowIndex] as DataGridViewComboBoxCell; DataGridViewComboBoxCell cell6x = dataGridView1[6, rowIndex] as DataGridViewComboBoxCell; int baseType = GoodsDictionarys.Instance().GoodsBaseType[cell4x.Value.ToString()]; var funcTypes = GoodsDictionarys.Instance().GoodsFuncType(baseType); int funcNumber = funcTypes.ToDictionary(kv => kv.Value, kv => kv.Key)[cell5x.Value.ToString()]; var specialComboxItems = GoodsDictionarys.Instance().GoodSpecialType(funcNumber); cell6x.DataSource = specialComboxItems.Values.ToArray(); cell6x.Value = specialComboxItems.Values.ToArray()[0]; }
/// <summary> /// 按物品基础属性向表格中添加一行 /// </summary> /// <param name="ID"></param> /// <param name="Name"></param> private void AddUnits(string ID, string Name, float weight, int price, string complain) { string itemType = GoodsDictionarys.Instance().GetGoodsType(int.Parse(ID)); string[] ItemType = itemType.Split(','); if (ItemType.Length == 3) { DataGridViewRow r = new DataGridViewRow(); DataGridViewCell[] cell = new DataGridViewCell[8]; for (int i = 0; i < cell.Length; i++) { if (i == 4 || i == 5 || i == 6) { cell[i] = new DataGridViewComboBoxCell() { FlatStyle = FlatStyle.Flat, Style = new DataGridViewCellStyle() { BackColor = Color.White } }; } else { cell[i] = new DataGridViewTextBoxCell(); } } cell[0].ToolTipText = "双击设置详细信息"; cell[0].Value = ID; cell[1].Value = Name; cell[2].Value = weight; cell[3].Value = price; var cell4 = cell[4] as DataGridViewComboBoxCell; cell4.Items.AddRange(baseType); cell4.Value = ItemType[0]; var cell5 = cell[5] as DataGridViewComboBoxCell; cell5.Items.AddRange(GetFuncType(ItemType[0])); cell[5].Value = ItemType[1]; var cell6 = cell[6] as DataGridViewComboBoxCell; string[] items = GetSpecialType(ItemType[1], ItemType[0]); cell6.Items.AddRange(items); cell6.Value = ItemType[2]; cell[7].Value = complain; r.Cells.AddRange(cell); dataGridView1.Rows.Add(r); } }
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { textBox2.Text = GoodsDictionarys.Instance().GetGoodsNatrue(int.Parse(comboBox1.Text.Split('~')[0])); }