/************************************************************* * 登録ボタン押下時の処理 *************************************************************/ private void btnAppend_Click(object sender, EventArgs e) { if (Program.MessageBoxBefore("登録しますか?") == DialogResult.Yes) { // 登録データのオブジェクトを作成 var entity = new ProductCode() { code = textRegCode.Text, year = Const.TARGET_YEAR, name = textRegName.Text, unit = textRegUnit.Text, kbn = getProductKbn(groupKbn1), note = textRegNote.Text, update_user = string.Concat(SystemInformation.ComputerName, "/", SystemInformation.UserName), update_date = DateTime.Now, del_flg = Const.FLG_OFF }; // データ登録処理(既に同じコードが存在する場合は登録しない) using (var context = new CostAccountingEntities()) { var target = from t in context.ProductCode where t.code.Equals(entity.code) && t.year.Equals(entity.year) select t; if (target.Count() == 0) { context.ProductCode.Add(entity); context.SaveChanges(); Logger.Info(Message.INF003, new string[] { this.Text, Message.create(textRegCode, textRegName) }); Program.MessageBoxAfter("登録し、再検索を行いました。"); btnSearch_Click(sender, e); } else { Program.MessageBoxError("既に同じコードの商品が登録されています。"); } } } }
/************************************************************* * CSVファイル登録ボタン押下時の処理 *************************************************************/ private void btnFileReg_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(labelFilePath.Text)) { Program.MessageBoxError("CSVファイルを選択してください。"); return; } string productKbn = getProductKbn(groupKbn2); if (string.IsNullOrEmpty(productKbn)) { Program.MessageBoxError("商品区分を選択してください。"); return; } if (Program.MessageBoxBefore(productKbn + "として登録しますか?" + Environment.NewLine + "※現在登録されている" + productKbn + "データは削除されます※") == DialogResult.Yes) { using (var context = new CostAccountingEntities()) { // データ削除処理 var target = from t in context.ProductCode where t.year.Equals(Const.TARGET_YEAR) && t.kbn.Equals(productKbn) select t; context.ProductCode.RemoveRange(target); // データ登録処理 foreach (ListViewItem items in listView.Items) { // 登録データのオブジェクトを作成 var entity = new ProductCode() { code = items.SubItems[0].Text, year = Const.TARGET_YEAR, name = items.SubItems[1].Text, unit = items.SubItems[2].Text, kbn = productKbn, note = string.Empty, update_user = string.Concat(SystemInformation.ComputerName, "/", SystemInformation.UserName), update_date = DateTime.Now, del_flg = Const.FLG_OFF }; context.ProductCode.Add(entity); } context.SaveChanges(); } Logger.Info(Message.INF003, new string[] { this.Text, Message.create(labelFilePath, recordCnt) + productKbn }); Program.MessageBoxAfter("登録し、再検索を行いました。"); btnSearch_Click(sender, e); } }