Exemple #1
0
        private void shortcut_Click(object sender, RoutedEventArgs e)
        {
            ViewStudent viewStudent = new ViewStudent();

            (this.Parent as Grid).Children.Add(viewStudent);
            (this.Parent as Grid).Children.Remove(this);
        }
Exemple #2
0
        private void save_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                SQLiteConnection conn;
                conn = new SQLiteConnection(@"Data Source=Database\MainDatabase.db;Version=3;");
                conn.Open();
                if (student_name.Text == "" || contact_no1.Text == "" || reg_no.Text == "" || batch.Text == "")
                {
                    MessageBox.Show("Student Name, Contact number, Registration Number and Batch are mandatory.");
                    return;
                }
                Int64 temp;
                if (!(Int64.TryParse(contact_no1.Text, out temp)))
                {
                    MessageBox.Show("Enter proper contact number");
                    return;
                }
                string sql, sql2;
                if (updateStudent == null)
                {
                    sql = "INSERT INTO student( student_name, contact_no1, studying_at, studying_at_name, address, student_email, parent_name, contact_no2, reg_no, batch, subjects, other_details, balance_fees) VALUES('"
                          + student_name.Text + "', '"
                          + contact_no1.Text + "', '"
                          + studying_at.Text + "', '"
                          + studying_at_name.Text + "', '"
                          + address.Text + "', '"
                          + student_email.Text + "', '"
                          + parent_name.Text + "', '"
                          + contact_no2.Text + "', '"
                          + reg_no.Text + "', '"
                          + batch.Text + "', '"
                          + subjects.Text + "', '"
                          + other_details.Text + "', '"
                          + balance_fees.Text + "');";

                    Student student = new Student();
                    student.Name  = student_name.Text;
                    student.RegNo = reg_no.Text;
                    string json = JsonConvert.SerializeObject(student);
                    sql2 = "INSERT INTO attendance VALUES('"
                           + reg_no.Text + "', '"
                           + json + "', '"
                           + json + "', '"
                           + json + "', '"
                           + json + "', '"
                           + json + "', '"
                           + json + "', '"
                           + json + "', '"
                           + json + "', '"
                           + json + "', '"
                           + json + "', '"
                           + json + "', '"
                           + json + "');";
                }
                else
                {
                    sql = "update student set student_name='"
                          + student_name.Text + "',  contact_no1 ='"
                          + contact_no1.Text + "',  studying_at ='"
                          + studying_at.Text + "', studying_at_name='"
                          + studying_at_name.Text + "', address='"
                          + address.Text + "', student_email='"
                          + student_email.Text + "', parent_name= '"
                          + parent_name.Text + "', contact_no2='"
                          + contact_no2.Text + "', reg_no='"
                          + reg_no.Text + "', batch='"
                          + batch.Text + "', subjects='"
                          + subjects.Text + "', other_details= '"
                          + other_details.Text + "', balance_fees='"
                          + balance_fees.Text + "' where reg_no='" + updateStudent + "';";

                    sql2 = "UPDATE attendance SET reg_no='" + reg_no.Text + "' WHERE reg_no='" + updateStudent + "';";
                }
                SQLiteCommand command = new SQLiteCommand(sql, conn);
                command.ExecuteNonQuery();
                command = new SQLiteCommand(sql2, conn);
                command.ExecuteNonQuery();
                conn.Close();
                student_name.Text     = contact_no1.Text = address.Text = studying_at.Text = "";
                studying_at_name.Text = student_email.Text = parent_name.Text = contact_no2.Text = reg_no.Text = "";
                batch.Text            = subjects.Text = other_details.Text = balance_fees.Text = "";
                if (updateStudent == null)
                {
                    //MessageBox.Show("Saved");
                    MessageBox.Show("Saved");
                }
                else
                {
                    ViewStudent vwstud = new ViewStudent();
                    vwstud.FillDataGrid();
                    (this.Parent as Grid).Children.Add(vwstud);
                    (this.Parent as Grid).Children.Remove(this);
                }
            }
            catch (SQLiteException)
            {
                MessageBox.Show("Please check input again (Reg no might already be in use)");
            }
            catch (Exception ex)
            {
                string msg = ex.GetType().Name + " : " + ex.Message;
                MessageBox.Show(msg);
            }
        }