/// <summary>
        /// ����һ������
        /// </summary>
        /// <param name="model">model</param>
        public int AddRecord(HOrgnizationData model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("set nocount on; ");
            strSql.Append("insert into HOrgnization(");
            strSql.Append("departNo,departNm,uppDepartId,departLeader,isEffect,isDel,isrtDt,isrtEmpId,updtDt,updtEmpId,mark)");
            strSql.Append(" values (");
            strSql.Append("@departNo,@departNm,@uppDepartId,@departLeader,@isEffect,@isDel,@isrtDt,@isrtEmpId,@updtDt,@updtEmpId,@mark)");
            strSql.Append("; select @@identity; set nocount off; ");
            SqlParameter[] parameters = {
                    new SqlParameter("@departNo", SqlDbType.NVarChar,10),
                    new SqlParameter("@departNm", SqlDbType.NVarChar,50),
                    new SqlParameter("@uppDepartId", SqlDbType.Int),
                    new SqlParameter("@departLeader", SqlDbType.Int),
                    new SqlParameter("@isEffect", SqlDbType.Bit),
                    new SqlParameter("@isDel", SqlDbType.Bit),
                    new SqlParameter("@isrtDt", SqlDbType.DateTime),
                    new SqlParameter("@isrtEmpId", SqlDbType.Int),
                    new SqlParameter("@updtDt", SqlDbType.DateTime),
                    new SqlParameter("@updtEmpId", SqlDbType.Int),
                    new SqlParameter("@mark", SqlDbType.NVarChar,500)
                };
            parameters[0].Value = model.departNo;
            parameters[1].Value = model.departNm;
            parameters[2].Value = model.uppDepartId;
            parameters[3].Value = model.departLeader;
            parameters[4].Value = model.isEffect;
            parameters[5].Value = model.isDel;
            parameters[6].Value = model.isrtDt == string.Empty ? null : model.isrtDt;
            parameters[7].Value = model.isrtEmpId;
            parameters[8].Value = model.updtDt == string.Empty ? null : model.updtDt;
            parameters[9].Value = model.updtEmpId;
            parameters[10].Value = model.mark;

            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;
        }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        HOrgnizationData model = new HOrgnizationData();
        HOrgnizationBB orgnizationBB = new HOrgnizationBB();
        try
        {
            if (this.State == "1")
            {
                this.SetModel(ref model);
                model.departNo = "";
                model.isrtDt = DateTime.Now.ToString();
                model.isrtEmpId = this.currentUser.empId;
                model.isDel = false;
                this.IdValue = orgnizationBB.AddRecord(model);
            }
            else if (this.State == "2")
            {
                model = orgnizationBB.GetModel(this.IdValue);
                this.SetModel(ref model);
                model.updtDt = DateTime.Now.ToString();
                model.updtEmpId = this.currentUser.empId;
                orgnizationBB.ModifyRecord(model);
            }
        }
        catch (Exception ex)
        {
            this.ClientScript.RegisterStartupScript(this.GetType(), "ShowErr", "ShowErr(\"" + Server.UrlEncode(ex.Message) + "\",3);", true);
            return;
        }
        finally
        {
            orgnizationBB.Dispose();
        }

        Response.Redirect("HOrgnizationList.aspx?itemNo=" + this.itemNo + "&pTypeNo=main", false);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            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
                        break;
                    case "2":   //update
                        //���ؿؼ�
                        HOrgnizationBB orgnizationBB = new HOrgnizationBB();
                        HOrgnizationData orgnizationData = new HOrgnizationData();
                        try
                        {
                            orgnizationData = orgnizationBB.GetModel(this.IdValue);

                            this.ShowInfo(this.IdValue);
                        }
                        finally
                        {
                            orgnizationBB.Dispose();
                        }
                        break;
                    default:
                        break;
                }
            }
        }
    }
 private void SetModel(ref HOrgnizationData model)
 {
     model.departNo = this.departNo.Text;
     model.departNm = this.departNm.Text;
     if (this.uppDepartId.Value != "")
     {
         model.uppDepartId = Convert.ToInt32(this.uppDepartId.Value);
     }
     else
     {
         model.uppDepartId = 0;
     }
     if (this.departLeader.Value != "")
     {
         model.departLeader = Convert.ToInt32(this.departLeader.Value);
     }
     else
     {
         model.departLeader = 0;
     }
     model.isEffect = this.isEffect.Checked;
     model.mark = this.mark.Text;
 }
        //*****************************************************************************
        //do it later      do it later      do it later
        //*****************************************************************************
        /// <summary>
        /// �����ϼ����Ż�ȡ�����������±���
        /// </summary>
        /// <param name="uppDepartId">�ϼ�����Id</param>
        /// <returns></returns>
        public string GetNewDepartNo(int uppDepartId)
        {
            string uppDepartNo = "";
            if (uppDepartId != 0)
            {
                HOrgnizationData orgnizationData = new HOrgnizationData();
                orgnizationData = this.GetModel(uppDepartId);
                uppDepartNo = orgnizationData.departNo;
            }

            string newDepartNo = "";
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select max(departNo) as maxDepartNo from HOrgnization");
            strSql.Append(" where isnull(uppDepartId,0) = @uppDepartId");
            if (uppDepartId != 0)
            {
                strSql.Append(" and departNo like '" + uppDepartNo + "%'");
            }

            SqlParameter[] parameters = {
                    new SqlParameter("@uppDepartId", SqlDbType.Int)
                };
            parameters[0].Value = uppDepartId;

            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["maxDepartNo"] != DBNull.Value)
                {
                    string maxDepartNo = row["maxDepartNo"].ToString().Substring(uppDepartNo.Length);
                    newDepartNo = (Convert.ToInt32(maxDepartNo) + 1).ToString("00");
                }
                else
                {
                    newDepartNo = "01";
                }
            }
            else
            {
                newDepartNo = "01";
            }
            //��Ϊ��ϵͳȨ�޿�����ʹ�ò��ű���������Ȩ�޿��ƣ����������˲��ű�����Ͻ���Ҫ�󣬱�����ϱ�׼xx��λ�����ʽ
            if (newDepartNo.Length > 2)
                throw new Exception("���ű��볬����λ���ƣ�����ϵϵͳ����Ա���������ű������");
            newDepartNo = uppDepartNo + newDepartNo;

            return newDepartNo;
        }
        /// <summary>
        /// ����һ������
        /// </summary>
        /// <param name="model">model</param>
        public bool ModifyRecord(HOrgnizationData model)
        {
            bool ret = false;
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update HOrgnization set ");
            strSql.Append("departNo=@departNo,");
            strSql.Append("departNm=@departNm,");
            strSql.Append("uppDepartId=@uppDepartId,");
            strSql.Append("departLeader=@departLeader,");
            strSql.Append("isEffect=@isEffect,");
            strSql.Append("isDel=@isDel,");
            strSql.Append("isrtDt=@isrtDt,");
            strSql.Append("isrtEmpId=@isrtEmpId,");
            strSql.Append("updtDt=@updtDt,");
            strSql.Append("updtEmpId=@updtEmpId,");
            strSql.Append("mark=@mark");
            strSql.Append(" where departId = @departId ");
            SqlParameter[] parameters = {
                    new SqlParameter("@departId", SqlDbType.Int),
                    new SqlParameter("@departNo", SqlDbType.NVarChar,10),
                    new SqlParameter("@departNm", SqlDbType.NVarChar,50),
                    new SqlParameter("@uppDepartId", SqlDbType.Int),
                    new SqlParameter("@departLeader", SqlDbType.Int),
                    new SqlParameter("@isEffect", SqlDbType.Bit),
                    new SqlParameter("@isDel", SqlDbType.Bit),
                    new SqlParameter("@isrtDt", SqlDbType.DateTime),
                    new SqlParameter("@isrtEmpId", SqlDbType.Int),
                    new SqlParameter("@updtDt", SqlDbType.DateTime),
                    new SqlParameter("@updtEmpId", SqlDbType.Int),
                    new SqlParameter("@mark", SqlDbType.NVarChar,500)
                };
            parameters[0].Value = model.departId;
            parameters[1].Value = model.departNo;
            parameters[2].Value = model.departNm;
            parameters[3].Value = model.uppDepartId;
            parameters[4].Value = model.departLeader;
            parameters[5].Value = model.isEffect;
            parameters[6].Value = model.isDel;
            parameters[7].Value = model.isrtDt == string.Empty ? null : model.isrtDt;
            parameters[8].Value = model.isrtEmpId;
            parameters[9].Value = model.updtDt == string.Empty ? null : model.updtDt;
            parameters[10].Value = model.updtEmpId;
            parameters[11].Value = model.mark;

            try
            {
                SqlHelper.ExecuteNonQuery(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters);
                ret = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return ret;
        }
        /// <summary>
        /// �õ�һ��model
        /// </summary>
        /// <param name="departId">����ֵ</param>
        /// <returns>model</returns>
        public HOrgnizationData GetModel(int departId)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select departId,departNo,departNm,uppDepartId,departLeader,isEffect,isDel,isrtDt,isrtEmpId,updtDt,updtEmpId,mark from HOrgnization");
            strSql.Append(" where departId = @departId ");
            SqlParameter[] parameters = {
                    new SqlParameter("@departId", SqlDbType.Int)
                };
            parameters[0].Value = departId;

            HOrgnizationData model = new HOrgnizationData();
            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["departId"] != DBNull.Value)
                {
                    model.departId = Convert.ToInt32(row["departId"]);
                }
                if (row["departNo"] != DBNull.Value)
                {
                    model.departNo = Convert.ToString(row["departNo"]);
                }
                if (row["departNm"] != DBNull.Value)
                {
                    model.departNm = Convert.ToString(row["departNm"]);
                }
                if (row["uppDepartId"] != DBNull.Value)
                {
                    model.uppDepartId = Convert.ToInt32(row["uppDepartId"]);
                }
                if (row["departLeader"] != DBNull.Value)
                {
                    model.departLeader = Convert.ToInt32(row["departLeader"]);
                }
                if (row["isEffect"] != DBNull.Value)
                {
                    model.isEffect = Convert.ToBoolean(row["isEffect"]);
                }
                if (row["isDel"] != DBNull.Value)
                {
                    model.isDel = Convert.ToBoolean(row["isDel"]);
                }
                if (row["isrtDt"] != DBNull.Value)
                {
                    model.isrtDt = Convert.ToString(row["isrtDt"]);
                }
                if (row["isrtEmpId"] != DBNull.Value)
                {
                    model.isrtEmpId = Convert.ToInt32(row["isrtEmpId"]);
                }
                if (row["updtDt"] != DBNull.Value)
                {
                    model.updtDt = Convert.ToString(row["updtDt"]);
                }
                if (row["updtEmpId"] != DBNull.Value)
                {
                    model.updtEmpId = Convert.ToInt32(row["updtEmpId"]);
                }
                if (row["mark"] != DBNull.Value)
                {
                    model.mark = Convert.ToString(row["mark"]);
                }
                return model;
            }
            else
            {
                return null;
            }
        }
