WFA_psychometric_chart.Form1_main.InsertChartComfortzoneInfo C# (CSharp) Method

InsertChartComfortzoneInfo() public method

public InsertChartComfortzoneInfo ( string chartid, string comfortzone_id ) : void
chartid string
comfortzone_id string
return void
        public void InsertChartComfortzoneInfo(string chartid, string comfortzone_id)
        {

            //string idValue = GetGUID();
            string tableName = "tbl_" + selectedBuildingList[0].BuildingName + "_chart_comfort_zone_setting";   // currentLineTableFromDB;
            string databasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            string databaseFile = databasePath + @"\db_psychrometric_project.s3db";
            string connString = @"Data Source=" + databaseFile + ";Version=3;";

            using (SQLiteConnection connection = new SQLiteConnection(connString))
            {
                connection.Open();
                //SQLiteDataReader reader = null;
                string sql_string = "insert into " + tableName + "(chartID,comfort_zone_ID) VALUES(@chartid,@comfortzoneid)";
                SQLiteCommand command = new SQLiteCommand(sql_string, connection);
                command.CommandType = CommandType.Text;
                command.Parameters.AddWithValue("@chartid", chartid);
                command.Parameters.AddWithValue("@comfortzoneid", comfortzone_id);
                command.ExecuteNonQuery();
            }
        }

Usage Example

        private void button1_Click(object sender, EventArgs e)
        {
            //When ok button is clicked the there should be plotting of the comfort zone.
            //This has basically two function...

            /*
             * 1.insert the comfort zone info to database
             * 2. Plot the comfort zone based on the value passed.
             */
            if (textBox1.Text != "" && textBox2.Text != "" && textBox3.Text != "" && textBox4.Text != "")
            {
                //chart id
                string chartid       = bs.chartDetailList[bs.indexOfChartSelected].chartID;
                string comfortzoneid = bs.listComfortZoneDetail[comboBox1.SelectedIndex].id;
                bs.InsertChartComfortzoneInfo(chartid, comfortzoneid);

                //now second part call the plot function
                // bs.PlotComfortZone()
                double mint = double.Parse(textBox1.Text);
                double maxt = double.Parse(textBox2.Text);
                double minh = double.Parse(textBox3.Text);
                double maxh = double.Parse(textBox4.Text);
                Color  c    = bs.listComfortZoneDetail[comboBox1.SelectedIndex].colorValue;
                string name = bs.listComfortZoneDetail[comboBox1.SelectedIndex].name;
                if (bs.default_comfort_zone_of_chart.Count > 0)
                {
                    if (bs.listchartComfortZoneInfoSingle.Count > 0)
                    {
                        //If default comfort zone is present then
                        //Clear previous one
                        //MessageBox.Show("Clear previous comfortzone");
                        bs.ClearComfortZone(double.Parse(bs.listchartComfortZoneInfoSingle[0].min_temp), double.Parse(bs.listchartComfortZoneInfoSingle[0].max_temp), double.Parse(bs.listchartComfortZoneInfoSingle[0].min_hum), double.Parse(bs.listchartComfortZoneInfoSingle[0].max_hum));
                    }
                }

                bs.PlotComfortZone(mint, maxt, minh, maxh, c, name);

                //insert of update database value
                bs.insertOrUpdateComfortChartSetting(chartid, comfortzoneid);

                if (bs.dataGridView1.Rows.Count > 0)  //If there is data then only do this one
                {
                    //set parameters of your event args
                    var eventArgs = new DataGridViewCellEventArgs(1, bs.dataGridView1.CurrentCell.RowIndex);
                    // or setting the selected cells manually before executing the function
                    bs.dataGridView1.Rows[bs.dataGridView1.CurrentCell.RowIndex].Cells[1].Selected = true;
                    bs.dataGridView1_CellClick(sender, eventArgs);
                }

                this.Close();
            }//close of if
        }
Form1_main