コード例 #1
0
ファイル: Wall.aspx.cs プロジェクト: choufubin/CRUD_Demo
        public static int DeleteWall(string ID)
        {
            crudEntities dbEntities = new crudEntities();

            wall_main entWallMain = null;

            string sID = "";

            if (!string.IsNullOrEmpty(ID))
            {
                sID = ID;

                var q = dbEntities.wall_main.Where(m => m.id == sID);
                dbEntities.wall_main.RemoveRange(q);
                dbEntities.SaveChanges();

                return 0;

                //entWallMain = dbEntities.wall_main.FirstOrDefault(m => m.id == sID);
                //if (entWallMain != null)
                //{
                //    dbEntities.wall_main.Remove(entWallMain);
                //    dbEntities.SaveChanges();

                //    return 0;
                //}
                //else
                //    return -2;
            }
            else
                return -1;
        }
コード例 #2
0
ファイル: Wall.aspx.cs プロジェクト: choufubin/CRUD_Demo
        public static List<wall_main> QueryWall(string FilterDate)
        {
            crudEntities dbEntities = new crudEntities();

            List<wall_main> lsWallMain = null;
            string sFilterDate = "";

            if (!string.IsNullOrEmpty(FilterDate))
            {
                sFilterDate = FilterDate;

                lsWallMain = dbEntities.wall_main.Where(m => m.id.Substring(0, 8) == sFilterDate).OrderBy(m => m.datetime).ToList();

                return lsWallMain;
            }
            else
                return null;
        }
コード例 #3
0
ファイル: Wall.aspx.cs プロジェクト: choufubin/CRUD_Demo
        public static int CreateWall(string Subject, string Content)
        {
            crudEntities dbEntities = new crudEntities();

            try {
                wall_main entWallMain = new wall_main();

                entWallMain.id = System.DateTime.Now.ToString("yyyyMMddHHmmss");
                entWallMain.subject = Subject;
                entWallMain.content = Content;
                entWallMain.datetime = System.DateTime.Now;
                entWallMain.ipaddr = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString();

                dbEntities.wall_main.Add(entWallMain);
                dbEntities.SaveChanges();

                return 0;
            }
            catch(Exception ex)
            {
                return -1;
            }
        }
コード例 #4
0
ファイル: Wall.aspx.cs プロジェクト: choufubin/CRUD_Demo
        public static int UpdateWall(string ID, string Subject, string Content)
        {
            crudEntities dbEntities = new crudEntities();

            wall_main entWallMain = null;

            string sID = "";
            string sSubject = "";
            string sContent = "";

            if ((!string.IsNullOrEmpty(ID)) && (!string.IsNullOrEmpty(Subject)) && (!string.IsNullOrEmpty(Content)))
            {
                sID = ID;

                sSubject = Subject;
                sContent = Content;

                entWallMain = dbEntities.wall_main.FirstOrDefault(m => m.id == sID);

                if (entWallMain != null)
                {
                    entWallMain.subject = sSubject;
                    entWallMain.content = sContent;
                    entWallMain.datetime = System.DateTime.Now;
                    entWallMain.ipaddr = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString();

                    dbEntities.SaveChanges();

                    return 0;
                }
                else
                    return - 2;
            }
            else
                return -1;
        }