/// <summary> /// Saves the weapon. /// </summary> /// <returns>Weapon Object</returns> public Weapon SaveWeapon() { SqlDataReader result; DatabaseConnection dbconn = new DatabaseConnection(); SqlCommand command = new SqlCommand(); SqlConnection connection = new SqlConnection(dbconn.SQLSEVERConnString); try { connection.Open(); command.Connection = connection; command.CommandType = CommandType.StoredProcedure; command.CommandText = "InsertUpdate_Weapon"; command.Parameters.Add(dbconn.GenerateParameterObj("@WeaponID", SqlDbType.Int, WeaponID.ToString(), 0)); command.Parameters.Add(dbconn.GenerateParameterObj("@WeaponName", SqlDbType.VarChar, WeaponName.ToString(), 50)); command.Parameters.Add(dbconn.GenerateParameterObj("@WeaponTypeID", SqlDbType.Int, WeaponTypeID.ToString(), 0)); command.Parameters.Add(dbconn.GenerateParameterObj("@WeaponSizeID", SqlDbType.Int, WeaponSizeID.ToString(), 0)); command.Parameters.Add(dbconn.GenerateParameterObj("@Cost", SqlDbType.Int, Cost.ToString(), 0)); command.Parameters.Add(dbconn.GenerateParameterObj("@RateOfFire", SqlDbType.VarChar, RateOfFire.ToString(), 3)); command.Parameters.Add(dbconn.GenerateParameterObj("@DamageDieNumber", SqlDbType.Int, DamageDieNumber.ToString(), 0)); command.Parameters.Add(dbconn.GenerateParameterObj("@DamageDieType", SqlDbType.Int, DamageDieType.ToString(), 0)); command.Parameters.Add(dbconn.GenerateParameterObj("@Stun", SqlDbType.Bit, Stun.ToString(), 0)); command.Parameters.Add(dbconn.GenerateParameterObj("@StunDieNumber", SqlDbType.Int, DamageDieNumber.ToString(), 0)); command.Parameters.Add(dbconn.GenerateParameterObj("@StunDieType", SqlDbType.Int, DamageDieType.ToString(), 0)); command.Parameters.Add(dbconn.GenerateParameterObj("@WeaponDescription", SqlDbType.Text, WeaponDescription.ToString(), 4000)); command.Parameters.Add(dbconn.GenerateParameterObj("@Weight", SqlDbType.Decimal, Weight.ToString(), 0)); command.Parameters.Add(dbconn.GenerateParameterObj("@BookID", SqlDbType.Int, BookID.ToString(), 0)); command.Parameters.Add(dbconn.GenerateParameterObj("@WeaponProficiencyFeatID", SqlDbType.Int, WeaponProficiencyFeatID.ToString(), 0)); command.Parameters.Add(dbconn.GenerateParameterObj("@EmplacementPoints", SqlDbType.Int, EmplacementPoints.ToString(), 0)); command.Parameters.Add(dbconn.GenerateParameterObj("@DoubleWeapon", SqlDbType.Bit, DoubleWeapon.ToString(), 0)); command.Parameters.Add(dbconn.GenerateParameterObj("@AreaOfAttack", SqlDbType.Bit, AreaOfAttack.ToString(), 0)); command.Parameters.Add(dbconn.GenerateParameterObj("@Accurate", SqlDbType.Bit, AreaOfAttack.ToString(), 0)); command.Parameters.Add(dbconn.GenerateParameterObj("@Inaccurate", SqlDbType.Bit, AreaOfAttack.ToString(), 0)); command.Parameters.Add(dbconn.GenerateParameterObj("@Slugthrower", SqlDbType.Bit, Slugthrower.ToString(), 0)); command.Parameters.Add(dbconn.GenerateParameterObj("@RequiresSeperateAmmo", SqlDbType.Bit, RequiresSeperateAmmo.ToString(), 0)); command.Parameters.Add(dbconn.GenerateParameterObj("@ExtraDamage", SqlDbType.Bit, ExtraDamage.ToString(), 0)); command.Parameters.Add(dbconn.GenerateParameterObj("@ExtraStunDamage", SqlDbType.Bit, ExtraStunDamage.ToString(), 0)); result = command.ExecuteReader(); result.Read(); SetReaderToObject(ref result); } catch { Exception e = new Exception(); this._insertUpdateOK = false; this._insertUpdateMessage.Append(e.Message + " Inner Exception= " + e.InnerException); throw e; } finally { command.Dispose(); connection.Close(); } return(this); }
public WeaponAmmo SaveWeaponAmmo() { SqlDataReader result; DatabaseConnection dbconn = new DatabaseConnection(); SqlCommand command = new SqlCommand(); SqlConnection connection = new SqlConnection(dbconn.SQLSEVERConnString); try { connection.Open(); command.Connection = connection; command.CommandType = CommandType.StoredProcedure; command.CommandText = "InsertUpdate_WeaponAmmo"; command.Parameters.Add(dbconn.GenerateParameterObj("@WeaponAmmoID", SqlDbType.Int, WeaponAmmoID.ToString(), 0)); command.Parameters.Add(dbconn.GenerateParameterObj("@WeaponAmmoName", SqlDbType.VarChar, WeaponAmmoName.ToString(), 50)); command.Parameters.Add(dbconn.GenerateParameterObj("@Cost", SqlDbType.Int, Cost.ToString(), 0)); command.Parameters.Add(dbconn.GenerateParameterObj("@RateOfFire", SqlDbType.VarChar, RateOfFire.ToString(), 3)); command.Parameters.Add(dbconn.GenerateParameterObj("@DamageDieNumber", SqlDbType.Int, DamageDieNumber.ToString(), 0)); command.Parameters.Add(dbconn.GenerateParameterObj("@DamageDieType", SqlDbType.Int, DamageDieType.ToString(), 0)); command.Parameters.Add(dbconn.GenerateParameterObj("@Stun", SqlDbType.Bit, Stun.ToString(), 0)); command.Parameters.Add(dbconn.GenerateParameterObj("@StunDieNumber", SqlDbType.Int, DamageDieNumber.ToString(), 0)); command.Parameters.Add(dbconn.GenerateParameterObj("@StunDieType", SqlDbType.Int, DamageDieType.ToString(), 0)); command.Parameters.Add(dbconn.GenerateParameterObj("@WeaponAmmoDescription", SqlDbType.Text, WeaponAmmoDescription.ToString(), 4000)); command.Parameters.Add(dbconn.GenerateParameterObj("@Weight", SqlDbType.Decimal, Weight.ToString(), 0)); command.Parameters.Add(dbconn.GenerateParameterObj("@BookID", SqlDbType.Int, BookID.ToString(), 0)); command.Parameters.Add(dbconn.GenerateParameterObj("@ExtraDamage", SqlDbType.Bit, ExtraDamage.ToString(), 0)); command.Parameters.Add(dbconn.GenerateParameterObj("@ExtraStunDamage", SqlDbType.Bit, ExtraStunDamage.ToString(), 0)); result = command.ExecuteReader(); result.Read(); SetReaderToObject(ref result); } catch { Exception e = new Exception(); this._insertUpdateOK = false; this._insertUpdateMessage.Append(e.Message.ToString()); throw e; } finally { command.Dispose(); connection.Close(); } return(this); }
public void Serialize() { // This is the XML Document which we are writing to. var doc = new XmlDocument(); doc.AppendChild(doc.CreateXmlDeclaration("1.0", "utf-8", null)); var root = doc.CreateElement("Object"); Thread.CurrentThread.CurrentCulture = new CultureInfo(1033); var command = doc.CreateComment("Generated on " + DateTime.Today.ToShortDateString() + " at " + DateTime.Now.ToShortTimeString()); doc.AppendChild(command); var objectType = doc.CreateAttribute("type"); objectType.Value = ObjectType; root.Attributes.Append(objectType); var objectId = doc.CreateAttribute("id"); objectId.Value = ObjectId; root.Attributes.Append(objectId); var @class = doc.CreateElement("Class"); // @class because "class" is a keyword @class.InnerText = Class; root.AppendChild(@class); var isItem = doc.CreateElement("Item"); root.AppendChild(isItem); if (itemCreatorForm.RemoteTexture) { var remoteTexture = doc.CreateElement("RemoteTexture"); var rtInstance = doc.CreateElement("Instance"); var rtId = doc.CreateElement("Id"); rtInstance.InnerText = RemoteTextureInstance; rtId.InnerText = RemoteTextureId; remoteTexture.AppendChild(rtInstance); remoteTexture.AppendChild(rtId); root.AppendChild(remoteTexture); } else { var texture = doc.CreateElement("Texture"); var tFile = doc.CreateElement("File"); var tIndex = doc.CreateElement("Index"); tFile.InnerText = TextureFile; tIndex.InnerText = TextureIndex; texture.AppendChild(tFile); texture.AppendChild(tIndex); root.AppendChild(texture); } var slotType = doc.CreateElement("SlotType"); slotType.InnerText = SlotType.ToString(); root.AppendChild(slotType); var tier = doc.CreateElement("Tier"); tier.InnerText = Tier == -1 ? "UT" : Tier.ToString(); root.AppendChild(tier); var description = doc.CreateElement("Description"); description.InnerText = Description; root.AppendChild(description); var rateOfFire = doc.CreateElement("RateOfFire"); rateOfFire.InnerText = RateOfFire.ToString(); root.AppendChild(rateOfFire); var sound = doc.CreateElement("sound"); sound.InnerText = "weapon/blunt_sword"; root.AppendChild(sound); var bagType = doc.CreateElement("BagType"); bagType.InnerText = BagType.ToString(); root.AppendChild(bagType); var oldSound = doc.CreateElement("OldSound"); oldSound.InnerText = "bladeSwing"; root.AppendChild(oldSound); var displayId = doc.CreateElement("DisplayId"); displayId.InnerText = DisplayName; root.AppendChild(displayId); doc.AppendChild(root); var writer = new StringWriter(); doc.Save(writer); var desktopFolder = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); var fullFileName = Path.Combine(desktopFolder, "Generated Item.xml"); var dlr = MessageBox.Show(writer.ToString(), "Finished XML", MessageBoxButtons.YesNo); if (dlr != DialogResult.Yes) { return; } MessageBox.Show("Saving generated XML file to \r\n" + fullFileName); doc.Save(fullFileName); }