コード例 #1
0
ファイル: Teacher.cs プロジェクト: pyteach/Learnsite
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(LearnSite.Model.Teacher model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into Teacher(");
            strSql.Append("Hname,Hpwd,Hpermiss,Hnote,Hnick)");
            strSql.Append(" values (");
            strSql.Append("@Hname,@Hpwd,@Hpermiss,@Hnote,@Hnick)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Hname",    SqlDbType.NVarChar, 50),
                new SqlParameter("@Hpwd",     SqlDbType.NVarChar, 50),
                new SqlParameter("@Hpermiss", SqlDbType.Bit,       1),
                new SqlParameter("@Hnote",    SqlDbType.NText),
                new SqlParameter("@Hnick",    SqlDbType.NVarChar, 50)
            };
            parameters[0].Value = model.Hname;
            parameters[1].Value = model.Hpwd;
            parameters[2].Value = model.Hpermiss;
            parameters[3].Value = model.Hnote;
            parameters[4].Value = model.Hnick;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(1);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
コード例 #2
0
ファイル: Teacher.cs プロジェクト: pyteach/Learnsite
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(LearnSite.Model.Teacher model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Teacher set ");
            strSql.Append("Hname=@Hname,");
            strSql.Append("Hpwd=@Hpwd,");
            strSql.Append("Hpermiss=@Hpermiss,");
            strSql.Append("Hnote=@Hnote, ");
            strSql.Append("Hnick=@Hnick ");
            strSql.Append(" where Hid=@Hid ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Hid",      SqlDbType.Int,       4),
                new SqlParameter("@Hname",    SqlDbType.NVarChar, 50),
                new SqlParameter("@Hpwd",     SqlDbType.NVarChar, 50),
                new SqlParameter("@Hpermiss", SqlDbType.Bit,       1),
                new SqlParameter("@Hnote",    SqlDbType.NText),
                new SqlParameter("@Hnick",    SqlDbType.NVarChar, 50)
            };
            parameters[0].Value = model.Hid;
            parameters[1].Value = model.Hname;
            parameters[2].Value = model.Hpwd;
            parameters[3].Value = model.Hpermiss;
            parameters[4].Value = model.Hnote;
            parameters[5].Value = model.Hnick;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }
コード例 #3
0
        /// <summary>
        /// 设置管理员的cookies值
        /// </summary>
        /// <param name="Model"></param>
        private static bool SetManagerCookies(LearnSite.Model.Teacher tcmodel)
        {
            if (tcmodel != null)
            {
                HttpCookie MCookies = new HttpCookie(mngCookieNname);

                Model.MngCook mngcook = new Model.MngCook();
                mngcook.Hid      = tcmodel.Hid;
                mngcook.Hname    = UrlEncode(tcmodel.Hname);
                mngcook.Hnick    = UrlEncode(tcmodel.Hnick);
                mngcook.Hroom    = UrlEncode(tcmodel.Hroom);
                mngcook.Hpermiss = tcmodel.Hpermiss;
                mngcook.Ss       = mngCookieNname;
                HttpContext.Current.Session[mngCookieNname] = mngCookieNname;
                mngcook.SessionId = HttpContext.Current.Session.SessionID;

                MCookies.Value = mngcook.ToStr();

                MCookies.Expires  = DateTime.Now.AddDays(1);
                MCookies.Path     = "/";
                MCookies.HttpOnly = true;
                HttpContext.Current.Response.AppendCookie(MCookies);
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #4
0
 /// <summary>
 /// 根据权限设置教师或管理员cookies
 /// </summary>
 /// <param name="tcmodel"></param>
 /// <param name="permiss"></param>
 /// <returns></returns>
 public static bool SetTMCookies(LearnSite.Model.Teacher tcmodel, bool permiss)
 {
     if (permiss)
     {
         return(SetManagerCookies(tcmodel));
     }
     else
     {
         return(SetTeacherCookies(tcmodel));
     }
 }
コード例 #5
0
ファイル: Teacher.cs プロジェクト: pyteach/Learnsite
        /// <summary>
        /// 根据姓名和密码得到一个教师对象实体,如果不存在返回null
        /// </summary>
        public LearnSite.Model.Teacher GetTeacherModel(string Hname, string Hpwd)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 Hid,Hname,Hpwd,Hpermiss,Hnote,Hnick,Hroom from Teacher ");
            strSql.Append(" where Hname=@Hname and Hpwd=@Hpwd and Hdelete=0");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Hname", SqlDbType.NVarChar, 50),
                new SqlParameter("@Hpwd",  SqlDbType.NVarChar, 50)
            };
            parameters[0].Value = Hname;
            parameters[1].Value = Hpwd;

            LearnSite.Model.Teacher model = new LearnSite.Model.Teacher();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["Hid"].ToString() != "")
                {
                    model.Hid = int.Parse(ds.Tables[0].Rows[0]["Hid"].ToString());
                }
                model.Hname = ds.Tables[0].Rows[0]["Hname"].ToString();
                model.Hpwd  = ds.Tables[0].Rows[0]["Hpwd"].ToString();
                if (ds.Tables[0].Rows[0]["Hpermiss"].ToString() != "")
                {
                    if ((ds.Tables[0].Rows[0]["Hpermiss"].ToString() == "1") || (ds.Tables[0].Rows[0]["Hpermiss"].ToString().ToLower() == "true"))
                    {
                        model.Hpermiss = true;
                    }
                    else
                    {
                        model.Hpermiss = false;
                    }
                }
                model.Hnote = ds.Tables[0].Rows[0]["Hnote"].ToString();
                model.Hnick = ds.Tables[0].Rows[0]["Hnick"].ToString();
                model.Hroom = ds.Tables[0].Rows[0]["Hroom"].ToString();
                return(model);
            }
            else
            {
                return(null);
            }
        }
