예제 #1
0
파일: Sys_Duty.cs 프로젝트: HuSri/HoneyWell
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.Sys_Duty model)
        {
            StringBuilder strSql = new StringBuilder();
            StringBuilder str1   = new StringBuilder();

            //利用反射获得属性的所有公共属性
            PropertyInfo[]      pros  = model.GetType().GetProperties();
            List <SqlParameter> paras = new List <SqlParameter>();

            strSql.Append("update Sys_Duty set ");
            foreach (PropertyInfo pi in pros)
            {
                //如果不是主键则追加sql字符串
                if (!pi.Name.Equals("ID"))
                {
                    //判断属性值是否为空
                    if (pi.GetValue(model, null) != null)
                    {
                        str1.Append(pi.Name + "=@" + pi.Name + ",");                          //声明参数
                        paras.Add(new SqlParameter("@" + pi.Name, pi.GetValue(model, null))); //对参数赋值
                    }
                }
            }
            strSql.Append(str1.ToString().Trim(','));
            strSql.Append(" where ID=@ID ");
            paras.Add(new SqlParameter("@ID", model.ID));
            return(DbHelperSQL.ExecuteSql(strSql.ToString(), paras.ToArray()) > 0);
        }
예제 #2
0
파일: Sys_Duty.cs 프로젝트: HuSri/HoneyWell
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.Sys_Duty GetModel(int ID)
        {
            StringBuilder strSql = new StringBuilder();
            StringBuilder str1   = new StringBuilder();

            Model.Sys_Duty model = new Model.Sys_Duty();
            //利用反射获得属性的所有公共属性
            PropertyInfo[] pros = model.GetType().GetProperties();
            foreach (PropertyInfo p in pros)
            {
                str1.Append(p.Name + ",");//拼接字段
            }
            strSql.Append("select top 1 " + str1.ToString().Trim(','));
            strSql.Append(" from Sys_Duty");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ID", SqlDbType.Int, 4)
            };
            parameters[0].Value = ID;
            DataTable dt = DbHelperSQL.Query(strSql.ToString(), parameters).Tables[0];

            if (dt.Rows.Count > 0)
            {
                return(DataRowToModel(dt.Rows[0]));
            }
            else
            {
                return(null);
            }
        }
예제 #3
0
파일: Sys_Duty.cs 프로젝트: HuSri/HoneyWell
 /// <summary>
 /// 将对象转换实体
 /// </summary>
 public Model.Sys_Duty DataRowToModel(DataRow row)
 {
     Model.Sys_Duty model = new Model.Sys_Duty();
     if (row != null)
     {
         //利用反射获得属性的所有公共属性
         Type modelType = model.GetType();
         for (int i = 0; i < row.Table.Columns.Count; i++)
         {
             //查找实体是否存在列表相同的公共属性
             PropertyInfo proInfo = modelType.GetProperty(row.Table.Columns[i].ColumnName);
             if (proInfo != null && row[i] != DBNull.Value)
             {
                 proInfo.SetValue(model, row[i], null);//用索引值设置属性值
             }
         }
     }
     return(model);
 }
