Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.90 KB | None | 0 0
  1.         public static int SavePlayerCharacter(PlayerModule playerModule)
  2.         {
  3.             // just init return value
  4.             int id = -1
  5.            
  6.             // use mysql connection
  7.             using (MySqlConnection connection = new MySqlConnection(connectionString))
  8.             {
  9.                 // generate MySqlCommand
  10.                 MySqlCommand command = connection.CreateCommand();
  11.                
  12.                 // INSERT command Builder
  13.                 command.CommandText = "INSERT INTO characters VALUES(@characterName, @accountID, @firstName, @lastName, @birthday, @age, @posX, @posY, @posZ, @rotation, @money, @bank, @armor, @sex, ";
  14.                 command.CommandText += "@fraction, @job, @rank, @phone, @radio, @jailed, @vehicleKeys, @documentation, @license, @insurance, @weaponLicense, @houseRent, @houseEntered, @businesEntered, ";
  15.                 command.CommandText += "@jobDeliver, @jobColldown, @played, @status, @socialName, @adminRank, @adminname, @employeeCooldown, @duty, @killed, @jobPoints, @rolePoints)";
  16.                 command.Parameters.AddWithValue("@characterName", playerModule.firstName + " " + playerModule.lastName);
  17.                 command.Parameters.AddWithValue("@accountID", playerModule.id);
  18.                 command.Parameters.AddWithValue("@firstName", playerModule.firstName);
  19.                 command.Parameters.AddWithValue("@lastName", playerModule.lastName);
  20.                 command.Parameters.AddWithValue("@birthdate", playerModule.birthdate);
  21.                 command.Parameters.AddWithValue("@realName", playerModule.realName);
  22.                 command.Parameters.AddWithValue("@adminName", playerModule.adminName);
  23.                 command.Parameters.AddWithValue("@adminRank", playerModule.adminRank);
  24.                 command.Parameters.AddWithValue("@posX", playerModule.position.X);
  25.                 command.Parameters.AddWithValue("@posY", playerModule.position.Y);
  26.                 command.Parameters.AddWithValue("@posZ", playerModule.position.Z);
  27.                 command.Parameters.AddWithValue("@rotation", playerModule.rotation.Z);
  28.                 command.Parameters.AddWithValue("@money", playerModule.money);
  29.                 command.Parameters.AddWithValue("@bank", playerModule.bank);
  30.                 command.Parameters.AddWithValue("@health", playerModule.health);
  31.                 command.Parameters.AddWithValue("@armor", playerModule.armor);
  32.                 command.Parameters.AddWithValue("@age", playerModule.age);
  33.                 command.Parameters.AddWithValue("@sex", playerModule.sex);
  34.                 command.Parameters.AddWithValue("@fraction", playerModule.fraction);
  35.                 command.Parameters.AddWithValue("@job", playerModule.job);
  36.                 command.Parameters.AddWithValue("@duty", playerModule.duty);
  37.                 command.Parameters.AddWithValue("@phone", playerModule.phone);
  38.                 command.Parameters.AddWithValue("@rank", playerModule.rank);
  39.                 command.Parameters.AddWithValue("@killed", playerModule.killed);
  40.                 command.Parameters.AddWithValue("@jailed", playerModule.jailed);
  41.                 command.Parameters.AddWithValue("@vehiecleKeys", playerModule.vehiecleKeys);
  42.                 command.Parameters.AddWithValue("@documentation", playerModule.documentation);
  43.                 command.Parameters.AddWithValue("@licenses", playerModule.licenses);
  44.                 command.Parameters.AddWithValue("@insurance", playerModule.insurance);
  45.                 command.Parameters.AddWithValue("@weaponLicense", playerModule.weaponLicense);
  46.                 command.Parameters.AddWithValue("@houseRent", playerModule.houseRent);
  47.                 command.Parameters.AddWithValue("@houseEntered", playerModule.houseEntered);
  48.                 command.Parameters.AddWithValue("@businessEntered", playerModule.businessEntered);
  49.                 command.Parameters.AddWithValue("@jobDeliver", playerModule.jobDeliver);
  50.                 command.Parameters.AddWithValue("@jobCooldown", playerModule.jobCooldown);
  51.                 command.Parameters.AddWithValue("@played", playerModule.played);
  52.                 command.Parameters.AddWithValue("@status", playerModule.status);
  53.                 command.Parameters.AddWithValue("@socialName", playerModule.socialName);
  54.                 command.Parameters.AddWithValue("@employeeCooldown", playerModule.employeeCooldown);
  55.                 command.Parameters.AddWithValue("@jobPoints", playerModule.jobPoints);
  56.                
  57.                 // open the Connection
  58.                 connection.Open();
  59.                
  60.                 // prepare the command
  61.                 command.Prepare();
  62.                 try
  63.                 {
  64.                     //execute Command
  65.                     command.ExecuteNonQuery();
  66.  
  67.                 }
  68.                 catch (Exception ex)
  69.                 {
  70.                     // write exeption on Console
  71.                     NAPI.Util.ConsoleOutput("[EXCEPTION SaveCharacter] " + ex.Message);
  72.                     NAPI.Util.ConsoleOutput("[EXCEPTION SaveCharacter] " + ex.StackTrace);
  73.  
  74.                 }
  75.                
  76.                 // get lastInsertID
  77.                 id = (int)command.LastInsertedId;
  78.                
  79.                 // return the Character ID
  80.                 return id;
  81.             }
  82.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement