コード例 #1
0
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        PManageDepartData model = new PManageDepartData();
        PManageDepartBB manageDepartBB = new PManageDepartBB();
        try
        {
            if (this.State == "1")
            {
                //�û�����һ����Ӷ��������
                manageDepartBB.AddRecord(Convert.ToInt32(this.empId.Value), Convert.ToInt32(this.roleId.SelectedValue), this.departId.Value);
            }
            else if (this.State == "2")
            {
                model = manageDepartBB.GetModel(this.IdValue);
                this.SetModel(ref model);
                manageDepartBB.ModifyRecord(model);
            }
        }
        catch (Exception ex)
        {
            this.ClientScript.RegisterStartupScript(this.GetType(), "ShowErr", "ShowErr(\"" + Server.UrlEncode(ex.Message) + "\",3);", true);
            return;
        }
        finally
        {
            manageDepartBB.Dispose();
        }

        Response.Redirect("PManageDepartList.aspx?itemNo=" + this.itemNo + "&pTypeNo=main", false);
    }
コード例 #2
0
        /// <summary>
        /// ����һ������
        /// </summary>
        /// <param name="model">model</param>
        public int AddRecord(PManageDepartData model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("set nocount on; ");
            strSql.Append("insert into PManageDepart(");
            strSql.Append("empId,roleId,departId)");
            strSql.Append(" values (");
            strSql.Append("@empId,@roleId,@departId)");
            strSql.Append("; select @@identity; set nocount off; ");
            SqlParameter[] parameters = {
                    new SqlParameter("@empId", SqlDbType.Int),
                    new SqlParameter("@roleId", SqlDbType.Int),
                    new SqlParameter("@departId", SqlDbType.Int)
                };
            parameters[0].Value = model.empId;
            parameters[1].Value = model.roleId;
            parameters[2].Value = model.departId;

            int id = 0;
            try
            {
                object ret = SqlHelper.ExecuteScalar(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters);

                if (ret != null && ret != DBNull.Value)
                {
                    id = Convert.ToInt32(ret);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return id;
        }
コード例 #3
0
        /// <summary>
        /// ����һ������
        /// </summary>
        /// <param name="model">model</param>
        public bool ModifyRecord(PManageDepartData model)
        {
            bool ret = false;
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update PManageDepart set ");
            strSql.Append("empId=@empId,");
            strSql.Append("roleId=@roleId,");
            strSql.Append("departId=@departId");
            strSql.Append(" where id = @id ");
            SqlParameter[] parameters = {
                    new SqlParameter("@id", SqlDbType.Int),
                    new SqlParameter("@empId", SqlDbType.Int),
                    new SqlParameter("@roleId", SqlDbType.Int),
                    new SqlParameter("@departId", SqlDbType.Int)
                };
            parameters[0].Value = model.id;
            parameters[1].Value = model.empId;
            parameters[2].Value = model.roleId;
            parameters[3].Value = model.departId;

            try
            {
                SqlHelper.ExecuteNonQuery(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters);
                ret = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return ret;
        }
コード例 #4
0
        /// <summary>
        /// �õ�һ��model
        /// </summary>
        /// <param name="id">����ֵ</param>
        /// <returns>model</returns>
        public PManageDepartData GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * from PManageDepart");
            strSql.Append(" where id = @id ");
            SqlParameter[] parameters = {
                    new SqlParameter("@id", SqlDbType.Int)
                };
            parameters[0].Value = id;

            PManageDepartData model = new PManageDepartData();
            DataSet ds = SqlHelper.ExecuteDataset(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                DataRow row = ds.Tables[0].Rows[0];
                if (row["id"] != DBNull.Value)
                {
                    model.id = Convert.ToInt32(row["id"]);
                }
                if (row["empId"] != DBNull.Value)
                {
                    model.empId = Convert.ToInt32(row["empId"]);
                }
                if (row["roleId"] != DBNull.Value)
                {
                    model.roleId = Convert.ToInt32(row["roleId"]);
                }
                if (row["departId"] != DBNull.Value)
                {
                    model.departId = Convert.ToInt32(row["departId"]);
                }
                return model;
            }
            else
            {
                return null;
            }
        }
コード例 #5
0
 /// <summary>
 /// ����һ������
 /// </summary>
 /// <param name="model">model</param>
 public bool ModifyRecord(PManageDepartData model)
 {
     return this.manageDepartDB.ModifyRecord(model);
 }
コード例 #6
0
        //*****************************************************************************
        //do it later      do it later      do it later
        //*****************************************************************************
        /// <summary>
        /// ���Ӷ���������
        /// </summary>
        /// <param name="empId"></param>
        /// <param name="roleId"></param>
        /// <param name="departIds"></param>
        public void AddRecord(int empId, int roleId, string departIds)
        {
            PManageDepartData model = new PManageDepartData();

            string[] rdepartIds = departIds.Split(',');
            foreach (string departId in rdepartIds)
            {
                model.empId = empId;
                model.roleId = roleId;
                model.departId = Convert.ToInt32(departId);
                this.manageDepartDB.AddRecord(model);
            }
        }
コード例 #7
0
 /// <summary>
 /// ����һ������
 /// </summary>
 /// <param name="model">model</param>
 public int AddRecord(PManageDepartData model)
 {
     return this.manageDepartDB.AddRecord(model);
 }
コード例 #8
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            this.BindList();
            if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
            {
                this.IdValue = Convert.ToInt32(Request.Params["id"]);
            }
            if (Request.Params["state"] != null && Request.Params["state"].Trim() != string.Empty)
            {
                this.State = Request.Params["state"].ToString();
                switch (this.State)
                {
                    case "1":   //add
                        this.btnConsultDept.Attributes.Add("onclick", "javascript:ConsultDepartment('departId','departNm','',1,3);");
                        break;
                    case "2":   //update
                        //���ؿؼ�
                        this.btnConsultDept.Attributes.Add("onclick", "javascript:ConsultDepartment('departId','departNm','',0,3);");

                        PManageDepartBB manageDepartBB = new PManageDepartBB();
                        PManageDepartData manageDepartData = new PManageDepartData();
                        try
                        {
                            manageDepartData = manageDepartBB.GetModel(this.IdValue);

                            this.ShowInfo(this.IdValue);
                        }
                        finally
                        {
                            manageDepartBB.Dispose();
                        }
                        break;
                    default:
                        break;
                }
            }
        }
    }
コード例 #9
0
 private void SetModel(ref PManageDepartData model)
 {
     if (this.empId.Value != "")
     {
         model.empId = Convert.ToInt32(this.empId.Value);
     }
     else
     {
         model.empId = 0;
     }
     if (this.roleId.SelectedValue != "")
     {
         model.roleId = Convert.ToInt32(this.roleId.SelectedValue);
     }
     else
     {
         model.roleId = 0;
     }
     if (this.departId.Value != "")
     {
         model.departId = Convert.ToInt32(this.departId.Value);
     }
     else
     {
         model.departId = 0;
     }
 }