/// -------------------------------------------------------------------------- /// <summary> /// データグリッドビューの指定行のデータを取得する </summary> /// <param name="dgv"> /// 対象とするデータグリッドビューオブジェクト</param> /// -------------------------------------------------------------------------- private Boolean GetData(DataGridView dgv, ref Entity.配布員 tempC) { int iX = 0; string sqlStr; Control.配布員 Staff = new Control.配布員(); OleDbDataReader dr; sqlStr = " where 配布員.ID = " + Utility.strToInt(dgv[0, dgv.SelectedRows[iX].Index].Value.ToString()); dr = Staff.FillBy(sqlStr); if (dr.HasRows == true) { while (dr.Read() == true) { tempC.ID = Convert.ToInt32(dr["ID"].ToString()); tempC.氏名 = dr["氏名"].ToString() + ""; tempC.フリガナ = dr["フリガナ"].ToString() + ""; tempC.郵便番号 = dr["郵便番号"].ToString() + ""; tempC.住所 = dr["住所"].ToString() + ""; tempC.携帯電話番号 = dr["携帯電話番号"].ToString() + ""; tempC.自宅電話番号 = dr["自宅電話番号"].ToString() + ""; tempC.PCアドレス = dr["PCアドレス"].ToString() + ""; tempC.携帯アドレス = dr["携帯アドレス"].ToString() + ""; tempC.登録日 = dr["登録日"].ToString() + ""; tempC.勤務区分 = Int32.Parse(dr["勤務区分"].ToString()); tempC.街頭配布区分 = Int32.Parse(dr["街頭配布区分"].ToString()); tempC.街頭配布備考 = dr["街頭配布備考"].ToString() + ""; tempC.事業所コード = Int32.Parse(dr["事業所コード"].ToString()); tempC.支払区分 = dr["支払区分"].ToString() + ""; tempC.金融機関コード = dr["金融機関コード"].ToString(); tempC.金融機関名 = dr["金融機関名"].ToString() + ""; tempC.金融機関名カナ = dr["金融機関名カナ"].ToString() + ""; tempC.支店コード = dr["支店コード"].ToString(); tempC.支店名 = dr["支店名"].ToString() + ""; tempC.支店名カナ = dr["支店名カナ"].ToString() + ""; tempC.口座種別 = Int32.Parse(dr["口座種別"].ToString()); tempC.口座番号 = dr["口座番号"].ToString() + ""; tempC.口座名義カナ = dr["口座名義カナ"].ToString() + ""; tempC.備考 = dr["備考"].ToString() + ""; tempC.マイナンバー = dr["マイナンバー"].ToString() + ""; tempC.ユーザーID = Utility.strToInt(dr["ユーザーID"].ToString()); } } else { dr.Close(); Staff.Close(); return(false); } dr.Close(); Staff.Close(); return(true); }
private void btnDel_Click(object sender, EventArgs e) { // 他に登録されているときは削除不可とする string SqlStr; SqlStr = " where "; SqlStr += "(配布指示.配布員ID = " + txtCode.Text.ToString() + ") "; OleDbDataReader dr; Control.配布指示 Shiji = new Control.配布指示(); dr = Shiji.FillBy(SqlStr); // 該当配布員が登録されているときは削除不可とする if (dr.HasRows == true) { MessageBox.Show(txtName1.Text.ToString() + "が配布指示データに登録されています", txtName1.Text.ToString() + "は削除できません", MessageBoxButtons.OK, MessageBoxIcon.Error); dr.Close(); Shiji.Close(); return; } dr.Close(); Shiji.Close(); // 削除確認 if (MessageBox.Show("削除します。よろしいですか?", "削除確認", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } // データ削除 Control.配布員 Staff = new Control.配布員(); if (Staff.DataDelete(Convert.ToInt32(txtCode.Text.ToString())) == true) { MessageBox.Show("削除されました", MESSAGE_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Information); } Staff.Close(); DispClear(); // データを 'darwinDataSet.配布員' テーブルに読み込みます。 this.配布員TableAdapter.Fill(this.darwinDataSet.配布員); //this.配布員TableAdapter.Fill(this.darwinDataSet.配布員gridview); // グリッド再表示 gridSerach(dataGridView1); }
private void txthCode_Validating(object sender, CancelEventArgs e) { if (txthCode.Text == "") { return; } if (Utility.NumericCheck(txthCode.Text) == false) { MessageBox.Show("数字で入力してください", MESSAGE_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error); e.Cancel = true; return; } OleDbDataReader dR; Control.配布員 cStaff = new Control.配布員(); dR = cStaff.FillBy("where ID = " + txthCode.Text); if (dR.HasRows == false) { lblName.Text = ""; MessageBox.Show("登録されていない配布員IDです", MESSAGE_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error); e.Cancel = true; return; } else { while (dR.Read()) { lblName.Text = dR["氏名"].ToString(); } } dR.Close(); cStaff.Close(); return; }
//登録データチェック private Boolean fDataCheck() { string str; double d; try { //登録モードのとき、コードをチェック if (fMode.Mode == 0) { // 数字か? if (txtCode.Text == null) { this.txtCode.Focus(); throw new Exception("コードは数字で入力してください"); } str = this.txtCode.Text; if (double.TryParse(str, System.Globalization.NumberStyles.Any, System.Globalization.NumberFormatInfo.InvariantInfo, out d)) { } else { this.txtCode.Focus(); throw new Exception("コードは数字で入力してください"); } // 未入力またはスペースのみは不可 if ((this.txtCode.Text).Trim().Length < 1) { this.txtCode.Focus(); throw new Exception("コードを入力してください"); } //ゼロは不可 if (Convert.ToInt32(this.txtCode.Text.ToString()) == 0) { this.txtCode.Focus(); throw new Exception("ゼロは登録できません"); } //登録済みコードか調べる string sqlStr; Control.配布員 Staff = new Control.配布員(); OleDbDataReader dr; sqlStr = " where ID = " + txtCode.Text.ToString(); dr = Staff.FillBy(sqlStr); if (dr.HasRows == true) { txtCode.Focus(); dr.Close(); Staff.Close(); throw new Exception("既に登録済みのコードです"); } dr.Close(); Staff.Close(); } //名称チェック if (txtName1.Text.Trim().Length < 1) { txtName1.Focus(); throw new Exception("氏名を入力してください"); } ////支払形態チェック //if (cmbShiharai.SelectedIndex == -1) //{ // cmbShiharai.Focus(); // throw new Exception("支払形態を選択してください"); //} ////事業所チェック //if (cmbShozoku.SelectedIndex == -1) //{ // cmbShozoku.Focus(); // throw new Exception("事業所を選択してください"); //} //金融機関コード if (txtBankCode.Text.ToString().Trim() != "") { str = this.txtBankCode.Text.ToString(); if (double.TryParse(str, System.Globalization.NumberStyles.Any, System.Globalization.NumberFormatInfo.InvariantInfo, out d)) { } else { this.txtBankCode.Focus(); throw new Exception("金融機関コードは数字で入力してください"); } } // 支店コード if (txtShitenCode.Text.ToString().Trim() != "") { str = this.txtShitenCode.Text.ToString(); if (double.TryParse(str, System.Globalization.NumberStyles.Any, System.Globalization.NumberFormatInfo.InvariantInfo, out d)) { } else { this.txtShitenCode.Focus(); throw new Exception("支店コードは数字で入力してください"); } } // マイナンバー if (txtMyNumber.Text != string.Empty) { if (Utility.strToLong(txtMyNumber.Text) == 0) { this.txtShitenCode.Focus(); throw new Exception("マイナンバーは数字で入力してください"); } if (txtMyNumber.Text.Length != 12) { this.txtShitenCode.Focus(); throw new Exception("マイナンバーは数字で12桁入力してください"); } } //クラスにデータセット cMaster.ID = Convert.ToInt32(txtCode.Text.ToString()); cMaster.氏名 = txtName1.Text.ToString(); cMaster.フリガナ = txtFuri.Text.ToString(); if (mtxtZipCode.Text.ToString().Replace("-", "").Trim() == "") { cMaster.郵便番号 = ""; } else { cMaster.郵便番号 = mtxtZipCode.Text.ToString(); } cMaster.住所 = txtAddress.Text.ToString(); cMaster.携帯電話番号 = txtMobile.Text.ToString(); cMaster.自宅電話番号 = txtTel.Text.ToString(); cMaster.PCアドレス = txteMail.Text.ToString(); cMaster.携帯アドレス = txteMailm.Text.ToString(); if (iDate.Checked == false) { cMaster.登録日 = ""; } else { cMaster.登録日 = iDate.Value.ToShortDateString(); } if (chkKinmu.Checked == true) { cMaster.勤務区分 = 1; } else { cMaster.勤務区分 = 0; } if (chkGaitou.Checked == true) { cMaster.街頭配布区分 = 1; } else { cMaster.街頭配布区分 = 0; } cMaster.街頭配布備考 = txtGaitouMemo.Text.ToString(); cMaster.支払区分 = cmbShiharai.Text; if (cmbShozoku.SelectedIndex == -1) { cMaster.事業所コード = 0; } else { Utility.ComboOffice cmb1 = new Utility.ComboOffice(); cmb1 = (Utility.ComboOffice)cmbShozoku.SelectedItem; cMaster.事業所コード = cmb1.ID; } cMaster.金融機関コード = txtBankCode.Text.ToString().Trim(); cMaster.金融機関名 = txtBank.Text.ToString(); if (txtBankFuri.Text.ToString().Length > 15) { cMaster.金融機関名カナ = txtBankFuri.Text.ToString().Substring(0, 15); } else { cMaster.金融機関名カナ = txtBankFuri.Text.ToString(); } cMaster.支店コード = txtShitenCode.Text.ToString().Trim(); cMaster.支店名 = txtShiten.Text.ToString(); if (txtShitenFuri.Text.ToString().Length > 15) { cMaster.支店名カナ = txtShitenFuri.Text.ToString().Substring(0, 15); } else { cMaster.支店名カナ = txtShitenFuri.Text.ToString(); } if (cmbShubetsu.SelectedIndex == -1) { cMaster.口座種別 = 0; } else { Utility.ComboKouza cmb2 = new Utility.ComboKouza(); cmb2 = (Utility.ComboKouza)cmbShubetsu.SelectedItem; cMaster.口座種別 = cmb2.ID; } cMaster.口座番号 = txtKouza.Text.ToString(); cMaster.口座名義カナ = txtMeigi.Text.ToString(); cMaster.備考 = txtMemo.Text.ToString(); if (fMode.Mode == 0) { cMaster.登録年月日 = DateTime.Now; cMaster.更年月日 = DateTime.Now; } else { cMaster.更年月日 = DateTime.Now; } cMaster.マイナンバー = txtMyNumber.Text; // 2015/07/16 cMaster.ユーザーID = global.loginUserID; // 2015/07/16 return(true); } catch (Exception ex) { MessageBox.Show(ex.Message, MESSAGE_CAPTION + "保守", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } }
private void btnUpdate_Click(object sender, EventArgs e) { try { if (fDataCheck() == true) { Control.配布員 Staff = new Control.配布員(); switch (fMode.Mode) { case 0: //新規登録 if (MessageBox.Show("新規登録します。よろしいですか?", "登録確認", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { Staff.Close(); return; } if (Staff.DataInsert(cMaster) == true) { MessageBox.Show("新規登録されました", MESSAGE_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("新規登録に失敗しました", MESSAGE_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Stop); } break; case 1: //更新 if (MessageBox.Show("更新します。よろしいですか?", "更新確認", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { Staff.Close(); return; } if (Staff.DataUpdate(cMaster) == true) { MessageBox.Show("更新されました", MESSAGE_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("更新に失敗しました", "所属マスター", MessageBoxButtons.OK, MessageBoxIcon.Stop); } break; } Staff.Close(); DispClear(); //データを 'darwinDataSet.配布員' テーブルに読み込みます。 this.配布員TableAdapter.Fill(this.darwinDataSet.配布員); //this.配布員gridviewTableAdapter.Fill(this.darwinDataSet.配布員gridview); // グリッド再表示 gridSerach(dataGridView1); } } catch (Exception ex) { MessageBox.Show(ex.Message.ToString(), "更新処理", MessageBoxButtons.OK, MessageBoxIcon.Stop); } }