Ejemplo n.º 1
0
        private void Add_Click(object sender, EventArgs e)
        {
            int flag = 0;

            try
            {
                AdvisorClass stu = new AdvisorClass();
                stu.Gender      = null;
                stu.LastName    = null;
                stu.Contact     = null;
                stu.DateOfBirth = null;
                stu.Salary      = null;
                if (Regexp("^[a-zA-Z]{1,100}", FirstNameTextBox, FNError, "Only alphabets are allowed.", 100))
                {
                    stu.FirstName = FirstNameTextBox.Text;
                    flag++;
                }
                if ((string.IsNullOrEmpty(LastNameTextBox.Text)))
                {
                    flag++;
                }
                else if (Regexp("^[a-zA-Z]{1,100}", LastNameTextBox, LNError, "Only alphabets are allowed.", 100))
                {
                    stu.LastName = LastNameTextBox.Text;
                    flag++;
                }
                if ((string.IsNullOrEmpty(ContactTextBox.Text)))
                {
                    flag++;
                }
                else if (Regexp("^[0-9]{1,20}", ContactTextBox, ConError, "Only valid numbers are allowed.", 20))
                {
                    stu.Contact = ContactTextBox.Text;
                    flag++;
                }
                if (Regexp("^([\\w\\.\\-]+)@([\\w\\-]+)((\\.(\\w){2,3})+)$", EmailTextBox, EmailError, "Format not correct eg. [email protected]", 30))
                {
                    stu.Email = EmailTextBox.Text;
                    String cmd1    = "Select Id from Person Where Email = '" + EmailTextBox.Text + "'";
                    var    reader1 = DatabaseConnection.getInstance().getData(cmd1);
                    while (reader1.Read())
                    {
                        flag--;
                        EmailError.Text      = "Already exists";
                        EmailError.ForeColor = System.Drawing.Color.Red;
                    }
                    flag++;
                }
                stu.DateOfBirth = DateOfBirthPick.Value;
                flag++;
                if ((string.IsNullOrEmpty(SalaryTextBox.Text)))
                {
                    flag++;
                }
                else if (Regexp("[0-9]{1,18}", SalaryTextBox, SalaryError, "Only valid numbers are allowed.", 18))
                {
                    stu.Salary = Convert.ToDecimal(SalaryTextBox.Text);
                    flag++;
                }
                String cmd    = "Select Id from Lookup Where Category = 'GENDER' AND Value = '" + GenderComboBox.Text + "'";
                var    reader = DatabaseConnection.getInstance().getData(cmd);
                while (reader.Read())
                {
                    stu.Gender = (int)reader.GetValue(0);
                }
                flag++;
                cmd    = "Select Id from Lookup Where Category = 'DESIGNATION' AND Value = '" + DesComboBox.Text + "'";
                reader = DatabaseConnection.getInstance().getData(cmd);
                while (reader.Read())
                {
                    stu.Designation = (int)reader.GetValue(0);
                }
                flag++;
                if (flag == 8)
                {
                    cmd = String.Format("INSERT INTO Person(FirstName, LastName, Contact, Email, DateOfBirth, Gender) values('{0}','{1}','{2}','{3}','{4}','{5}')", stu.FirstName, stu.LastName, stu.Contact, stu.Email, stu.DateOfBirth, stu.Gender);
                    DatabaseConnection.getInstance().exectuteQuery(cmd);
                    cmd    = "Select Id from Person Where Email = '" + stu.Email + "'";
                    reader = DatabaseConnection.getInstance().getData(cmd);
                    int?id = null;
                    while (reader.Read())
                    {
                        id = (int)reader.GetValue(0);
                    }
                    if (id != null)
                    {
                        cmd = String.Format("Insert INTO Advisor(Id, Designation, Salary) values('{0}', '{1}', '{2}')", id, stu.Designation, stu.Salary);
                        DatabaseConnection.getInstance().exectuteQuery(cmd);
                    }
                    par.Refresh();
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 2
0
        public Project()
        {
            InitializeComponent();
            this.MinimumSize = new Size(this.Width, this.Height);
            try
            {
                String cmd    = "Select Id, Title, Description from Project";
                var    reader = DatabaseConnection.getInstance().getData(cmd);

                List <ProjectClass> students = new List <ProjectClass>();
                while (reader.Read())
                {
                    ProjectClass stu = new ProjectClass();
                    stu.Id          = (int)reader.GetValue(0);
                    stu.Titlle      = reader.GetString(1);
                    stu.Description = reader.GetString(2);
                    students.Add(stu);
                }
                ProjectDataGrid.DataSource         = students;
                ProjectDataGrid.Columns[0].Visible = false;
                ProjectDataGrid.Columns[2].Visible = false;
                DataGridViewButtonColumn bcol3 = new DataGridViewButtonColumn();
                bcol3.HeaderText = "";
                bcol3.Text       = "Details";
                bcol3.Name       = "btnDetails";
                bcol3.UseColumnTextForButtonValue = true;
                ProjectDataGrid.Columns.Add(bcol3);
                DataGridViewButtonColumn bcol = new DataGridViewButtonColumn();
                bcol.HeaderText = "";
                bcol.Text       = "Edit";
                bcol.Name       = "btnEdit";
                bcol.UseColumnTextForButtonValue = true;
                ProjectDataGrid.Columns.Add(bcol);
                DataGridViewButtonColumn bcol1 = new DataGridViewButtonColumn();
                bcol1.HeaderText = "";
                bcol1.Text       = "Delete";
                bcol1.Name       = "btnDelete";
                bcol1.UseColumnTextForButtonValue = true;
                ProjectDataGrid.Columns.Add(bcol1);
                DataGridViewButtonColumn bcol2 = new DataGridViewButtonColumn();
                bcol2.HeaderText = "";
                bcol2.Text       = "Group";
                bcol2.Name       = "btnGroup";
                bcol2.UseColumnTextForButtonValue = true;
                ProjectDataGrid.Columns.Add(bcol2);
                cmd    = "Select Title from Project";
                reader = DatabaseConnection.getInstance().getData(cmd);
                int i = 0;
                while (reader.FieldCount > i)
                {
                    if (!SearchCategory.Items.Contains(reader.GetName(i)))
                    {
                        SearchCategory.Items.Add(reader.GetName(i));
                    }
                    i++;
                }
                SearchCategory.SelectedIndex = 0;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }