Example #1
0
        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            //Load DatagridView into AlarmSettings Form
            AlarmSettings AlarmSettingsGui = new AlarmSettings(this);
            AlarmSettingsGui.LastRowIndex = e.RowIndex;
            if(dataGridView1.Rows[e.RowIndex].Cells[0].Value != null) {
                AlarmSettingsGui.Date = string.Format("{0:dd.MM.yyyy}", dataGridView1.Rows[e.RowIndex].Cells[0].Value);
            }
            if (dataGridView1.Rows[e.RowIndex].Cells[1].Value != null) {
                AlarmSettingsGui.Hour = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
            }
            if (dataGridView1.Rows[e.RowIndex].Cells[2].Value != null) {
                AlarmSettingsGui.Minute = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
            }
            if (dataGridView1.Rows[e.RowIndex].Cells[3].Value != null) {
                AlarmSettingsGui.AlarmActive = Convert.ToBoolean(dataGridView1.Rows[e.RowIndex].Cells[3].Value);
            }
            if (dataGridView1.Rows[e.RowIndex].Cells[4].Value != null) {
                AlarmSettingsGui.Note = dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString();
            }
            if (dataGridView1.Rows[e.RowIndex].Cells[5].Value != null) {
                AlarmSettingsGui.ProgPathActiv = Convert.ToBoolean(dataGridView1.Rows[e.RowIndex].Cells[5].Value);
            }
            if (dataGridView1.Rows[e.RowIndex].Cells[6].Value != null) {
                AlarmSettingsGui.ProgPath = dataGridView1.Rows[e.RowIndex].Cells[6].Value.ToString(); //Path to start Programm
            }
            if (dataGridView1.Rows[e.RowIndex].Cells[7].Value != null) {
                AlarmSettingsGui.SoundActive = Convert.ToBoolean(dataGridView1.Rows[e.RowIndex].Cells[7].Value);
            }
            if (dataGridView1.Rows[e.RowIndex].Cells[8].Value != null) {
                AlarmSettingsGui.SoundSource = dataGridView1.Rows[e.RowIndex].Cells[8].Value.ToString(); //Radiobtn "ringtone", "soundfile", "youtube"
            }
            if (dataGridView1.Rows[e.RowIndex].Cells[9].Value != null) {
                AlarmSettingsGui.ID = dataGridView1.Rows[e.RowIndex].Cells[9].Value.ToString(); ;
            }
            if (dataGridView1.Rows[e.RowIndex].Cells[10].Value != null) {
                AlarmSettingsGui.YoutubePath = dataGridView1.Rows[e.RowIndex].Cells[10].Value.ToString();
            }
            if (dataGridView1.Rows[e.RowIndex].Cells[11].Value != null) {
                AlarmSettingsGui.AlarmSound = dataGridView1.Rows[e.RowIndex].Cells[11].Value.ToString();
            }
            if (dataGridView1.Rows[e.RowIndex].Cells[12].Value != null) {
                AlarmSettingsGui.Mon = Convert.ToBoolean(dataGridView1.Rows[e.RowIndex].Cells[12].Value);
            }
            if (dataGridView1.Rows[e.RowIndex].Cells[13].Value != null) {
                AlarmSettingsGui.Tue = Convert.ToBoolean(dataGridView1.Rows[e.RowIndex].Cells[13].Value);
            }
            if (dataGridView1.Rows[e.RowIndex].Cells[14].Value != null) {
                AlarmSettingsGui.Wed = Convert.ToBoolean(dataGridView1.Rows[e.RowIndex].Cells[14].Value);
            }
            if (dataGridView1.Rows[e.RowIndex].Cells[15].Value != null) {
                AlarmSettingsGui.Thu = Convert.ToBoolean(dataGridView1.Rows[e.RowIndex].Cells[15].Value);
            }
            if (dataGridView1.Rows[e.RowIndex].Cells[16].Value != null) {
                AlarmSettingsGui.Fri = Convert.ToBoolean(dataGridView1.Rows[e.RowIndex].Cells[16].Value);
            }
            if (dataGridView1.Rows[e.RowIndex].Cells[17].Value != null) {
                AlarmSettingsGui.Sat = Convert.ToBoolean(dataGridView1.Rows[e.RowIndex].Cells[17].Value);
            }
            if (dataGridView1.Rows[e.RowIndex].Cells[18].Value != null) {
                AlarmSettingsGui.Sun = Convert.ToBoolean(dataGridView1.Rows[e.RowIndex].Cells[18].Value);
            }
            if (dataGridView1.Rows[e.RowIndex].Cells[19].Value != null) {
                AlarmSettingsGui.Repeat = Convert.ToBoolean(dataGridView1.Rows[e.RowIndex].Cells[19].Value);
            }
            AlarmSettingsGui.Show();

            ///
            // Manuel way to Set up a Form + Controls
            ///
            //Form GridForm = new Form();
            //GridForm.Visible = true;
            //GridForm.Show();

            ////GridNote
            //TextBox GridNote = new TextBox();
            //GridNote.Location = new Point(70, 5);
            //GridNote.Size = new System.Drawing.Size(210, 25);
            //GridNote.BackColor = Color.HotPink;
            //GridNote.Text = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
            //GridForm.Controls.Add(GridNote);

            ////GridNoteLabel
            //Label GlblNote = new Label();
            //GlblNote.Text = "Note:";
            //GlblNote.Location = new Point(5,5);
            //GridForm.Controls.Add(GlblNote);
        }
