public void combineGroup(Group g) /*將單一group合併到本group*/ { //確認g是單一Group if (g.Qty.Count > 1) { //Globals.ThisAddIn.odiMsgOut("[Error] Can't comine complex group, check code!"); MessageBox.Show("[Error] Can't comine complex group, check code!"); return; } else { //合併main source資料 Qty.Add(g.Qty[0]); ProjectName.Add(g.ProjectName[0]); SCHVersion.Add(g.SCHVersion[0]); BOMVersion.Add(g.BOMVersion[0]); BOMKey.Add(g.getBomKey()); //歷遍目前AVL,找到相同的合併,並且從g移除 bool foundAVLing; foreach (var i in AVL) { foundAVLing = g.AVL.TryGetValue(i.Key, out Item gi); i.Value.ProjectName.Add(g.ProjectName[0]); //不論有沒有找到,都要增加project欄位 i.Value.SCHVersion.Add(g.SCHVersion[0]); i.Value.BOMVersion.Add(g.BOMVersion[0]); i.Value.BOMKey.Add(g.getBomKey()); if (foundAVLing) { i.Value.Qty.Add(gi.Qty[0]); g.AVL.Remove(i.Key); } else { i.Value.Qty.Add(0); } } //如果g還有剩下(新的)AVL item,則加入目前的AVL dictionary, 並且補足其前面的空白欄位 if (g.AVL.Count > 0) { foreach (var j in g.AVL) { j.Value.ProjectName = ProjectName; j.Value.SCHVersion = SCHVersion; j.Value.BOMVersion = BOMVersion; j.Value.BOMKey = BOMKey; for (int k = 0; k < Qty.Count() - 1; k++) { j.Value.Qty.Insert(0, 0); } AVL.Add(j.Key, j.Value); } } } }
private void btn_save_Click(object sender, EventArgs e) { if (formHelper.inputCheck(this.groupBox1)) { projectNameObj = new projectName(); projectNameObj.itemProject = this.txt_itemProject.Text.Trim(); projectNameObj.name = this.txt_name.Text.Trim(); projectNameObj.no = this.txt_no.Text.Trim(); projectNameObj.position = this.txt_position.Text.Trim(); projectNameObj.subsectionProject = this.txt_subsectionProject.Text.Trim(); projectNameObj.unitProject = this.txt_unitProject.Text.Trim(); projectNameObj.inputMan = this.UserName; bool isExist = doProjectName.selectItems(projectNameObj); if (isExist) { MessageBox.Show("此记录已经存在无法添加!"); ClearAllTextBox(); return; } else { doProjectName.Add(projectNameObj); } query(); } ClearAllTextBox(); }