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

            model.Idx               = row.IsNull("Idx")?null:(System.Int32?)row["Idx"];
            model.UserUIdx_Fx       = row.IsNull("UserUIdx_Fx")?null:(System.Int32?)row["UserUIdx_Fx"];
            model.ActivitiesIdx_Fx  = row.IsNull("ActivitiesIdx_Fx")?null:(System.Int32?)row["ActivitiesIdx_Fx"];
            model.DateOfApplication = row.IsNull("DateOfApplication")?null:(System.DateTime?)row["DateOfApplication"];
            model.ApprovalStatus    = row.IsNull("ApprovalStatus")?null:(System.String)row["ApprovalStatus"];
            return(model);
        }
        public int AddNew(Tab_Activity_Apply model)
        {
            string sql = "insert into Tab_Activity_Apply(UserUIdx_Fx,ActivitiesIdx_Fx,DateOfApplication,ApprovalStatus)  values(@UserUIdx_Fx,@ActivitiesIdx_Fx,@DateOfApplication,@ApprovalStatus); select @@identity ;";
            int    Idx = Convert.ToInt32(SqlHelper.ExecuteScalar(CommandType.Text, sql
                                                                 , new SqlParameter("@UserUIdx_Fx", model.UserUIdx_Fx)
                                                                 , new SqlParameter("@ActivitiesIdx_Fx", model.ActivitiesIdx_Fx)
                                                                 , new SqlParameter("@DateOfApplication", model.DateOfApplication)
                                                                 , new SqlParameter("@ApprovalStatus", model.ApprovalStatus)
                                                                 ));

            return(Idx);
        }
        public bool Update(Tab_Activity_Apply model)
        {
            string sql  = "update Tab_Activity_Apply set UserUIdx_Fx=@UserUIdx_Fx,ActivitiesIdx_Fx=@ActivitiesIdx_Fx,DateOfApplication=@DateOfApplication,ApprovalStatus=@ApprovalStatus where Idx=@Idx";
            int    rows = SqlHelper.ExecuteNonQuery(CommandType.Text, sql
                                                    , new SqlParameter("@UserUIdx_Fx", model.UserUIdx_Fx)
                                                    , new SqlParameter("@ActivitiesIdx_Fx", model.ActivitiesIdx_Fx)
                                                    , new SqlParameter("@DateOfApplication", model.DateOfApplication)
                                                    , new SqlParameter("@ApprovalStatus", model.ApprovalStatus)
                                                    , new SqlParameter("Idx", model.Idx)
                                                    );

            return(rows > 0);
        }
        public Tab_Activity_Apply Get(string Idx)
        {
            DataTable dt = SqlHelper.ExecuteDataset(CommandType.Text, "select * from Tab_Activity_Apply  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_Activity_Apply model = ToModel(row);

            return(model);
        }