Exemplo n.º 1
0
 private void GetData(string selectCommand)
 {
     try
     {
         // Create a new data adapter based on the specified query.
         RegiondataAdapter = new MySqlDataAdapter(selectCommand, Util.Connection);
         // Create a command builder to generate SQL update, insert, and
         // delete commands based on selectCommand. These are used to
         // update the database.
         commandBuilder = new MySqlCommandBuilder(RegiondataAdapter);
         RegionDatatable.Clear();
         // Populate a new data table and bind it to the BindingSource.
         RegionDatatable.Locale = System.Globalization.CultureInfo.InvariantCulture;
         RegiondataAdapter.Fill(RegionDatatable);
         RegionbindingSource.DataSource = RegionDatatable;
     }
     catch (MySqlException ex)
     {
         MessageBox.Show("Error " + ex.Message);
     }
 }
Exemplo n.º 2
0
        private void SaveNewRegion_Click(object sender, EventArgs e)
        {
            #region Check Box Value

            if (Util.IsEmpty(this.RegionIDtextBox.Text))
            {
                MessageBox.Show("You need to specify a RegionID value.");
                return;
            }
            int styleid;
            if (!Int32.TryParse(RegionIDtextBox.Text.ToString(), out styleid))
            {
                MessageBox.Show("You need to specify a numeric value for RegionID.");
                return;
            }

            if (Util.IsEmpty(this.IPtextBox.Text))
            {
                MessageBox.Show("You need to specify a IPtextBox value.");
                return;
            }

            if (Util.IsEmpty(this.PorttextBox.Text))
            {
                MessageBox.Show("You need to specify a Port value.");
                return;
            }
            int port;
            if (!Int32.TryParse(PorttextBox.Text.ToString(), out port))
            {
                MessageBox.Show("You need to specify a numeric value for Port.");
                return;
            }

            if (Util.IsEmpty(this.WaterLeveltextBox.Text))
            {
                MessageBox.Show("You need to specify a WaterLevel value.");
                return;
            }
            int waterLevel;
            if (!Int32.TryParse(WaterLeveltextBox.Text.ToString(), out waterLevel))
            {
                MessageBox.Show("You need to specify a numeric value for water level.");
                return;
            }

            #endregion Check Box Value

            if (MessageBox.Show("Save this new region?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                this.RegiondataGridView.ReadOnly = false;

                long i = 1;
                foreach (byte b in Guid.NewGuid().ToByteArray())
                {
                    i *= ((int)b + 1);
                }
                i -= DateTime.Now.Ticks;
                string  str     = "Dol_Server_Editor_" + i.ToString();
                DataRow datarow = RegionDatatable.NewRow();

                datarow["Regions_ID"]     = str;
                datarow["RegionID"]       = Util.Find_Free_Region_ID();
                datarow["Name"]           = NametextBox.Text;
                datarow["Description"]    = DescriptiontextBox.Text;
                datarow["IP"]             = IPtextBox.Text;
                datarow["Port"]           = PorttextBox.Text;
                datarow["Expansion"]      = ExpansioncomboBox.Text;
                datarow["HousingEnabled"] = Util.Find_Bool_Value(HousingEnablecomboBox.Text);
                datarow["DivingEnabled"]  = Util.Find_Bool_Value(DivingEnablecomboBox.Text);
                datarow["WaterLevel"]     = WaterLeveltextBox.Text;
                datarow["ClassType"]      = ClassTypecomboBox.Text;
                datarow["IsFrontier"]     = Util.Find_Bool_Value(IsFrontiercomboBox.Text);

                RegionDatatable.Rows.Add(datarow);

                this.Validate();
                this.RegionbindingSource.EndEdit();

                try
                {
                    this.RegiondataAdapter.Update(RegionDatatable);
                }
                catch (MySqlException s)
                {
                    MessageBox.Show(s.Message);
                }

                this.RegiondataGridView.ReadOnly = true;
                this.EditRegionControl.Hide();
                this.RegiondataGridView.Show();
                this.ControlMenu.Visible         = true;
                this.AddRegionButton.Visible     = true;
                this.RegionListingButton.Visible = false;
                this.SaveNewbutton.Hide();
            }
        }