private void chooseMemberNameData() { MembersScData msds = FormMembersList.ReceiveItems(msd); if (msds == null) { return; } textBoxMemberCode.Text = msds.MemberCode; }
/// <summary> /// データグリッドビュー変更処理 /// </summary> /// <param name="TargetPoint"></param> private void DataGridViewChange(Point TargetPoint) { DataGridViewRow TargetdgvRow = this.dataGridViewList.Rows[TargetPoint.Y]; switch (TargetPoint.X) { // Wakamatsu 20170302 case 2: // 原価コード if (Convert.ToString(TargetdgvRow.Cells[9].Value) != "I") { TargetdgvRow.Cells[2].Value = CostKey.CostCodeH + CostKey.CostCodeNum; TargetdgvRow.Dispose(); return; } // 入力確認 string CheckCodeU = Convert.ToString(TargetdgvRow.Cells[2].Value).ToUpper(); string CheckResult = CostCodeCheck(CheckCodeU, TargetPoint.Y); if (CheckResult != "") { MessageBox.Show(CheckResult); TargetdgvRow.Cells[2].Value = CostKey.CostCodeH + CostKey.CostCodeNum; TargetdgvRow.Dispose(); return; } TargetdgvRow.Cells[1].Value = CheckCodeU.Substring(0, 1); TargetdgvRow.Cells[2].Value = CheckCodeU; string CheckCodeH = ""; if (CostKey.CostCodeH == "A" || CostKey.CostCodeH == "B") { if (CostKey.CostCodeH == "A") { CheckCodeH = "B"; } else { CheckCodeH = "A"; } if (Convert.ToString(TargetdgvRow.Cells[1].Value) == "A" || Convert.ToString(TargetdgvRow.Cells[1].Value) == "B") { // 変更前も変更後も原価コードの先頭文字列が"A"または"B"の場合 for (int i = 0; i < this.dataGridViewList.Rows.Count; i++) { if (Convert.ToString(this.dataGridViewList.Rows[i].Cells[2].Value) == CheckCodeH + CostKey.CostCodeNum && Convert.ToString(this.dataGridViewList.Rows[i].Cells[7].Value) == CostKey.MemberCode) { if (Convert.ToString(TargetdgvRow.Cells[1].Value) == "A") { CheckCodeH = "B"; } else { CheckCodeH = "A"; } this.dataGridViewList.Rows[i].Cells[1].Value = CheckCodeH; this.dataGridViewList.Rows[i].Cells[2].Value = CheckCodeH + Convert.ToString(TargetdgvRow.Cells[2].Value).Substring(1); } } } else { // 変更前の原価コードの先頭文字列が"A"または"B"で変更後の原価コードの先頭文字列が"A"または"B"でない場合 for (int i = 0; i < this.dataGridViewList.Rows.Count; i++) { if (Convert.ToString(this.dataGridViewList.Rows[i].Cells[2].Value) == CheckCodeH + CostKey.CostCodeNum && Convert.ToString(this.dataGridViewList.Rows[i].Cells[7].Value) == CostKey.MemberCode) { this.dataGridViewList.Rows.RemoveAt(i); } } TargetdgvRow.Cells[7].Value = ""; } } else { if (Convert.ToString(TargetdgvRow.Cells[1].Value) == "A" || Convert.ToString(TargetdgvRow.Cells[1].Value) == "B") { // 変更前の原価コードの先頭文字列が"A"または"B"でなく変更後の原価コードの先頭文字列が"A"または"B"場合 if (Convert.ToString(TargetdgvRow.Cells[1].Value) == "A") { CheckCodeH = "B"; } else { CheckCodeH = "A"; } TargetdgvRow.Cells[3].Value = ""; TargetdgvRow.Cells[6].Value = CheckDecimal("0"); TargetdgvRow.Cells[7].Value = ""; TargetdgvRow.Cells[10].Value = "[原価名称]を入力してください。"; this.dataGridViewList.Rows.Insert(TargetPoint.Y + 1); this.dataGridViewList.Rows[TargetPoint.Y + 1].Cells[1].Value = CheckCodeH; this.dataGridViewList.Rows[TargetPoint.Y + 1].Cells[2].Value = CheckCodeH + Convert.ToString(TargetdgvRow.Cells[2].Value).Substring(1); this.dataGridViewList.Rows[TargetPoint.Y + 1].Cells[3].Value = ""; this.dataGridViewList.Rows[TargetPoint.Y + 1].Cells[6].Value = CheckDecimal("0"); this.dataGridViewList.Rows[TargetPoint.Y + 1].Cells[7].Value = ""; this.dataGridViewList.Rows[TargetPoint.Y + 1].Cells[10].Value = "[原価名称]を入力してください。"; } } if (Convert.ToString(TargetdgvRow.Cells[1].Value) == "K") { if (Convert.ToString(TargetdgvRow.Cells[3].Value) == "" || Convert.ToString(TargetdgvRow.Cells[3].Value) == CODEL) { TargetdgvRow.Cells[3].Value = CODEK; } } else if (Convert.ToString(TargetdgvRow.Cells[1].Value) == "L" && Convert.ToString(TargetdgvRow.Cells[3].Value) == "") { if (Convert.ToString(TargetdgvRow.Cells[3].Value) == "" || Convert.ToString(TargetdgvRow.Cells[3].Value) == CODEK) { TargetdgvRow.Cells[3].Value = CODEL; } } break; // Wakamatsu 20170302 case 3: // 原価名称 if (Convert.ToString(TargetdgvRow.Cells[9].Value) != "I") { TargetdgvRow.Cells[3].Value = CostKey.CostName; TargetdgvRow.Dispose(); return; } if (Convert.ToString(TargetdgvRow.Cells[3].Value) == "") { // 社員番号を空欄とする TargetdgvRow.Cells[7].Value = ""; if (Convert.ToString(TargetdgvRow.Cells[1].Value) == "A" || Convert.ToString(TargetdgvRow.Cells[1].Value) == "B") { // 対となる原価コード変更 PairCostControl("", ""); } } else { if (Convert.ToString(TargetdgvRow.Cells[1].Value) == "A" || Convert.ToString(TargetdgvRow.Cells[1].Value) == "B") { // 原価名称編集後 ListFormDataOp lo = new ListFormDataOp(); // メンバー取得 MembersScData[] msdl = lo.SelectMembersScData(Convert.ToString(TargetdgvRow.Cells[3].Value), 0); MembersScData msd = null; if (msdl != null) { msd = FormMembersList.ReceiveItems(msdl); } if (msd == null) { // 選択されなかった場合 msd = new MembersScData(); msd.Name = ""; msd.MemberCode = ""; TargetdgvRow.Cells[3].Value = msd.Name; TargetdgvRow.Cells[7].Value = msd.MemberCode; } else { // 選択された社員情報を格納 TargetdgvRow.Cells[3].Value = msd.Name; TargetdgvRow.Cells[7].Value = msd.MemberCode; string OverlapCode = ""; // 重複原価コード格納用 string[] OverlapCodeList; // 重複原価コード格納用(配列) bool OverlapFlag = false; // 重複社員番号フラグ // 選択された場合 for (int i = 0; i < this.dataGridViewList.Rows.Count; i++) { if (Convert.ToString(this.dataGridViewList.Rows[i].Cells[1].Value) == "A" || Convert.ToString(this.dataGridViewList.Rows[i].Cells[1].Value) == "B") { // 原価コードが"A"または"B"の場合 if (Convert.ToString(this.dataGridViewList.Rows[i].Cells[7].Value) == msd.MemberCode) { // 社員番号が同じ場合 OverlapCode += Convert.ToString(this.dataGridViewList.Rows[i].Cells[2].Value) + ","; } } } // 社員番号重複確認 if (OverlapCode.Length != 0) { // 末尾の","を外す OverlapCode = OverlapCode.Substring(0, OverlapCode.Length - 1); } OverlapCodeList = OverlapCode.Split(','); if (OverlapCodeList.Length == 2) { // 社員番号の重複が2つの場合 if (OverlapCodeList[0].Substring(0, 1) == OverlapCodeList[1].Substring(0, 1)) { // 社員番号が重複している行の原価コードの先頭が同じ場合登録不可 OverlapFlag = true; } else if (OverlapCodeList[0].Substring(1) != OverlapCodeList[1].Substring(1)) { // 社員番号が重複している行の原価コードの先頭以外が異なる場合登録不可 OverlapFlag = true; } } else if (OverlapCodeList.Length > 2) { // 社員番号が重複している行が3行以上の場合登録不可 OverlapFlag = true; } if (OverlapFlag == true) { MessageBox.Show("原価コード:" + Convert.ToString(TargetdgvRow.Cells[2].Value) + "\r\n" + "原価名称:" + Convert.ToString(TargetdgvRow.Cells[3].Value) + "\r\n" + "すでに登録されている社員番号です。"); TargetdgvRow.Cells[3].Value = ""; TargetdgvRow.Cells[7].Value = ""; msd.Name = ""; msd.MemberCode = ""; } } if (Convert.ToString(TargetdgvRow.Cells[1].Value) == "B" && msd.Name != "") { TargetdgvRow.Cells[3].Value += CODEB; } // 対となる原価コード変更 PairCostControl(msd.Name, msd.MemberCode); } } // 変更確認 if (Convert.ToString(TargetdgvRow.Cells[3].Value) != CostKey.CostName) { if (Convert.ToString(TargetdgvRow.Cells[9].Value) != "I") { TargetdgvRow.Cells[9].Value = "U"; } } break; case 4: // 細別 // 変更確認 if (Convert.ToString(TargetdgvRow.Cells[4].Value) != CostKey.CostDetail) { if (Convert.ToString(TargetdgvRow.Cells[9].Value) != "I") { TargetdgvRow.Cells[9].Value = "U"; } } break; case 5: // 単位 // 変更確認 if (Convert.ToString(TargetdgvRow.Cells[5].Value) != CostKey.CostUnit) { if (Convert.ToString(TargetdgvRow.Cells[9].Value) != "I") { TargetdgvRow.Cells[9].Value = "U"; } } break; case 6: // 原価 TargetdgvRow.Cells[6].Value = CheckDecimal(Convert.ToString(TargetdgvRow.Cells[6].Value)); // 変更確認 if (Convert.ToString(TargetdgvRow.Cells[6].Value) != CostKey.SetCost) { if (Convert.ToString(TargetdgvRow.Cells[9].Value) != "I") { TargetdgvRow.Cells[9].Value = "U"; } } break; default: // その他 break; } // 入力確認 InputCheck(TargetPoint.Y); TargetdgvRow.Dispose(); }