コード例 #1
0
        public static void getModelFromDataBaseWithScaleFactor(float modelX, float modelY, float modelZ, float scaleFactor)
        {
            try
            {
                NpgsqlConnection connection = DataBaseConnect.GetConnection();
                connection.Open();
                NpgsqlCommand command = new NpgsqlCommand();
                command.Connection = connection;


                if (GetModels.allModelsCheckBox.Checked)
                {
                    command.CommandText = "select model_id,model_name,model_x,model_y,model_z from models where model_x>@minModel_x and model_x<@maxModel_x and" +
                                          " model_y>@minModel_y and model_y<@maxModel_y and model_z>@minModel_z and model_z<@maxModel_z and (model_private is not true or user_id=@user_id);";
                }
                else
                {
                    command.CommandText = "select model_id,model_name,model_x,model_y,model_z from models where model_x>@minModel_x and model_x<@maxModel_x and" +
                                          " model_y>@minModel_y and model_y<@maxModel_y and model_z>@minModel_z and model_z<@maxModel_z and user_id=@user_id;";
                }

                command.Parameters.AddWithValue("@user_id", getUserIdByLoginAndPassword(Utils.GetLogin(), Utils.GetPassword()));
                command.Parameters.AddWithValue("@model_x", modelX);
                command.Parameters.AddWithValue("@model_y", modelY);
                command.Parameters.AddWithValue("@model_z", modelZ);

                command.Parameters.AddWithValue("@minModel_x", modelX - modelX * scaleFactor / 100);
                command.Parameters.AddWithValue("@minModel_y", modelY - modelY * scaleFactor / 100);
                command.Parameters.AddWithValue("@minModel_z", modelZ - modelZ * scaleFactor / 100);

                command.Parameters.AddWithValue("@maxModel_x", modelX + modelX * scaleFactor / 100);
                command.Parameters.AddWithValue("@maxModel_y", modelY + modelY * scaleFactor / 100);
                command.Parameters.AddWithValue("@maxModel_z", modelZ + modelZ * scaleFactor / 100);

                NpgsqlDataReader dr = command.ExecuteReader();
                if (dr.HasRows)
                {   //TODO: Make getModelFromDataBaseWithScaleFactor() returns NpgsqlDataReader, and use this method with result
                    GetModelsController.SetViewDataGrid(dr);
                }
                else
                {
                    MessageBox.Show("There is no models with this paremeters!", "Try other params", MessageBoxButtons.OK);
                }

                connection.Close();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "getModelFromDataBase()", MessageBoxButtons.OK);
            }
        }
コード例 #2
0
 private void searchButton_Click(object sender, EventArgs e)
 {
     GetModelsController.SearchModels();
 }