public bool AddDirector(clsDirector info)
        {
            int st = 0;

            try
            {
                using (SqlConnection conn = new SqlConnection(strConn))
                {
                    conn.Open();

                    {
                        using (SqlCommand cmd = new SqlCommand("TMR_USP_AddDirector"))
                        {
                            cmd.CommandType = CommandType.StoredProcedure;
                            cmd.Connection  = conn;
                            cmd.Parameters.AddWithValue("@DirectorName", info.strName);
                            cmd.Parameters.AddWithValue("@CNIC", info.strCNIC);

                            st = cmd.ExecuteNonQuery();
                        }
                    }
                    conn.Close();
                }
            }
            catch (Exception ex) { }
            if (st > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public List <clsDirector> GetAllDirectors()
        {
            List <clsDirector> lst = new List <clsDirector>();

            using (SqlConnection conn = new SqlConnection(strConn))
            {
                conn.Open();

                using (SqlCommand cmd = new SqlCommand("TMR_USP_GetDirectors"))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Connection  = conn;

                    SqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        var info = new clsDirector();

                        info.strName = reader["DirectorName"].ToString();
                        info.strCNIC = reader["Cnic"].ToString();
                        info.id      = Convert.ToInt32(reader["ID"]);

                        lst.Add(info);
                    }
                    conn.Close();
                }
            }
            return(lst);
        }
예제 #3
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (txtName.Text.Trim() == string.Empty)
            {
                MessageBox.Show("Please enter a name.");
                txtName.Focus();
                return;
            }
            if (txtCNIC.Text.Trim() == "")
            {
                MessageBox.Show("Please enter a CNIC #.");
                txtCNIC.Focus();
                return;
            }

            foreach (DataGridViewRow dgr in dgList.Rows)
            {
                if (dgr.Cells["DirectorName"].Value.ToString().Trim().ToUpper() == txtName.Text.Trim().ToUpper() && this.id != Convert.ToInt32(dgr.Cells["ID1"].Value))
                {
                    MessageBox.Show("A director with same name already exists.");
                    return;
                }
            }

            clsDirector cat = new clsDirector();

            cat.strName = txtName.Text.Trim();
            cat.strCNIC = txtCNIC.Text.Trim();
            cat.id      = this.id;

            bool result = da.AddDirector(cat);

            if (result == false)
            {
                MessageBox.Show("An error occurred.");
                return;
            }

            LoadDirectors();

            Clear();
        }