コード例 #1
0
ファイル: DHMS_Student.cs プロジェクト: WeiAiER/DHMS-M
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(DHMSClass.Model.DHMS_Student model)
        {
            StringBuilder strSql  = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();

            if (model.Student_Sno != null)
            {
                strSql1.Append("Student_Sno,");
                strSql2.Append("'" + model.Student_Sno + "',");
            }
            if (model.Student_Name != null)
            {
                strSql1.Append("Student_Name,");
                strSql2.Append("'" + model.Student_Name + "',");
            }
            if (model.Student_Sex != null)
            {
                strSql1.Append("Student_Sex,");
                strSql2.Append("'" + model.Student_Sex + "',");
            }
            if (model.Student_Birthday != null)
            {
                strSql1.Append("Student_Birthday,");
                strSql2.Append("'" + model.Student_Birthday + "',");
            }
            if (model.Student_Num != null)
            {
                strSql1.Append("Student_Num,");
                strSql2.Append("'" + model.Student_Num + "',");
            }
            if (model.Department_ID != null)
            {
                strSql1.Append("Department_ID,");
                strSql2.Append("'" + model.Department_ID + "',");
            }
            if (model.Class_ID != null)
            {
                strSql1.Append("Class_ID,");
                strSql2.Append("'" + model.Class_ID + "',");
            }
            strSql.Append("insert into DHMS_Student(");
            strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
            strSql.Append(")");
            strSql.Append(";select @@IDENTITY");
            object obj = DbHelperSQL.GetSingle(strSql.ToString());

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
コード例 #2
0
ファイル: DHMS_Student.cs プロジェクト: WeiAiER/DHMS-M
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(DHMSClass.Model.DHMS_Student model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update DHMS_Student set ");
            if (model.Student_Name != null)
            {
                strSql.Append("Student_Name='" + model.Student_Name + "',");
            }
            if (model.Student_Sex != null)
            {
                strSql.Append("Student_Sex='" + model.Student_Sex + "',");
            }
            if (model.Student_Birthday != null)
            {
                strSql.Append("Student_Birthday='" + model.Student_Birthday + "',");
            }
            if (model.Student_Num != null)
            {
                strSql.Append("Student_Num='" + model.Student_Num + "',");
            }
            if (model.Department_ID != null)
            {
                strSql.Append("Department_ID='" + model.Department_ID + "',");
            }
            if (model.Class_ID != null)
            {
                strSql.Append("Class_ID='" + model.Class_ID + "',");
            }
            int n = strSql.ToString().LastIndexOf(",");

            strSql.Remove(n, 1);
            strSql.Append(" where Student_ID=" + model.Student_ID + "");
            int rowsAffected = DbHelperSQL.ExecuteSql(strSql.ToString());

            if (rowsAffected > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #3
0
ファイル: DHMS_Student.cs プロジェクト: WeiAiER/DHMS-M
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public DHMSClass.Model.DHMS_Student GetModel(int Student_ID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1  ");
            strSql.Append(" Student_ID,Student_Sno,Student_Name,Student_Sex,Student_Birthday,Student_Num,Department_ID,Class_ID ");
            strSql.Append(" from DHMS_Student ");
            strSql.Append(" where Student_ID=" + Student_ID + "");
            DHMSClass.Model.DHMS_Student model = new DHMSClass.Model.DHMS_Student();
            DataSet ds = DbHelperSQL.Query(strSql.ToString());

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }
コード例 #4
0
ファイル: DHMS_Student.cs プロジェクト: WeiAiER/DHMS-M
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public DHMSClass.Model.DHMS_Student DataRowToModel(DataRow row)
 {
     DHMSClass.Model.DHMS_Student model = new DHMSClass.Model.DHMS_Student();
     if (row != null)
     {
         if (row["Student_ID"] != null && row["Student_ID"].ToString() != "")
         {
             model.Student_ID = int.Parse(row["Student_ID"].ToString());
         }
         if (row["Student_Sno"] != null)
         {
             model.Student_Sno = row["Student_Sno"].ToString();
         }
         if (row["Student_Name"] != null)
         {
             model.Student_Name = row["Student_Name"].ToString();
         }
         if (row["Student_Sex"] != null)
         {
             model.Student_Sex = row["Student_Sex"].ToString();
         }
         if (row["Student_Birthday"] != null && row["Student_Birthday"].ToString() != "")
         {
             model.Student_Birthday = DateTime.Parse(row["Student_Birthday"].ToString());
         }
         if (row["Student_Num"] != null)
         {
             model.Student_Num = row["Student_Num"].ToString();
         }
         if (row["Department_ID"] != null)
         {
             model.Department_ID = row["Department_ID"].ToString();
         }
         if (row["Class_ID"] != null)
         {
             model.Class_ID = row["Class_ID"].ToString();
         }
     }
     return(model);
 }