/// <summary> /// 「編集」 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button_Update_Click(object sender, EventArgs e) { if (this.listView_Display.SelectedItems.Count < 1) { MessageBox.Show("項目が選択されていません。", "Error!!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } ListViewItem item = this.listView_Display.SelectedItems[0]; using (Form_UpdateCharacter f = new Form_UpdateCharacter()) { CharacterData doc = new CharacterData(); doc.ID = item.SubItems[6].Text; doc.Name = item.SubItems[1].Text; doc.Kana = item.SubItems[9].Text; doc.Sex = item.SubItems[2].Text; doc.Type = item.SubItems[0].Text; doc.Race = item.SubItems[10].Text; doc.Age = item.SubItems[11].Text; doc.Grade = item.SubItems[3].Text; doc.Skill = item.SubItems[4].Text; doc.Club = item.SubItems[12].Text; doc.Organization = item.SubItems[13].Text; doc.Remarks = item.SubItems[14].Text.Replace(",", Environment.NewLine); CreaterData creater = new CreaterData(); creater.ID = item.SubItems[7].Text; doc.Creater = creater; string[] urlArray = item.Tag.ToString().Split(','); doc.URLToWiki = urlArray[2]; string url = string.Empty; for (int i = 3; i < urlArray.Length; i++) { url += urlArray[i] + Environment.NewLine; } doc.URLToPixiv = url.Substring(0, url.Length - 1); f.Character = doc; f.Pass = item.SubItems[8].Text; doc.ImageData = this.imageList[this.listView_Display.SelectedIndices[0]]; DialogResult dr = f.ShowDialog(); if (dr != DialogResult.OK) { return; } // 更新 loadDisplay(); } }
/// <summary> /// データ取得 /// </summary> /// <returns></returns> private List<CharacterData> getData() { MySqlConnection cn = null; MySqlCommand cmd = null; MySqlDataReader reader = null; try { cn = new MySqlConnection(this.connectionString); cn.Open(); cmd = cn.CreateCommand(); cmd.CommandText = @" select ch.id as id, ch.name as name, ch.kana as kana, t.name as type, g.name as gender, ch.race as race, ch.age as age, ch.grade as grade, ch.skill as skill, ch.club as club, ch.organization as org, ch.remarks as rem, cr.id as cr_id, cr.name as cr_name, cr.pixiv_id as pixiv, cr.twitter_id as twitter, ch.wiki_url as wiki, ch.sheet_url as sheet, cr.password as pass from chara ch join creater cr on ch.creater_id = cr.id join type t on ch.type_id = t.id join gender g on ch.gender_id = g.id order by t.id asc, ch.kana asc ;"; reader = cmd.ExecuteReader(); List<CharacterData> data = new List<CharacterData>(); //this.imageList.Clear(); while (reader.Read()) { CharacterData doc = new CharacterData(); doc.ID = reader["id"].ToString(); doc.Name = reader["name"].ToString(); doc.Kana = reader["kana"].ToString(); doc.Type = reader["type"].ToString(); doc.Race = reader["race"].ToString(); doc.Sex = reader["gender"].ToString(); doc.Age = reader["age"].ToString(); doc.Grade = reader["grade"].ToString(); doc.Skill = reader["skill"].ToString(); doc.Club = reader["club"].ToString(); doc.Organization = reader["org"].ToString(); doc.Remarks = reader["rem"].ToString(); doc.URLToWiki = reader["wiki"].ToString(); doc.URLToPixiv = reader["sheet"].ToString(); CreaterData creater = new CreaterData(); creater.ID = reader["cr_id"].ToString(); creater.Name = reader["cr_name"].ToString(); creater.PixivID = reader["pixiv"].ToString(); creater.TwitterID = reader["twitter"].ToString(); creater.Password = reader["pass"].ToString(); doc.Creater = creater; data.Add(doc); /* byte[] imageData = new byte[0]; if (reader["IMAGE"].ToString() != string.Empty) { imageData = (byte[])reader["IMAGE"]; } this.imageList.Add(imageData);*/ } return data; } finally { if (reader != null) { reader.Close(); } if (cmd != null) { cmd.Dispose(); } if (cn != null) { cn.Close(); } } }
private void validateAndInsert() { #region 入力チェック // 名前 if (this.textBox_Name.Text.Trim() == string.Empty) { MessageBox.Show("名前が未入力です。", "Error!!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // よみがな if (this.textBox_Kana.Text.Trim() == string.Empty) { MessageBox.Show("よみがなが未入力です。", "Error!!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // 種族 if (this.textBox_Race.Text.Trim() == string.Empty) { MessageBox.Show("種族が未入力です。", "Error!!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // 年齢 string age = this.textBox_Age.Text.Trim(); if (age == string.Empty) { MessageBox.Show("年齢が未入力です。", "Error!!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } age = Strings.StrConv(age, VbStrConv.Narrow); // 学年 string grade = this.textBox_Grade.Text.Trim(); if (grade == string.Empty) { MessageBox.Show("学年が未入力です。", "Error!!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } grade = Strings.StrConv(grade, VbStrConv.Narrow); // キャラクターシートURL if (this.textBox_URLToPixiv.Text.Trim() == string.Empty) { MessageBox.Show("キャラクターシートURLが未入力です。", "Error!!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // 魔砲 string skill = this.textBox_Skill.Text.Trim(); if (skill == string.Empty) { skill = "NoData"; } // 部活 string club = string.Empty; if (this.textBox_Club.Text.Trim() != string.Empty) { club = this.textBox_Club.Text.Trim(); } // 組織 string organization = string.Empty; if (this.textBox_Organization.Text.Trim() != string.Empty) { organization = this.textBox_Organization.Text.Trim(); } // 親御さん情報 CreaterData creater = new CreaterData(); creater.ID = this.createrID[this.comboBox_Creater.SelectedIndex]; // キャラクターシートURL if (this.textBox_URLToPixiv.Text.Trim() == string.Empty) { MessageBox.Show("キャラクターシートURLが未入力です。", "Error!!", MessageBoxButtons.OK, MessageBoxIcon.Error); } string url = this.textBox_URLToPixiv.Text.Trim(); #endregion DialogResult dr = MessageBox.Show(string.Format(@" 以下の情報で登録してよろしいですか? 名前 : {0} よみがな : {1} 性別 : {2} 属性 : {3} 種族 : {4} 年齢 : {5} 学年 : {6} 魔砲 : {7} 部活 : {8} 組織 : {9} 備考 : {10} キャラクターシートURL : {11} WikiURL : {12} 親御さん情報 名前 : {13}", this.textBox_Name.Text.Trim(), this.textBox_Kana.Text.Trim(), this.comboBox_Sex.SelectedItem.ToString(), this.comboBox_Type.SelectedItem.ToString(), this.textBox_Race.Text.Trim(), age, grade, skill, club, organization, this.textBox_Remarks.Text.Trim(), url, this.textBox_Wiki.Text.Trim() != string.Empty ? this.textBox_Wiki.Text.Trim() : "なし", this.comboBox_Creater.Text.Trim() ), "Question.", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (dr != DialogResult.OK) { return; } CharacterData doc = new CharacterData(); doc.Type = this.typeID[this.comboBox_Type.SelectedIndex]; doc.Name = this.textBox_Name.Text.Trim(); doc.Kana = this.textBox_Kana.Text.Trim(); doc.Sex = this.sexID[this.comboBox_Sex.SelectedIndex]; doc.Race = this.textBox_Race.Text.Trim(); doc.Age = age; doc.Grade = grade; doc.Skill = skill; doc.Club = club; doc.Organization = organization; doc.Remarks = this.textBox_Remarks.Text.Trim().Replace(Environment.NewLine, ","); doc.URLToWiki = this.textBox_Wiki.Text.Trim(); doc.URLToPixiv = url.Replace(Environment.NewLine, ","); doc.Creater = new CreaterData(); doc.Creater.ID = this.createrID[this.comboBox_Creater.SelectedIndex]; doc.ImageData = this.picturePath != string.Empty ? File.ReadAllBytes(this.picturePath) : new byte[] { }; try { // データ登録 insert(doc); MessageBox.Show("Success!!"); this.DialogResult = DialogResult.OK; this.Close(); } catch (Exception ex) { string message = "Error!!" + Environment.NewLine + ex.Message; if (ex.Message.StartsWith("Unable to connect to any of the specified ")) { message = "データベースに接続できませんでした。" + Environment.NewLine + "サーバーが立ち上がっていない可能性がありますので、今しばらくお待ち下さい。" + Environment.NewLine + "現在のサーバーの状況は、以下のTwitterアカウントにて随時報告されております。" + Environment.NewLine + Environment.NewLine + "https://twitter.com/mikaze_Atlantis"; MessageBox.Show(message, "Error!!", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show(message, "Error!!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void validateAndUpdate() { #region 入力チェック // パスワード string pass = this.textBox_Pass.Text.Trim(); if (pass == string.Empty) { MessageBox.Show("パスワードが未入力です。", "Error!!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!pass.Equals(this.Pass)) { MessageBox.Show("登録時のパスワードと一致しません。", "Error!!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // 名前 if (this.textBox_Name.Text.Trim() == string.Empty) { MessageBox.Show("名前が未入力です。", "Error!!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // よみがな if (this.textBox_Kana.Text.Trim() == string.Empty) { MessageBox.Show("よみがなが未入力です。", "Error!!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // 種族 if (this.textBox_Race.Text.Trim() == string.Empty) { MessageBox.Show("種族が未入力です。", "Error!!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // 年齢 string age = this.textBox_Age.Text.Trim(); if (age == string.Empty) { MessageBox.Show("年齢が未入力です。", "Error!!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } age = Strings.StrConv(age, VbStrConv.Narrow); // 学年 string grade = this.textBox_Grade.Text.Trim(); if (grade == string.Empty) { MessageBox.Show("学年が未入力です。", "Error!!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } grade = Strings.StrConv(grade, VbStrConv.Narrow); // キャラクターシートURL if (this.textBox_URLToPixiv.Text.Trim() == string.Empty) { MessageBox.Show("キャラクターシートURLが未入力です。", "Error!!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // 魔砲 string skill = this.textBox_Skill.Text.Trim(); if (skill == string.Empty) { skill = "NoData"; } // 部活 string club = string.Empty; if (this.textBox_Club.Text.Trim() != string.Empty) { club = this.textBox_Club.Text.Trim(); } // 組織 string organization = string.Empty; if (this.textBox_Organization.Text.Trim() != string.Empty) { organization = this.textBox_Organization.Text.Trim(); } // 親御さん情報 CreaterData creater = new CreaterData(); creater.ID = this.createrID[this.comboBox_Creater.SelectedIndex]; // キャラクターシートURL if (this.textBox_URLToPixiv.Text.Trim() == string.Empty) { MessageBox.Show("キャラクターシートURLが未入力です。", "Error!!", MessageBoxButtons.OK, MessageBoxIcon.Error); } string url = this.textBox_URLToPixiv.Text.Trim(); #endregion DialogResult dr = MessageBox.Show(string.Format(@" 以下の情報で登録してよろしいですか? 名前 : {0} よみがな : {1} 性別 : {2} 属性 : {3} 種族 : {4} 年齢 : {5} 学年 : {6} 魔砲 : {7} 部活 : {8} 組織 : {9} 備考 : {10} キャラクターシートURL : {11} WikiURL : {12} 親御さん情報 名前 : {13}", this.textBox_Name.Text.Trim(), this.textBox_Kana.Text.Trim(), this.comboBox_Sex.SelectedItem.ToString(), this.comboBox_Type.SelectedItem.ToString(), this.textBox_Race.Text.Trim(), age, grade, skill, club, organization, this.textBox_Remarks.Text.Trim(), url, this.textBox_Wiki.Text.Trim() != string.Empty ? this.textBox_Wiki.Text.Trim() : "なし", this.comboBox_Creater.Text.Trim() ), "Question.", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (dr != DialogResult.OK) { return; } CharacterData doc = new CharacterData(); doc.Type = this.typeID[this.comboBox_Type.SelectedIndex]; doc.Name = this.textBox_Name.Text.Trim(); doc.Kana = this.textBox_Kana.Text.Trim(); doc.Sex = this.sexID[this.comboBox_Sex.SelectedIndex]; doc.Race = this.textBox_Race.Text.Trim(); doc.Age = age; doc.Grade = grade; doc.Skill = skill; doc.Club = club; doc.Organization = organization; doc.Remarks = this.textBox_Remarks.Text.Trim().Replace(Environment.NewLine, ","); doc.URLToWiki = this.textBox_Wiki.Text.Trim(); doc.URLToPixiv = url.Replace(Environment.NewLine, ","); doc.Creater = new CreaterData(); doc.Creater.ID = this.createrID[this.comboBox_Creater.SelectedIndex]; byte[] imageData = new byte[0]; if (this.picturePath != string.Empty) { imageData = File.ReadAllBytes(this.picturePath); } else if (this.pictureBox_Character.Image != null) { imageData = convertImageToByteArray(this.pictureBox_Character.Image); } doc.ImageData = imageData; try { // データ更新 update(doc, this.Character.ID); MessageBox.Show("Success!!"); this.DialogResult = DialogResult.OK; this.Close(); } catch (Exception ex) { string message = @"Error!! " + ex.Message; if (ex.Message.StartsWith("Unable to connect to any of the specified ")) { message = @"データベースに接続できませんでした。 サーバーが立ち上がっていない可能性がありますので、今しばらくお待ち下さい。 現在のサーバーの状況は、以下のTwitterアカウントにて随時報告されております。 https://twitter.com/mikaze_Atlantis"; MessageBox.Show(message, "Error!!", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show(message, "Error!!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } this.Close(); }
/// <summary> /// データ更新 /// </summary> /// <param name="doc">入力された情報</param> /// <param name="id">更新するID</param> private void update(CharacterData doc, string id) { string sql = @" update chara set name = @name, kana = @kana, type_id= @type, gender_id = @sex, race = @race, age = @age, grade = @grade, skill = @skill, club = @club, organization = @organization, remarks = @remarks, creater_id = @createrId, wiki_url = @urlToWiki, sheet_url = @urlToPixiv, image = @image where id = @id ;"; List<string[]> param = new List<string[]>(); param.Add(new string[] { "name", doc.Name }); param.Add(new string[] { "kana", doc.Kana }); param.Add(new string[] { "type", doc.Type }); param.Add(new string[] { "sex", doc.Sex }); param.Add(new string[] { "race", doc.Race }); param.Add(new string[] { "age", doc.Age }); param.Add(new string[] { "grade", doc.Grade }); param.Add(new string[] { "skill", doc.Skill }); param.Add(new string[] { "club", doc.Club }); param.Add(new string[] { "organization", doc.Organization }); param.Add(new string[] { "remarks", doc.Remarks }); param.Add(new string[] { "createrId", doc.Creater.ID }); param.Add(new string[] { "urlToWiki", doc.URLToWiki }); param.Add(new string[] { "urlToPixiv", doc.URLToPixiv }); param.Add(new string[] { "id", id }); executeQuery(sql, param, doc.ImageData); }
/// <summary> /// データ登録 /// </summary> /// <param name="doc">入力された情報</param> private void insert(CharacterData doc) { string sql = @" insert into chara values ( null, @name, @kana, @type, @sex, @race, @age, @grade, @skill, @club, @organization, @remarks, @createrId, @urlToWiki, @urlToPixiv, @image );"; List<string[]> param = new List<string[]>(); param.Add(new string[] { "name", doc.Name }); param.Add(new string[] { "kana", doc.Kana }); param.Add(new string[] { "type", doc.Type }); param.Add(new string[] { "sex", doc.Sex }); param.Add(new string[] { "race", doc.Race }); param.Add(new string[] { "age", doc.Age }); param.Add(new string[] { "grade", doc.Grade }); param.Add(new string[] { "skill", doc.Skill }); param.Add(new string[] { "club", doc.Club }); param.Add(new string[] { "organization", doc.Organization }); param.Add(new string[] { "remarks", doc.Remarks }); param.Add(new string[] { "createrId", doc.Creater.ID }); param.Add(new string[] { "urlToWiki", doc.URLToWiki }); param.Add(new string[] { "urlToPixiv", doc.URLToPixiv }); executeQuery(sql, param, doc.ImageData); }
/// <summary> /// データ取得 /// </summary> /// <returns></returns> private List <CharacterData> getData() { MySqlConnection cn = null; MySqlCommand cmd = null; MySqlDataReader reader = null; try { cn = new MySqlConnection(this.connectionString); cn.Open(); cmd = cn.CreateCommand(); cmd.CommandText = @" select ch.id as id, ch.name as name, ch.kana as kana, t.name as type, g.name as gender, ch.race as race, ch.age as age, ch.grade as grade, ch.skill as skill, ch.club as club, ch.organization as org, ch.remarks as rem, cr.id as cr_id, cr.name as cr_name, cr.pixiv_id as pixiv, cr.twitter_id as twitter, ch.wiki_url as wiki, ch.sheet_url as sheet, cr.password as pass from chara ch join creater cr on ch.creater_id = cr.id join type t on ch.type_id = t.id join gender g on ch.gender_id = g.id order by t.id asc, ch.kana asc ;"; reader = cmd.ExecuteReader(); List <CharacterData> data = new List <CharacterData>(); //this.imageList.Clear(); while (reader.Read()) { CharacterData doc = new CharacterData(); doc.ID = reader["id"].ToString(); doc.Name = reader["name"].ToString(); doc.Kana = reader["kana"].ToString(); doc.Type = reader["type"].ToString(); doc.Race = reader["race"].ToString(); doc.Sex = reader["gender"].ToString(); doc.Age = reader["age"].ToString(); doc.Grade = reader["grade"].ToString(); doc.Skill = reader["skill"].ToString(); doc.Club = reader["club"].ToString(); doc.Organization = reader["org"].ToString(); doc.Remarks = reader["rem"].ToString(); doc.URLToWiki = reader["wiki"].ToString(); doc.URLToPixiv = reader["sheet"].ToString(); CreaterData creater = new CreaterData(); creater.ID = reader["cr_id"].ToString(); creater.Name = reader["cr_name"].ToString(); creater.PixivID = reader["pixiv"].ToString(); creater.TwitterID = reader["twitter"].ToString(); creater.Password = reader["pass"].ToString(); doc.Creater = creater; data.Add(doc); /* * byte[] imageData = new byte[0]; * if (reader["IMAGE"].ToString() != string.Empty) * { * imageData = (byte[])reader["IMAGE"]; * } * this.imageList.Add(imageData);*/ } return(data); } finally { if (reader != null) { reader.Close(); } if (cmd != null) { cmd.Dispose(); } if (cn != null) { cn.Close(); } } }