예제 #4
0
파일: Sys_Duty.cs 프로젝트: HuSri/HoneyWell
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.Sys_Duty model)
        {
            StringBuilder strSql = new StringBuilder();
            StringBuilder str1   = new StringBuilder(); //数据字段
            StringBuilder str2   = new StringBuilder(); //数据参数

            //利用反射获得属性的所有公共属性
            PropertyInfo[]      pros  = model.GetType().GetProperties();
            List <SqlParameter> paras = new List <SqlParameter>();

            strSql.Append("insert into  Sys_Duty(");
            foreach (PropertyInfo pi in pros)
            {
                //如果不是主键则追加sql字符串
                if (!pi.Name.Equals("ID"))
                {
                    //判断属性值是否为空
                    if (pi.GetValue(model, null) != null)
                    {
                        str1.Append(pi.Name + ",");                                           //拼接字段
                        str2.Append("@" + pi.Name + ",");                                     //声明参数
                        paras.Add(new SqlParameter("@" + pi.Name, pi.GetValue(model, null))); //对参数赋值
                    }
                }
            }
            strSql.Append(str1.ToString().Trim(','));
            strSql.Append(") values (");
            strSql.Append(str2.ToString().Trim(','));
            strSql.Append(") ");
            strSql.Append(";select @@IDENTITY;");
            object obj = DbHelperSQL.GetSingle(strSql.ToString(), paras.ToArray());

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
예제 #5
0
        /// <summary>
        /// 绑定单体对象
        /// </summary>
        void BindModel()
        {
            BLL.Sys_Duty   sys_BLL   = new BLL.Sys_Duty();
            Model.Sys_Duty sys_Model = sys_BLL.GetModel(PKID);
            DutyName    = sys_Model.DutyName;
            DutyDesc    = sys_Model.DutyDesc;
            MenuSetting = sys_Model.MenuSetting;

            string    txt_str = "<table width='100%' border='0' cellspacing='0' cellpadding='0'>";
            DataTable dt      = new HoneyWell.BLL.Sys_Menu().GetMenuTree("", " and MenuLevel=1 order by MenuOrder").Tables[0];

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                txt_str = txt_str + "<tr>";
                txt_str = txt_str + "<td width='10%' align='left' valign='top'>" + dt.Rows[i]["MenuNameC"].ToString() + ":</td>";
                DataTable dt1 = new HoneyWell.BLL.Sys_Menu().GetMenuTree("", " and ParentID=" + dt.Rows[i]["ID"].ToString() + " and MenuLevel=2 order by MenuOrder").Tables[0];
                txt_str = txt_str + "<td width='90%' align='left'>";
                txt_str = txt_str + "<table  border='0' cellspacing='0' cellpadding='0'>";
                txt_str = txt_str + "<tr>";
                for (int k = 0; k < dt1.Rows.Count; k++)
                {
                    string str_checked = "";
                    if (sys_Model.MenuSetting.ToString().Length > 0)
                    {
                        string[] S_MenuSetting = sys_Model.MenuSetting.ToString().Split(',');
                        for (int j = 0; j < S_MenuSetting.Length; j++)
                        {
                            if (S_MenuSetting[j] == dt1.Rows[k]["ID"].ToString())
                            {
                                str_checked = "checked='true'";
                            }
                        }
                    }

                    txt_str = txt_str + "<td align='left'>";
                    txt_str = txt_str + "&nbsp;&nbsp;<input type=\"checkbox\"  " + str_checked + " style=\"margin-bottom:7px;\"   onclick=\"checkJX(" + dt1.Rows[k]["Id"].ToString() + ");\" name='cb' id=\"cb_" + dt1.Rows[k]["Id"].ToString() + "\"  value='" + dt1.Rows[k]["Id"].ToString() + "' ></input>";
                    txt_str = txt_str + "&nbsp;" + dt1.Rows[k]["MenuNameC"].ToString() + "";

                    DataTable dt2 = new HoneyWell.BLL.Sys_Menu().GetMenuTree("", " and ParentID=" + dt1.Rows[k]["ID"].ToString() + " and MenuLevel=3 order by MenuOrder").Tables[0];
                    if (dt2 != null && dt2.Rows.Count > 0)
                    {
                        txt_str = txt_str + ":<br>";
                        for (int g = 0; g < dt2.Rows.Count; g++)
                        {
                            string str_checked1 = "";
                            if (sys_Model.MenuSetting.ToString().Length > 0)
                            {
                                string[] S_MenuSetting1 = sys_Model.MenuSetting.ToString().Split(',');
                                for (int m = 0; m < S_MenuSetting1.Length; m++)
                                {
                                    if (S_MenuSetting1[m] == dt2.Rows[g]["ID"].ToString())
                                    {
                                        str_checked1 = "checked='true'";
                                    }
                                }
                            }

                            txt_str = txt_str + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=\"checkbox\"  " + str_checked1 + " style=\"margin-bottom:7px;\"   onclick=\"checkJX(" + dt2.Rows[g]["Id"].ToString() + ");\" name='cb' id=\"cb_" + dt2.Rows[g]["Id"].ToString() + "\"  value='" + dt2.Rows[g]["Id"].ToString() + "' ></input>";
                            txt_str = txt_str + "&nbsp;" + dt2.Rows[g]["MenuNameC"].ToString() + "";
                        }
                    }


                    txt_str = txt_str + "</td>";

                    if (k == 5 || k == 11 || k == 17)
                    {
                        txt_str = txt_str + "</tr><tr>";
                    }
                }
                txt_str = txt_str + "</table>";
                txt_str = txt_str + "</td>";
                txt_str = txt_str + "</tr>";
            }
            txt_str = txt_str + "</table>";
            sp_MenuSetting.InnerHtml = txt_str;
        }
