private static Tab_CourseTest_Question ToModel(DataRow row)
        {
            Tab_CourseTest_Question model = new Tab_CourseTest_Question();

            model.Idx = row.IsNull("Idx")?null:(System.Int32?)row["Idx"];
            model.CourseMainIdx_Fx = row.IsNull("CourseMainIdx_Fx")?null:(System.Int32?)row["CourseMainIdx_Fx"];
            model.QuestionText     = row.IsNull("QuestionText")?null:(System.String)row["QuestionText"];
            model.Aquestion        = row.IsNull("Aquestion")?null:(System.String)row["Aquestion"];
            model.Bquestion        = row.IsNull("Bquestion")?null:(System.String)row["Bquestion"];
            model.Cquestion        = row.IsNull("Cquestion")?null:(System.String)row["Cquestion"];
            model.Dquestion        = row.IsNull("Dquestion")?null:(System.String)row["Dquestion"];
            model.Answer           = row.IsNull("Answer")?null:(System.String)row["Answer"];
            return(model);
        }
        public int AddNew(Tab_CourseTest_Question model)
        {
            string sql = "insert into Tab_CourseTest_Question(CourseMainIdx_Fx,QuestionText,Aquestion,Bquestion,Cquestion,Dquestion,Answer)  values(@CourseMainIdx_Fx,@QuestionText,@Aquestion,@Bquestion,@Cquestion,@Dquestion,@Answer); select @@identity ;";
            int    Idx = Convert.ToInt32(SqlHelper.ExecuteScalar(CommandType.Text, sql
                                                                 , new SqlParameter("@CourseMainIdx_Fx", model.CourseMainIdx_Fx)
                                                                 , new SqlParameter("@QuestionText", model.QuestionText)
                                                                 , new SqlParameter("@Aquestion", model.Aquestion)
                                                                 , new SqlParameter("@Bquestion", model.Bquestion)
                                                                 , new SqlParameter("@Cquestion", model.Cquestion)
                                                                 , new SqlParameter("@Dquestion", model.Dquestion)
                                                                 , new SqlParameter("@Answer", model.Answer)
                                                                 ));

            return(Idx);
        }
        public bool Update(Tab_CourseTest_Question model)
        {
            string sql  = "update Tab_CourseTest_Question set CourseMainIdx_Fx=@CourseMainIdx_Fx,QuestionText=@QuestionText,Aquestion=@Aquestion,Bquestion=@Bquestion,Cquestion=@Cquestion,Dquestion=@Dquestion,Answer=@Answer where Idx=@Idx";
            int    rows = SqlHelper.ExecuteNonQuery(CommandType.Text, sql
                                                    , new SqlParameter("@CourseMainIdx_Fx", model.CourseMainIdx_Fx)
                                                    , new SqlParameter("@QuestionText", model.QuestionText)
                                                    , new SqlParameter("@Aquestion", model.Aquestion)
                                                    , new SqlParameter("@Bquestion", model.Bquestion)
                                                    , new SqlParameter("@Cquestion", model.Cquestion)
                                                    , new SqlParameter("@Dquestion", model.Dquestion)
                                                    , new SqlParameter("@Answer", model.Answer)
                                                    , new SqlParameter("Idx", model.Idx)
                                                    );

            return(rows > 0);
        }
        public Tab_CourseTest_Question Get(string Idx)
        {
            DataTable dt = SqlHelper.ExecuteDataset(CommandType.Text, "select * from Tab_CourseTest_Question  where Idx=@Idx",
                                                    new SqlParameter("Idx", Idx)).Tables[0];

            if (dt.Rows.Count > 1)
            {
                throw new Exception("more than 1 row was found");
            }

            if (dt.Rows.Count <= 0)
            {
                return(null);
            }

            DataRow row = dt.Rows[0];
            Tab_CourseTest_Question model = ToModel(row);

            return(model);
        }