private void b_regist_Click(object sender, EventArgs e) { //必須入力チェック //存在チェック項目の追加 chkExist.addControl(t_reception_code); chkExist.addControl(d_receipt_date); chkExist.addControl(t_reception_time); chkExist.addControl(d_receipt_staff); chkExist.addControl(d_receipt_store); chkExist.addControl(d_status); chkExist.addControl(t_photographers); chkExist.addControl(d_coming_store_category); chkExist.addControl(d_motivation); chkExist.addControl(d_customer_code); if (chkExist.check("W00000", chkExist.checkControlImportant)) { return; } //受付コードチェック chkreceptcode.addControl(t_reception_code); if (chkreceptcode.check("W00001", chkreceptcode.checkTextboxLength, 8)) { return; } //受付時間チェック chkrecepttime.addControl(t_reception_time); if (chkrecepttime.check("W00001", chkrecepttime.checkTextboxLength, 5)) { return; } if (chkrecepttime.check("W00003", chkrecepttime.checkTextboxFormat, @"^[0-2][0-9]:[0-5][0-9]$", @"HH:MM")) { return; } //撮影人数チェック chkphotographers.addControl(t_photographers); if (chkphotographers.check("W00001", chkphotographers.checkTextboxLength, 4)) { return; } if (chkphotographers.check("W00003", chkphotographers.checkTextboxFormat, @"\d+", @"0~9999")) { return; } //メモチェック //メモチェック chkmemo.addControl(t_memo); if (chkmemo.check("W00001", chkmemo.checkTextboxLength, 255)) { return; } //クレームチェック //クレームチェック chkclaim.addControl(d_claim); if (chkclaim.check("W00001", chkclaim.checkTextboxLength, 255)) { return; } //登録処理 //キーの設定 string recept_code = t_reception_code.Text; //登録処理 DB.t_reception reception = new DB.t_reception(); using (var dbc = new DB.DBConnect()) { dbc.npg.Open(); using (var transaction = dbc.npg.BeginTransaction()) { //登録処理 var data = dbc.t_reception.FirstOrDefault(x => x.reception_code == recept_code); if (data == null) { reception.reception_code = recept_code; reception.receipt_date = d_receipt_date.Value; reception.receipt_time = TimeSpan.Parse(t_reception_time.Text); reception.status = (d_status.SelectedIndex + 1).ToString(); reception.photographers = int.Parse(t_photographers.Text); reception.coming_store_category = (d_coming_store_category.SelectedIndex + 1).ToString(); reception.customer_code = d_customer_code.Text != ""? d_customer_code.Text:"00000000"; reception.store = storeCodeList.Find(x => x.store_name == d_receipt_store.Text).store_name; reception.staff = staffCodeList.Find(x => x.staff_name == d_receipt_staff.Text).staff_name; reception.memo = t_memo.Text; reception.claim = d_claim.Text; reception.motivation = (d_motivation.SelectedIndex + 1).ToString(); reception.noprint = "0"; reception.registration_date = DateTime.Now.Date; reception.registration_staff = MainForm.session_m_staff.staff_name; dbc.t_reception.Add(reception); } else { MessageBox.Show("データがすでに存在してます。"); return; } try { dbc.SaveChanges(); transaction.Commit(); } catch (Exception) { transaction.Rollback(); } } } if (d_customer_code.Text != "") { //セッション情報の追加 MainForm.session_t_reception = reception; //ヘッダメニュー更新 MainForm.Header_Menu.LabelReWrite(); } //一つ前に戻る pageParent.PageRefresh(); MainForm.backPage(this); }
//検索ボタンをクリックしたときに、条件を設定して受付情報を //検索して一覧表にセットする。 private void b_search_Click(object sender, EventArgs e) { //where句の編集 strSQLWHERE = ""; //日付の編集 strSQLWHERE += t_start_time_from != null ?"receipt_date >=" + "'" + t_start_time_from + "'":""; strSQLWHERE += t_start_time_to != null && strSQLWHERE.Length > 0 ? " and " : ""; strSQLWHERE += t_start_time_to != null ? " receipt_date <=" + "'" + t_start_time_to + "'" : ""; //名前検索条件の編集 strSQLWHERE += t_customer.Text != null && strSQLWHERE.Length > 0? " and " : ""; strSQLWHERE += t_customer.Text != null ? " (c.surname || c.name LIKE " + "'%" + t_customer.Text + "%')": ""; //予約のみ表示 strSQLWHERE += strSQLWHERE.Length > 0 ? " and " : ""; strSQLWHERE += "r.status = '1' "; strSQLWHERE = strSQLWHERE.Length > 0 ? "WHERE " + strSQLWHERE : ""; //テーブルにアクセスするメソッドの呼び出し。 // DataGridView初期化(データクリア) dataGridView1.Rows.Clear(); //結果格納クエリーの初期化 NpgsqlDataReader dataReader = null; //データベースアクセス処理 using (var db = new DB.DBConnect()) { //オープン処理がないと怒られる。 db.npg.Open(); StringBuilder sb = new StringBuilder(); sb.Append(@"select r.reception_code as reception_code, r.receipt_date as receipt_date, r.receipt_time as receipt_time, r.store as store, r.staff as staff, r.customer_code, c.surname || c.name as name, r.status as status, r.photographers as photographers, r.coming_store_category, r.memo as memo, r.noprint as noprint, r.claim, r.motivation "); sb.Append(@"from t_reception r LEFT JOIN m_customer c ON r.customer_code = c.customer_code "); sb.Append(@strSQLWHERE); sb.Append(@"order by reception_code"); var command = new NpgsqlCommand(sb.ToString(), db.npg); dataReader = command.ExecuteReader(); receptions = new List <DB.t_reception>(); if (dataReader.HasRows) { while (dataReader.Read()) { //チェックボックスの編集 var cb = dataReader["noprint"].ToString() == "1" ? true : false; //ステータスを変換 int intVal = int.Parse(dataReader["status"].ToString()); var status = (Utile.Data.受付ステータス)Enum.ToObject(typeof(Utile.Data.受付ステータス), intVal); //日付編集 DateTime receipt_date; DateTime.TryParse(dataReader["receipt_date"].ToString(), out receipt_date); //時刻編集 DateTime receipt_time; DateTime.TryParse(dataReader["receipt_time"].ToString(), out receipt_time); dataGridView1.Rows.Add( cb, dataReader["reception_code"], receipt_date.ToShortDateString(), receipt_time.ToShortTimeString(), dataReader["store"], dataReader["staff"], dataReader["name"], status, dataReader["memo"] ); DB.t_reception _Reception = new DB.t_reception(); _Reception.reception_code = dataReader["reception_code"].ToString(); _Reception.receipt_date = DateTime.Parse(dataReader["receipt_date"].ToString()); _Reception.receipt_time = TimeSpan.Parse(dataReader["receipt_time"].ToString()); _Reception.status = dataReader["status"].ToString(); _Reception.photographers = int.Parse(dataReader["photographers"].ToString()); _Reception.coming_store_category = dataReader["coming_store_category"].ToString(); _Reception.customer_code = dataReader["customer_code"].ToString(); _Reception.store = dataReader["store"].ToString(); _Reception.staff = dataReader["staff"].ToString(); _Reception.memo = dataReader["memo"].ToString(); _Reception.claim = dataReader["claim"].ToString(); _Reception.motivation = dataReader["motivation"].ToString(); _Reception.noprint = dataReader["noprint"].ToString(); receptions.Add(_Reception); } } else { MessageBox.Show("検索結果が0件でした。", "お知らせ", MessageBoxButtons.OK); } } }