public void SetcontentItems(Correction correction) { string id_string = correction.Id.ToString(); var target_item = this.listView1.Items.Find(id_string, false); target_item[0].SubItems[0].Text = correction.Importance; target_item[0].SubItems[1].Text = correction.Content; target_item[0].SubItems[2].Text = correction.Remarks; target_item[0].SubItems[3].Text = correction.Date.ToString("yyyy/MM/dd (ddd)"); string sql = string.Format("UPdate content SET importance = '{0}', content = '{1}', remarks = '{2}', date = '{3}' WHERE id = '{4}'", correction.Importance, correction.Content, correction.Remarks, correction.Date.ToString("yyyy-MM-dd hh:mm:ss"), correction.Id); MySqlConnection con = new MySqlConnection(); string conString = ConfigurationManager.ConnectionStrings["conString"].ConnectionString; con.ConnectionString = conString; try { con.Open(); var cmd = new MySqlCommand(sql.ToString(), con); cmd.ExecuteNonQuery(); con.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public Form1(Correction se) { InitializeComponent(); this.correction = se; string strid = se.Id.ToString(); label10.Text = strid; label11.Text = se.Importance; label12.Text = se.Content; label13.Text = se.Remarks; }
/// <summary> /// 引数ありコンストラクタ /// </summary> /// <param name="cn"></param> public Form2(Correction cn, Form1 form) { this.form = form; InitializeComponent(); this.correction = cn; string strid = cn.Id.ToString(); label1.Text = strid; comboBoxS.Text = cn.Importance; textBoxS.Text = cn.Content; textBoxS2.Text = cn.Remarks; }
/// <summary> /// 変更ボタンのクリックハンドラ /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonChange_Click(object sender, EventArgs e) { try { //----1.データを作る為にリストビューから値を取得 Correction cn = new Correction(); //----2.値を詰め込む //cn.id = this.savedidList[this.listView2.CheckedItems[0].Index]; cn.Id = int.Parse(this.listView2.CheckedItems[0].SubItems[0].Text); // cn.importance = this.listView2.CheckedItems[0].SubItems[1].Text; cn.Content = this.listView2.CheckedItems[0].SubItems[2].Text; //cn.category_id = int.Parse(this.listView2.CheckedItems[3].SubItems[0].Text); cn.Category = this.listView2.CheckedItems[0].SubItems[3].Text; cn.Price = this.listView2.CheckedItems[0].SubItems[4].Text; cn.Date = DateTime.Parse(this.listView2.CheckedItems[0].SubItems[5].Text); cn.Remarks = this.listView2.CheckedItems[0].SubItems[6].Text; //MessageBox.Show(cn.importance); //----3.詰め込んだ物を渡す Form3 main = new Form3(cn, this, categories); //----4.渡した状態で画面起動 main.ShowDialog(this); main.Dispose(); //this.dataLoad(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// モデルクラスをやりとりして変更内容を反映する /// </summary> /// <param name="se"></param> public void SetcontentItems(Correction se) { string id_string = se.Id.ToString(); var target_item = this.listView2.Items.Find(id_string, false); target_item[0].SubItems[0].Text = se.Id.ToString(); target_item[0].SubItems[2].Text = se.Content; target_item[0].SubItems[3].Text = se.Category; target_item[0].SubItems[4].Text = se.Price; target_item[0].SubItems[5].Text = se.Date.ToString("yyyy/MM/dd"); target_item[0].SubItems[6].Text = se.Remarks; string sql = string.Format("UPDATE content SET content = '{0}', category_id = (SELECT id FROM category WHERE name = '{1}'), price = '{2}', date = '{3}', remarks = '{4}' WHERE id = '{5}'", se.Content, se.Category, se.Price, se.Date.ToString("yyyy-MM-dd hh:mm:ss"), se.Remarks, se.Id); MySqlConnection con = new MySqlConnection(); string conString = ConfigurationManager.ConnectionStrings["conString"].ConnectionString; con.ConnectionString = conString; try { con.Open(); var cmd = new MySqlCommand(sql, con); cmd.ExecuteNonQuery(); con.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void button6_Click(object sender, EventArgs e) { //----1.データを作る為にリストビューから値を取得 Correction cn = new Correction(); //----2.値を詰め込む //cn.id = this.savedidList[this.listView1.CheckedItems[0].Index]; cn.Id = int.Parse(this.listView1.CheckedItems[0].SubItems[0].Text); cn.Importance = this.listView1.CheckedItems[0].SubItems[1].Text; cn.Content = this.listView1.CheckedItems[0].SubItems[2].Text; cn.Remarks = this.listView1.CheckedItems[0].SubItems[3].Text; cn.Date = DateTime.Parse(this.listView1.CheckedItems[0].SubItems[4].Text); //MessageBox.Show(cn.importance); //----3.詰め込んだ物を渡す Form2 main = new Form2(cn, this); //----4.渡した状態で画面起動 main.ShowDialog(this); main.Dispose(); //this.dataLoad(); using (Form2 sub = new Form2()) { Correction se = new Correction(); // プロパティに値を設定して子フォームを開く // 子フォームで設定されたプロパティから値を反映する string strid = se.Id.ToString(); this.label10.Text = strid; this.label11.Text = se.Importance; this.label12.Text = se.Content; this.label13.Text = se.Remarks; //オブジェクト指向パラダイム MySqlConnection con = new MySqlConnection(); string conString = ConfigurationManager.ConnectionStrings["conString"].ConnectionString; con.ConnectionString = conString; try { con.Open(); //MessageBox.Show("接続成功"); } catch (Exception err) { MessageBox.Show(err.Message); } if (label10.Text != "") { string msg = label10.Text; string setiimportance = label11.Text; string seticontent = label12.Text; string setiremarks = label13.Text; // UPdate文出す StringBuilder sql = new StringBuilder(); sql.AppendLine("UPdate content SET importance = '" + setiimportance + "' , content = '" + seticontent + "' , remarks = '" + setiremarks + "' WHERE id = '" + msg + "'"); // よみこむやつ MySqlCommand cmd = new MySqlCommand(sql.ToString(), con); cmd.ExecuteNonQuery(); } //最後にとじる con.Close(); //接続する button1_Click(sender, e); } }
private void button5_Click(object sender, EventArgs e) { //----1.データを作る為にリストビューから値を取得 Correction se = new Correction(); //----2.値を詰め込む string strid = se.Id.ToString(); se.Id = int.Parse(this.label1.Text); se.Importance = this.comboBoxS.Text; se.Content = this.textBoxS.Text; se.Remarks = this.textBoxS2.Text; se.Date = this.correction.Date; form.SetcontentItems(se); //----3.詰め込んだ物を渡す //Form1 sub = new Form1(se); //----4.渡した状態で画面起動 //sub.ShowDialog(this); //sub.Dispose(); this.Close(); //this.Dispose(); //this.dataLoad(); }