using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; using Microsoft.Data.SqlClient; namespace XmlTool.Importers { internal class Buff { } public class BuffImporter { private readonly string _connectionString= "Buff.xml"; private string xmlPath = "XML\\Buff.xml"; //C:\\DbImporter\\XmlTool\\XML\\Buff.xml public BuffImporter(string connectionString) { _connectionString = connectionString; } public void Import(string xmlPath) { if (!File.Exists(xmlPath)) throw new FileNotFoundException("Buff.xml not found"); XDocument doc = XDocument.Load(xmlPath); using (SqlConnection conn = new SqlConnection(_connectionString)) { conn.Open(); foreach (var buff in doc.Descendants("Buff")) { SqlCommand cmd = new SqlCommand(@" INSERT INTO Buff (BuffId, Name, DigimonSkillCode, SkillCode, MinLevel, ConditionLevel, Class, Type, LifeType, TimeType) VALUES (@BuffId, @Name, @DigimonSkillCode, @SkillCode, @MinLevel, @ConditionLevel, @Class, @Type, @LifeType, @TimeType)", conn); cmd.Parameters.AddWithValue("@BuffId", (int)buff.Element("BuffId")); cmd.Parameters.AddWithValue("@Name", (string)buff.Element("Name") ?? ""); cmd.Parameters.AddWithValue("@DigimonSkillCode", (int)buff.Element("DigimonSkillCode")); cmd.Parameters.AddWithValue("@SkillCode", (int)buff.Element("SkillCode")); cmd.Parameters.AddWithValue("@MinLevel", (int)buff.Element("MinLevel")); cmd.Parameters.AddWithValue("@ConditionLevel", (int)buff.Element("ConditionLevel")); cmd.Parameters.AddWithValue("@Class", (int)buff.Element("Class")); cmd.Parameters.AddWithValue("@Type", (int)buff.Element("Type")); cmd.Parameters.AddWithValue("@LifeType", (int)buff.Element("LifeType")); cmd.Parameters.AddWithValue("@TimeType", (int)buff.Element("TimeType")); cmd.ExecuteNonQuery(); } } } } }