public List<AchievementAssessment> CreatAchievementAssessment(AchievementAssessment sTemperatureData) { List<AchievementAssessment> returnValue = new List<AchievementAssessment>(); AchievementAssessment temp = new AchievementAssessment(); DataBase Base = new DataBase(); string strSql = ""; string strSqlPara = ""; foreach (System.Reflection.FieldInfo fldInfo in sTemperatureData.GetType().GetFields()) { switch (fldInfo.Name) { case "ID": case "Unit": // strSql += (string.IsNullOrEmpty(strSql) ? "" : ",") + fldInfo.Name + " = " + fldInfo.GetValue(sTemperatureData); break; case "CreateFileDate": case "UpFileDate": strSql += (string.IsNullOrEmpty(strSql) ? "" : ",") + fldInfo.Name; strSqlPara += (string.IsNullOrEmpty(strSqlPara) ? "" : ",") + "getdate() "; //cmd.Parameters.Add("@" + fldInfo.Name, SqlDbType.Date).Value = DateTime.Now.ToLongDateString(); break; default: strSql += (string.IsNullOrEmpty(strSql) ? "" : ",") + fldInfo.Name; strSqlPara += (string.IsNullOrEmpty(strSqlPara) ? "@" : ",@") + fldInfo.Name; break; } } using (SqlConnection Sqlconn = new SqlConnection(Base.GetConnString())) { try { StaffDataBase sDB = new StaffDataBase(); List<string> CreateFileName = sDB.getStaffDataName(HttpContext.Current.User.Identity.Name); Sqlconn.Open(); string sql = " insert into AchievementAssessment ( " + strSql + ")values(" + strSqlPara + ") "; sql += " select @@identity as id "; SqlCommand cmd = new SqlCommand(sql, Sqlconn); foreach (System.Reflection.FieldInfo fldInfo in sTemperatureData.GetType().GetFields()) { switch (fldInfo.Name) { case "ID": case "Unit": // strSql += (string.IsNullOrEmpty(strSql) ? "" : ",") + fldInfo.Name + " = " + fldInfo.GetValue(sTemperatureData); break; case "CreateFileBy": case "UpFileBy": //cmd.Parameters.Add("@" + fldInfo.Name, fldInfo.GetValue(sTemperatureData)); cmd.Parameters.Add("@" + fldInfo.Name, SqlDbType.Int).Value = Chk.CheckStringtoIntFunction(CreateFileName[0]); break; default: if (fldInfo.GetValue(sTemperatureData) != null) { cmd.Parameters.Add("@" + fldInfo.Name, fldInfo.GetValue(sTemperatureData).ToString()); } else { cmd.Parameters.Add("@" + fldInfo.Name, System.DBNull.Value); } break; } } SqlDataReader dr = cmd.ExecuteReader(); if (dr.Read()) { temp.ID = dr["id"].ToString(); } } catch (Exception e) { temp.ID = e.Message.ToString(); } Sqlconn.Close(); } //temp.ID = strSql; returnValue.Add(temp); return returnValue; }
public List<AchievementAssessmentLoad> ShowAchievementAssessment(int ID) { string strSql = ""; List<AchievementAssessmentLoad> returnvalue = new List<AchievementAssessmentLoad>(); AchievementAssessmentLoad temp = new AchievementAssessmentLoad(); AchievementAssessment sTemperatureData = new AchievementAssessment(); foreach (System.Reflection.FieldInfo fldInfo in sTemperatureData.GetType().GetFields()) { switch (fldInfo.Name) { case "ID": case "Unit": break; case "Intelligence_Date": case "AuditorySkills_Date": case "Vocabulary_Date": case "Vocabulary1_Date": case "Language1_Date": case "Language2_Date": case "Language3_Date": strSql += (string.IsNullOrEmpty(strSql) ? "" : ",") + "convert(varchar, isnull(convert(date, a." + fldInfo.Name + ",1),'1912'), 111) as " + fldInfo.Name; break; default: strSql += (string.IsNullOrEmpty(strSql) ? "" : ",") + "a." + fldInfo.Name; break; } } DataBase Base = new DataBase(); using (SqlConnection Sqlconn = new SqlConnection(Base.GetConnString())) { try { StaffDataBase sDB = new StaffDataBase(); Sqlconn.Open(); string sql = "select b.studentname , " + strSql + " from AchievementAssessment a left join studentDatabase b on a.studentid = b.id where a.ID=@ID and isnull(a.isDeleted,0) = 0 "; SqlCommand cmd = new SqlCommand(sql, Sqlconn); cmd.Parameters.Add("@ID", SqlDbType.Int).Value = ID; SqlDataReader dr = cmd.ExecuteReader(); if (dr.Read()) { temp.IDname = "studentName"; temp.ThisValue = dr["studentName"].ToString(); returnvalue.Add(temp); foreach (System.Reflection.FieldInfo fldInfo in sTemperatureData.GetType().GetFields()) { switch (fldInfo.Name) { case "ID": case "Unit": break; case "Intelligence_Date": case "AuditorySkills_Date": case "Vocabulary_Date": case "Vocabulary1_Date": case "Language1_Date": case "Language2_Date": case "Language3_Date": temp.IDname = fldInfo.Name; temp.ThisValue = Convert.ToDateTime(dr[fldInfo.Name].ToString()).AddYears(-1911).ToShortDateString().Remove(0, 1); returnvalue.Add(temp); break; default: string namee = fldInfo.Name; string namee2 = dr[fldInfo.Name].ToString(); temp.IDname = fldInfo.Name; temp.ThisValue = dr[fldInfo.Name].ToString(); returnvalue.Add(temp); break; } } } dr.Close(); Sqlconn.Close(); } catch (Exception e) { string error = e.Message; } } return returnvalue; }