示例#1
0
        public IList <Depart> GetAllDepartment()
        {
            _ds = new DataSet();

            using (SqlConnection con = new SqlConnection(connect))
            {
                con.Open();
                SqlCommand cmd = new SqlCommand("DepartCrud", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@mode", "GetDepartList");
                _adapter = new SqlDataAdapter(cmd);
                _adapter.Fill(_ds);

                if (_ds.Tables.Count > 0)
                {
                    for (int i = 0; i < _ds.Tables[0].Rows.Count; i++)
                    {
                        Depart obj = new Depart();
                        obj.DepartId   = Convert.ToInt32(_ds.Tables[0].Rows[i]["DepartId"]);
                        obj.DepartName = Convert.ToString(_ds.Tables[0].Rows[i]["DepartName"]);


                        departList.Add(obj);
                    }
                }
            }


            return(departList);
        }
示例#2
0
        public void UpdateDepartment(Depart model)
        {
            using (SqlConnection con = new SqlConnection(connect))
            {
                con.Open();
                SqlCommand cmd = new SqlCommand("DepartCrud", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@mode", "UpdateDepart");
                cmd.Parameters.AddWithValue("@DepId", model.DepartId);
                cmd.Parameters.AddWithValue("@DepName", model.DepartName);

                cmd.ExecuteNonQuery();
            }
        }
示例#3
0
        public Depart GetDepartById(int id)
        {
            var obj = new Depart();

            using (SqlConnection con = new SqlConnection(connect))
            {
                con.Open();
                SqlCommand cmd = new SqlCommand("DepartCrud", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@mode", "GetDepById");
                cmd.Parameters.AddWithValue("@DepId", id);
                _adapter = new SqlDataAdapter(cmd);
                _ds      = new DataSet();
                _adapter.Fill(_ds);
                if (_ds.Tables.Count > 0 && _ds.Tables[0].Rows.Count > 0)
                {
                    obj.DepartId   = Convert.ToInt32(_ds.Tables[0].Rows[0]["DepartId"]);
                    obj.DepartName = Convert.ToString(_ds.Tables[0].Rows[0]["DepartName"]);
                }
            }
            return(obj);
        }