예제 #6
0
        void Sys_Duty_Manage(HttpContext context)
        {
            #region 处理请求参数
            string Id   = context.Request["Id"];
            int    pkid = 0;
            if (!string.IsNullOrEmpty(Id))
            {
                pkid = Convert.ToInt32(Id);
            }
            string DutyName    = StringHelper.NullToStr(context.Request["DutyName"]);
            string DutyDesc    = StringHelper.NullToStr(context.Request["DutyDesc"]);
            string MenuSetting = StringHelper.NullToStr(context.Request["MenuSetting"]);
            #endregion



            string jsonRet = "";
            string retMsg  = "";

            UserInfo user = new UserInfo();

            if (pkid < 1)
            {
                #region 添加操作
                Model.Sys_Duty sys_Model = new Model.Sys_Duty();
                BLL.Sys_Duty   sys_BLL   = new BLL.Sys_Duty();
                sys_Model.DutyName    = DutyName;
                sys_Model.DutyDesc    = DutyDesc;
                sys_Model.MenuSetting = MenuSetting;
                sys_Model.CreateTime  = DateTime.Now.ToLocalTime();
                sys_Model.CreateUser  = user.GetUserName();
                sys_Model.ModifyTime  = DateTime.Now.ToLocalTime();
                sys_Model.ModifyUser  = user.GetUserName();
                sys_Model.MoreCol1    = "";
                sys_Model.MoreCol2    = "";
                int ret = sys_BLL.Add(sys_Model);
                if (ret > 0)
                {
                    retMsg  = "添加成功";
                    jsonRet = "{retMsg:\"" + retMsg + "\"}";
                }
                else
                {
                    retMsg  = "添加失败";
                    jsonRet = "{retMsg:\"" + retMsg + "\"}";
                }
                context.Response.Write(retMsg);
                context.Response.End();
                #endregion
            }
            else
            {
                #region 更新操作
                Model.Sys_Duty sys_Model = new BLL.Sys_Duty().GetModel(pkid);
                BLL.Sys_Duty   sys_BLL   = new BLL.Sys_Duty();
                sys_Model.ID          = pkid;
                sys_Model.DutyName    = DutyName;
                sys_Model.DutyDesc    = DutyDesc;
                sys_Model.MenuSetting = MenuSetting;
                sys_Model.ModifyTime  = DateTime.Now.ToLocalTime();
                sys_Model.ModifyUser  = user.GetUserName();
                sys_Model.MoreCol1    = "";
                sys_Model.MoreCol2    = "";

                bool ret = sys_BLL.Update(sys_Model);
                if (ret == true)
                {
                    retMsg  = "更新成功";
                    jsonRet = "{retMsg:\"" + retMsg + "\"}";
                }
                else
                {
                    retMsg  = "更新失败";
                    jsonRet = "{retMsg:\"" + retMsg + "\"}";
                }

                context.Response.Write(retMsg);
                context.Response.End();
                #endregion
            }
        }
예제 #7
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(Model.Sys_Duty model)
 {
     return(dal.Update(model));
 }
예제 #8
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int  Add(Model.Sys_Duty model)
 {
     return(dal.Add(model));
 }