Example #2
0
        public void UpdateRowDetails(AlarmSettings settings)
        {
            dataGridView1.Rows[settings.LastRowIndex].Cells[0].Value = string.Format ("{0:dd.MM.yyyy}",settings.Date);
            dataGridView1.Rows[settings.LastRowIndex].Cells[1].Value = settings.Hour;
            if (dataGridView1.Rows[settings.LastRowIndex].Cells[2].Value != null) {
                dataGridView1.Rows[settings.LastRowIndex].Cells[2].Value = settings.Minute;
            }
            if (dataGridView1.Rows[settings.LastRowIndex].Cells[3].Value != null) {
                dataGridView1.Rows[settings.LastRowIndex].Cells[3].Value = settings.AlarmActive;
            }
            //if (dataGridView1.Rows[settings.LastRowIndex].Cells[4].Value != null) {
                dataGridView1.Rows[settings.LastRowIndex].Cells[4].Value = settings.Note;
            //}
            if (dataGridView1.Rows[settings.LastRowIndex].Cells[5].Value != null) {
                dataGridView1.Rows[settings.LastRowIndex].Cells[5].Value = settings.ProgPathActiv;
            }
            //if (dataGridView1.Rows[settings.LastRowIndex].Cells[6].Value != null) {
                dataGridView1.Rows[settings.LastRowIndex].Cells[6].Value = settings.ProgPath;
            //}
            if (dataGridView1.Rows[settings.LastRowIndex].Cells[7].Value != null) {
                dataGridView1.Rows[settings.LastRowIndex].Cells[7].Value = settings.SoundActive;
            }
            //if (dataGridView1.Rows[settings.LastRowIndex].Cells[8].Value != null) {
                dataGridView1.Rows[settings.LastRowIndex].Cells[8].Value = settings.SoundSource;
            //}
            if (dataGridView1.Rows[settings.LastRowIndex].Cells[9].Value != null) {
                dataGridView1.Rows[settings.LastRowIndex].Cells[9].Value = settings.ID;
            }
            //if (dataGridView1.Rows[settings.LastRowIndex].Cells[10].Value != null) {
                dataGridView1.Rows[settings.LastRowIndex].Cells[10].Value = settings.YoutubePath;
            //}
            if (dataGridView1.Rows[settings.LastRowIndex].Cells[11].Value != null) {
                dataGridView1.Rows[settings.LastRowIndex].Cells[11].Value = settings.AlarmSound;
            }
            dataGridView1.Rows[settings.LastRowIndex].Cells[12].Value = settings.Mon;
            dataGridView1.Rows[settings.LastRowIndex].Cells[13].Value = settings.Tue;
            dataGridView1.Rows[settings.LastRowIndex].Cells[14].Value = settings.Wed;
            dataGridView1.Rows[settings.LastRowIndex].Cells[15].Value = settings.Thu;
            dataGridView1.Rows[settings.LastRowIndex].Cells[16].Value = settings.Fri;
            dataGridView1.Rows[settings.LastRowIndex].Cells[17].Value = settings.Sat;
            dataGridView1.Rows[settings.LastRowIndex].Cells[18].Value = settings.Sun;
            dataGridView1.Rows[settings.LastRowIndex].Cells[19].Value = settings.Repeat;

            //AlarmSettingsGui.Hour = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString());
            //AlarmSettingsGui.Minute = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString());
            //AlarmSettingsGui.AlarmActive = Convert.ToBoolean(dataGridView1.Rows[e.RowIndex].Cells[3].Value);
            //AlarmSettingsGui.Note = dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString();
            //AlarmSettingsGui.ProgPathActiv = Convert.ToBoolean(dataGridView1.Rows[e.RowIndex].Cells[5].Value);
            //AlarmSettingsGui.ProgPath = dataGridView1.Rows[e.RowIndex].Cells[6].Value.ToString(); //Path to start Programm
            //AlarmSettingsGui.SoundActive = Convert.ToBoolean(dataGridView1.Rows[e.RowIndex].Cells[7].Value);
            //AlarmSettingsGui.SoundSource = dataGridView1.Rows[e.RowIndex].Cells[8].Value.ToString(); //Radiobtn "ringtone", "soundfile", "youtube"
            //AlarmSettingsGui.ID = dataGridView1.Rows[e.RowIndex].Cells[9].Value.ToString();

            StringBuilder sb = new StringBuilder();

            IEnumerable<string> columnNames = ADT.Columns.Cast<DataColumn>().Select(column => column.ColumnName);
            sb.AppendLine(string.Join(",", columnNames));

            foreach (DataRow row in ADT.Rows) {
                IEnumerable<string> fields = row.ItemArray.Select(field => string.Concat("\"", field.ToString().Replace("\"", "\"\""), "\""));
                sb.AppendLine(string.Join(",", fields));
            }

            File.WriteAllText("C:\\Temp\\AlarmList.csv", sb.ToString());
        }