Beispiel #8
0
 /// <summary>
 /// 获得当前部门
 /// </summary>
 /// <returns></returns>
 public HOrgnizationData GetCurrentDept()
 {
     HOrgnizationData departData = null;
     if (this.currentUser.nowDepartId != 0)
     {
         int departId = this.currentUser.nowDepartId;
         HOrgnizationBB departBB = new HOrgnizationBB();
         try
         {
             departData = departBB.GetModel(departId);
         }
         finally
         {
             departBB.Dispose();
         }
     }
     if (null == departData)
     {
         departData = new HOrgnizationData();
     }
     return departData;
 }
    /// <summary>
    /// ɾ��
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnDel_Click(object sender, EventArgs e)
    {
        bool retChecked = false;
        HOrgnizationBB orgnizationBB = new HOrgnizationBB();
        try
        {
            //��ȡѡ�е�����Id
            foreach (GridViewRow gvrow in this.grid.Rows)
            {
                CheckBox chkId = (CheckBox)gvrow.FindControl("chkId");
                if (chkId.Checked == true)
                {
                    retChecked = true;
                    int id = int.Parse(chkId.ValidationGroup);
                    HOrgnizationData orgnizationData = new HOrgnizationData();
                    orgnizationData = orgnizationBB.GetModel(id);

                    orgnizationData.isDel = true;
                    orgnizationBB.ModifyRecord(orgnizationData);
                }
            }
        }
        catch (Exception ex)
        {
            this.ClientScript.RegisterStartupScript(this.GetType(), "ShowErr", "ShowErr(\"" + Server.UrlEncode(ex.Message) + "\",3);", true);
            return;
        }
        finally
        {
            orgnizationBB.Dispose();
        }

        if (retChecked)
        {
            this.BindGrid();
        }
    }
        /// <summary>
        /// ����һ������
        /// </summary>
        /// <param name="model">model</param>
        public bool ModifyRecord(HOrgnizationData model)
        {
            //����ϼ����Ÿı䣬��ӱ������������в��ŵIJ��ű�����������
            if (model.uppDepartId != 0)
            {
                HOrgnizationData oldModel = new HOrgnizationData();
                oldModel = this.GetModel(model.departId);

                if (oldModel.uppDepartId != model.uppDepartId)
                {
                    model.departNo = this.GetNewDepartNo(model.uppDepartId);

                    this.orgnizationDB.ModifyRecord(model);

                    this.UpdateChildrenDepartNo(model.departId);
                }
                else
                {
                    this.orgnizationDB.ModifyRecord(model);
                }
            }
            else
            {
                this.orgnizationDB.ModifyRecord(model);
            }

            return true;
        }
 /// <summary>
 /// ����һ������
 /// </summary>
 /// <param name="model">model</param>
 public int AddRecord(HOrgnizationData model)
 {
     //��ֵ���ű��
     model.departNo = this.GetNewDepartNo(model.uppDepartId);
     return this.orgnizationDB.AddRecord(model);
 }