예제 #1
0
        private void button7_Click(object sender, EventArgs e)
        {
            label9.Visible = false;
            string   studentId = textBox1.Text;
            string   intake    = comboBox1.SelectedItem.ToString();
            string   fName     = textBox2.Text;
            string   lName     = textBox3.Text;
            string   pNo       = textBox4.Text;
            DateTime bd        = dateTimePicker1.Value;
            string   address   = textBox6.Text;

            if (studentId.Length < 2 || intake.Length < 2 || fName.Length < 2 || lName.Length < 2 ||
                pNo.Length < 2 || address.Length < 2)
            {
                label9.Text    = "Please Fill All The Fields";
                label9.Visible = true;
                return;
            }
            DataSets.student studentInfo = new DataSets.student();
            studentInfo.id      = studentId;
            studentInfo.intake  = intake;
            studentInfo.fname   = fName;
            studentInfo.lname   = lName;
            studentInfo.pno     = pNo;
            studentInfo.bd      = bd;
            studentInfo.address = address;
            if (dbm.addStudent(studentInfo))
            {
                MessageBox.Show("The New Student Has Been Added Successfully.");
                this.Dispose();
            }
            label9.Text    = "The Student Is Already Exist";
            label9.Visible = true;
        }
        public List <DataSets.student> getStudents()
        {
            List <DataSets.student> retVal = new List <DataSets.student>();

            m_dbConnection.Open();
            string           sql     = "SELECT * FROM STUDENT";
            SQLiteCommand    command = new SQLiteCommand(sql, m_dbConnection);
            SQLiteDataReader reader  = command.ExecuteReader();

            while (reader.Read())
            {
                DataSets.student temp = new DataSets.student();
                temp.id      = reader.GetString(0);
                temp.intake  = reader.GetString(1);
                temp.fname   = reader.GetString(2);
                temp.lname   = reader.GetString(3);
                temp.pno     = reader.GetString(4);
                temp.bd      = DateTime.Parse(reader.GetString(5));
                temp.address = reader.GetString(6);
                retVal.Add(temp);
            }
            reader.Close();
            m_dbConnection.Close();
            return(retVal);
        }
        //(id varchar(20),intake varchar(20),fname varchar(20),lname varchar(20),pno varchar(20),bd DATETIME,address varchar(100))
        public bool addStudent(DataSets.student stInfo)
        {
            bool retVal = false;

            m_dbConnection.Open();
            string           sql     = "SELECT * FROM STUDENT WHERE id='" + stInfo.id + "'";
            SQLiteCommand    command = new SQLiteCommand(sql, m_dbConnection);
            SQLiteDataReader reader  = command.ExecuteReader();

            if (!reader.Read())
            {
                reader.Close();
                retVal = true;
                sql    = "INSERT INTO STUDENT (id,intake,fname,lname,pno,bd,address) values('" + stInfo.id +
                         "','" + stInfo.intake + "','" + stInfo.fname + "','" + stInfo.lname + "','" + stInfo.pno +
                         "','" + stInfo.bd + "','" + stInfo.address + "')";
                command = new SQLiteCommand(sql, m_dbConnection);
                command.ExecuteNonQuery();
                m_dbConnection.Close();
                return(retVal);
            }
            reader.Close();
            m_dbConnection.Close();
            return(retVal);
        }
        public void updateStudent(DataSets.student stInfo)
        {
            m_dbConnection.Open();
            string sql = "UPDATE STUDENT SET intake='" + stInfo.intake + "',fname='" + stInfo.fname +
                         "',lname='" + stInfo.lname + "',pno='" + stInfo.pno + "',bd='" + stInfo.bd + "',address='" +
                         stInfo.address + "' WHERE id='" + stInfo.id + "'";
            SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);

            command.ExecuteNonQuery();
            m_dbConnection.Close();
        }