コード例 #6
0
        /// <summary>
        /// 设置管理员的cookies值
        /// </summary>
        /// <param name="Model"></param>
        private static bool SetManagerCookies(LearnSite.Model.Teacher tcmodel)
        {
            if (tcmodel != null)
            {
                HttpCookie TCookies = new HttpCookie(mngCookieNname);
                TCookies.Values.Add("Hid", tcmodel.Hid.ToString());
                TCookies.Values.Add("Hname", UrlEncode(tcmodel.Hname));
                TCookies.Values.Add("Hnick", UrlEncode(tcmodel.Hnick));
                TCookies.Values.Add("Hroom", UrlEncode(tcmodel.Hroom));
                TCookies.Values.Add("Hpermiss", tcmodel.Hpermiss.ToString());
                TCookies.Values.Add("Hs", Common.WordProcess.GetMD5(tcmodel.Hid.ToString()));

                TCookies.Expires  = DateTime.Now.AddDays(1);
                TCookies.Path     = "/";
                TCookies.HttpOnly = true;
                HttpContext.Current.Response.AppendCookie(TCookies);
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #7
0
ファイル: Teacher.cs プロジェクト: dalinhuang/learnsite
        /// <summary>
        /// ��������������õ�һ����ʦ����ʵ�壬��������ڷ���null
        /// </summary>
        public LearnSite.Model.Teacher GetTeacherModel(string Hname,string Hpwd)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 Hid,Hname,Hpwd,Hpermiss,Hnote from Teacher ");
            strSql.Append(" where Hname=@Hname and Hpwd=@Hpwd ");
            SqlParameter[] parameters = {
                    new SqlParameter("@Hname", SqlDbType.NVarChar,50),
                    new SqlParameter("@Hpwd", SqlDbType.NVarChar,50)};
            parameters[0].Value = Hname;
            parameters[1].Value = Hpwd;

            LearnSite.Model.Teacher model = new LearnSite.Model.Teacher();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["Hid"].ToString() != "")
                {
                    model.Hid = int.Parse(ds.Tables[0].Rows[0]["Hid"].ToString());
                }
                model.Hname = ds.Tables[0].Rows[0]["Hname"].ToString();
                model.Hpwd = ds.Tables[0].Rows[0]["Hpwd"].ToString();
                if (ds.Tables[0].Rows[0]["Hpermiss"].ToString() != "")
                {
                    if ((ds.Tables[0].Rows[0]["Hpermiss"].ToString() == "1") || (ds.Tables[0].Rows[0]["Hpermiss"].ToString().ToLower() == "true"))
                    {
                        model.Hpermiss = true;
                    }
                    else
                    {
                        model.Hpermiss = false;
                    }
                }
                model.Hnote = ds.Tables[0].Rows[0]["Hnote"].ToString();
                return model;
            }
            else
            {
                return null;
            }
        }