public Register(Database db, User user) { InitializeComponent(); _db = db; add_btn.Text = "上書き"; IsUpdate = true; SetForm(user); }
//DBの情報をアップデート public void Update(User user) { User u = user; string com = "firstName = '" + u._firstName + "',lastName = '" + u._lastName + "',sex = '" + u._sex + "',bYear = '" + u._bYear + "',bMonth = '" + u._bMonth + "',bDay = '" + u._bDay + "',phone1 = '" + u._phone1 + "',phone2 = '" + u._phone2 + "',email = '" + u._email + "',note = '" + u._note + "' WHERE id = " + u._id + ";"; ConnectDB(); MakeCommand("UPDATE profile SET " + com); _command.ExecuteNonQuery(); _connection.Close(); }
//DBに挿入 public void Insert(User user) { User u = user; string com = "'" + u._firstName + "','" + u._lastName + "','" + u._sex + "','" + u._bYear + "','" + u._bMonth + "','" + u._bDay + "','" + u._phone1 + "','" + u._phone2 + "','" + u._email + "','" + u._note + "'"; ConnectDB(); MakeCommand("INSERT INTO profile (firstName,lastName,sex,bYear,bMonth,bDay,phone1,phone2,email,note) VALUES(" + com + ");"); _command.ExecuteNonQuery(); _connection.Close(); }
private void AddUserForDGV(User user) { dataGridView1.Rows.Add(); int idx = dataGridView1.Rows.Count-1; dataGridView1.Rows[idx].Cells[0].Value = user._id; dataGridView1.Rows[idx].Cells[1].Value = user.GetName(); dataGridView1.Rows[idx].Cells[2].Value = user.GetSex(); dataGridView1.Rows[idx].Cells[3].Value = user.GetBirthday(); dataGridView1.Rows[idx].Cells[4].Value = user._phone1; dataGridView1.Rows[idx].Cells[5].Value = user._phone2; dataGridView1.Rows[idx].Cells[6].Value = user._email; dataGridView1.Rows[idx].Cells[7].Value = user._note; }
private void SetForm(User user) { id_lbl.Text = user._id; firstName_tbx.Text = user._firstName; lastName_tbx.Text = user._lastName; sex_cbx.Text = user.GetSex(); year_cbx.Text = user._bYear; month_cbx.Text = user._bMonth; day_cbx.Text = user._bDay; phone1_tbx.Text = user._phone1; phone2_tbx.Text = user._phone2; email_tbx.Text = user._email; note_tbx.Text = user._note; }
private void add_btn_Click(object sender, EventArgs e) { if (IsFillNameTbx()) { List<string> profile = MakeProf(); User user = new User(profile); if (IsUpdate) { user._id = id_lbl.Text; _db.Update(user); }else { _db.Insert(user); } this.DialogResult = DialogResult.OK; Close(); } else { MessageBox.Show("名前を入力してください"); } }
private void enter_btn_Click(object sender, EventArgs e) { if (dataGridView1.Rows.Count > 0) { string id = (string)dataGridView1.CurrentRow.Cells[0].Value; _currentUser = _db.GetData(int.Parse(id)); this.DialogResult = DialogResult.OK; Close(); //DataManager dm = new DataManager(user,_cd); //DialogResult dr = dm.ShowDialog(); //if (dr == DialogResult.OK) { // this.DialogResult = DialogResult.OK; // Close(); //} } }
//ユーザー選択ボタン private void openUserManager_btn_Click(object sender, EventArgs e) { User user = new User(); UserManager um = new UserManager(); if (um.ShowDialog() == DialogResult.OK) { _user = um._currentUser; //ファイルの場所を確保 _user.MakeFileName(_dataDirectryPath); currentUser_lbl.Text = "ID: "+_user._id +" / " + _user.GetName(); string rawDirectory = _user._fileDirectory + "\\RAW"; if (!System.IO.Directory.Exists(rawDirectory)) { System.IO.DirectoryInfo di = System.IO.Directory.CreateDirectory(_user._fileDirectory); System.IO.DirectoryInfo di2 = System.IO.Directory.CreateDirectory(rawDirectory); } } }
//User情報を獲得 public List<User> GetAllData() { List<User> result = new List<User>(); ConnectDB(); MakeCommand("SELECT * FROM profile"); using (SQLiteDataReader reader = _command.ExecuteReader()) { while (reader.Read()) { User tempUser = new User(); tempUser._id = reader["id"].ToString(); tempUser._firstName = reader["firstName"].ToString(); tempUser._lastName = reader["lastName"].ToString(); tempUser._sex = reader["sex"].ToString(); tempUser._bYear = reader["bYear"].ToString(); tempUser._bMonth = reader["bMonth"].ToString(); tempUser._bDay = reader["bDay"].ToString(); tempUser._phone1 = reader["phone1"].ToString(); tempUser._phone2 = reader["phone2"].ToString(); tempUser._email = reader["email"].ToString(); tempUser._note = reader["note"].ToString(); result.Add(tempUser); } } _connection.Close(); return result; }
public User GetData(int idx) { User result = new User(); ConnectDB(); MakeCommand("SELECT * FROM profile WHERE id=" + idx.ToString() + ";"); using (SQLiteDataReader reader = _command.ExecuteReader()) { while (reader.Read()) { result._id = reader["id"].ToString(); result._firstName = reader["firstName"].ToString(); result._lastName = reader["lastName"].ToString(); result._sex = reader["sex"].ToString(); result._bYear = reader["bYear"].ToString(); result._bMonth = reader["bMonth"].ToString(); result._bDay = reader["bDay"].ToString(); result._phone1 = reader["phone1"].ToString(); result._phone2 = reader["phone2"].ToString(); result._email = reader["email"].ToString(); result._note = reader["note"].ToString(); } } _connection.Close(); return result; }