Exemplo n.º 1
0
        public static bool CreateForm(OdbcDataReader reader, Room room)
        {
            int fCount = reader.FieldCount;
            for (int i = 0; i < fCount; i++)
            {
                string name = reader.GetName(i);

                // Map to DB field. Need to change if db changed
                switch (name) {
                    case "room_id": room._roomID = reader.GetInt32(i);
                                      break;
                    case "branch_id": room._branchID = reader.GetInt32(i);
                                      break;
                    case "name": room._name = reader.GetString(i);
                                      break;
                    case "seat_no": room._seatNo = reader.GetInt32(i);
                                      break;
                    case "img": room._img = reader.GetString(i);
                                      break;
                    case "description": room._description = reader.GetString(i);
                                      break;

                    // helper info
                    case "branch_name": room._branchName = reader.GetString(i);
                                      break;

                }
            }
            return reader.HasRows;
        }
Exemplo n.º 2
0
        public void DoEditRoom(string roomID)
        {
            DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC);
            theRoom = new Room();
            if (!theRoom.LoadFromDB(db, "room_id=" + roomID)) theRoom = null;

            branchList = Branch.LoadListFromDB(db, "");

            db.Close();
        }
Exemplo n.º 3
0
        protected void DoAddSubmitRoom()
        {
            try
            {
                Room r = new Room();

                // validate data
                r._name = Request["roomname"];
                r._branchID = Int32.Parse(Request["branch_id"]);
                r._seatNo = Int32.Parse(Request["seat_no"]);
                r._description = Request["description"];

                r._img = "noimg.jpg";
                if (portrait.PostedFile.FileName != "")
                {

                    string serverFileExt = Path.GetExtension(portrait.PostedFile.FileName);
                    Random rand = new Random((int)DateTime.Now.Ticks);
                    string fullpath = "";
                    string imgname = "";
                    do
                    {
                        string randomFName = rand.Next(Int32.MaxValue).ToString();
                        imgname = randomFName + serverFileExt;
                        fullpath = Config.PATH_APP_ROOT + "\\" + Config.URL_PIC_ROOM + "\\" + imgname;
                    } while (File.Exists(fullpath));

                    portrait.PostedFile.SaveAs(fullpath);
                    r._img = imgname;

                }

                // Save to DB
                DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC);
                db.Connect();
                r.AddToDB(db);
                db.Close();
            }
            catch (Exception err)
            {
                errorText = err.Message + err.StackTrace;
                Response.Redirect("RoomManage.aspx?actPage=add&errorText=ข้อมูลไม่ถูกต้อง โปรดตรวจสอบอีกครั้ง");
            }
        }
Exemplo n.º 4
0
        protected void DoDeleteRoom(string roomID)
        {
            Room t = new Room();
            t._roomID = Int32.Parse(roomID);

            DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC);
            db.Connect();
            t.DeleteToDB(db);
            db.Close();
        }
Exemplo n.º 5
0
 public static Room CreateForm(OdbcDataReader reader)
 {
     Room room = new Room();
     Room.CreateForm(reader, room);
     return room;
 }
Exemplo n.º 6
0
        public static Room[] LoadListFromDBCustom(DBManager db, string sqlAll)
        {
            OdbcDataReader reader = db.Query(sqlAll);
            LinkedList<Room> list = new LinkedList<Room>();
            while (reader.Read())
            {
                list.AddLast(Room.CreateForm(reader));
            }

            Room[] entities = new Room[list.Count];
            int i = 0;
            foreach (Room r in list)
            {
                entities[i++] = r;
            }
            return entities;
        }