Exemplo n.º 1
0
 public int deleteUser(User u)
 {
     try
     {
         conn.Open();
         u = this.getUser(u);
         string sql = @"DELETE FROM [Library].[dbo].[User]
       WHERE user_id = "+ u.User_id +" OR userName = '******'";
         sqlcom = new SqlCommand(sql, conn);
         sqlcom.ExecuteScalar();
         sql = @"DELETE FROM [Library].[dbo].[Link]
       WHERE user_id = " + u.User_id ;
         sqlcom = new SqlCommand(sql, conn);
         sqlcom.ExecuteScalar();
         return 1;
     }
     catch
     {
         return 0;
     }
     finally
     {
         conn.Close();
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 明細頁
        /// </summary>
        /// <param name="id">會員Id</param>
        /// <returns></returns>
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Library.User user = userWeb.GetUsers().Single(g => g.Id == id);

            if (user == null)
            {
                return(HttpNotFound());
            }

            if (user.UserClass == 1)
            {
                ViewBag.UserClass = "管理員";
            }
            else
            {
                ViewBag.UserClass = "一般";
            }

            if (SessionManagement.LoginUser != null && SessionManagement.LoginUser.UserClass == 2)
            {
                return(View(user));
            }
            else
            {
                return(RedirectToAction("Index", "Message"));
            }
        }
 public FileVersion(string filePath, int versionNumber, User owner)
 {
     FilePath = filePath;
     VersionNumber = versionNumber;
     TimeStamp = DateTime.Now;
     Owner = owner.Id;
 }
Exemplo n.º 4
0
        public ActionResult Edit([Bind(Include = "Id,UserAccount, UserClass, Email, Password, RePassword, UserName")] Library.User user)
        {
            user.Id = userWeb.GetUsers().Single(g => g.Id == user.Id).Id;

            if (!ModelState.IsValid)
            {
                return(View("Edit", user));
            }

            userWeb.SaveUser(user);

            byte UserClass = 0;

            if (Session["Id"] != null)
            {
                byte.TryParse(Session["UserClass"].ToString(), out UserClass);
            }
            if (UserClass == 2)
            {
                return(RedirectToAction("Index", "User"));
            }
            else
            {
                if (Session["Id"] != null)
                {
                    Session["UserName"] = user.UserName;
                }
                return(RedirectToAction("Index", "Message"));
            }
        }
Exemplo n.º 5
0
 public bool checkUserValidate(User u)
 {
     user = u;
     try
     {
         conn.Open();
         string sql = "SELECT [passWord] FROM [Library].[dbo].[User] where [userName]='" + user.UserName + "'";
         sqlcom = new SqlCommand(sql, conn);
         string pwd = sqlcom.ExecuteScalar().ToString();
         if (pwd == user.PassWord)
         {
             return true;
         }
         else
         {
             return false;
         }
     }
     catch
     {
         throw;
     }
     finally
     {
         conn.Close();
     }
 }
Exemplo n.º 6
0
        public ActionResult Create(Library.User user, string UserAccount)
        {
            UserWeb userWeb = new UserWeb();


            if (!ModelState.IsValid)
            {
                return(View("Create"));
            }

            bool isSuccess = userWeb.AddUser(user);

            if (isSuccess)
            {
                ViewBag.Msg = "帳號已註冊過";
                return(View());
            }
            else
            {
                byte UserClass = 0;

                if (Session["Id"] != null)
                {
                    byte.TryParse(Session["UserClass"].ToString(), out UserClass);
                }
                if (UserClass == 2)
                {
                    return(RedirectToAction("Index", "User"));
                }
                else
                {
                    return(RedirectToAction("Login", "User"));
                }
            }
        }
        public int AddFile(string fileName, string fileDesc, int projectid)
        {
            Project project = new Library.Project();
            project.Id = projectid;
            File file = new File(fileName, fileDesc, project);
            User owner = new Library.User(1);
            try
            {
                file.FileLock = 1;
                file.FileLockTime = DateTime.Now;
                file.VersionNr = 1;
                var option = new TransactionOptions();
                option.IsolationLevel = IsolationLevel.ReadCommitted;

                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, option))
                {
                    bool f = dbFile.AddFIle(file);
                    FileVersion fv = new FileVersion(file.Id.ToString(), file, file.VersionNr, owner);

                    bool version = dbFileVersion.AddFileVersion(fv);

                    if (version && f)
                        scope.Complete();
                }
                return file.Id;
            }
            catch (Exception e)
            {
                throw new Exception("File not added to DB " + e);
            }
        }
Exemplo n.º 8
0
 public CheckBookHadBorrow_Info(User u)
 {
     InitializeComponent();
     DataTable dt = new DataTable();
     dt = manager.selectBooksByUser(u);
     dataGridView1.DataSource = dt.DefaultView;
 }
 public FileVersion(int id, string filePath, int versionNumber, DateTime timeStamp, User owner)
 {
     Id = id;
     FilePath = filePath;
     VersionNumber = versionNumber;
     TimeStamp = timeStamp;
     Owner = owner.Id;
 }
Exemplo n.º 10
0
        /// <summary>
        /// Notifica al juez y le muestra su carta negra
        /// </summary>
        /// <returns></returns>
        private async void NotifyJudge()
        {
            SingletonBot bot = SingletonBot.Instance;

            Library.User judge     = (Library.User)bot.GetJudge();
            Card         cardBlack = bot.AskBlackCard();
            await Bot.SendTextMessageAsync(judge.ID, "Sos el juez");

            await Bot.SendTextMessageAsync(judge.ID, "Tu carta es " + cardBlack.ToString());
        }
Exemplo n.º 11
0
 public AddUserInfo(User u)
 {
     user = u;
     InitializeComponent();
     if (user.IsAdmin != "是")
     {
         label5.Hide();
         checkBox1.Hide();
     }
 }
 public Project(int id, string title, string description, string projectFolder, User projectAdministrator)
 {
     Id = id;
     Title = title;
     Description = description;
     ProjectFolder = projectFolder;
     //ProjectMembers = ProjectMembers;
     ProjectAdministrators = new List<User> {projectAdministrator};
     ProjectFiles = new List<File>();
 }
Exemplo n.º 13
0
        /// <summary>
        /// Notifica a todos los jugadores que empezó el juego.
        /// </summary>
        /// <returns></returns>
        private async void NotifyPlayer()
        {
            SingletonBot bot = SingletonBot.Instance;
            IEnumerator <Library.User> listUser = bot.GetListUser();

            while (listUser.MoveNext())
            {
                Library.User user = listUser.Current;
                await Bot.SendTextMessageAsync(user.ID, "Empieza el juego, espera que se repartan las cartas");
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Notifica la carta ganadora a los jugadores
        /// </summary>
        /// <param name="card"></param>
        /// <returns></returns>
        private async void notifyWin(Card card)
        {
            SingletonBot bot = SingletonBot.Instance;
            IEnumerator <Library.User> listUser = bot.GetListUser();

            while (listUser.MoveNext())
            {
                Library.User user = listUser.Current;
                await Bot.SendTextMessageAsync(user.ID, "El juez seleccionó esta carta :" + card);
            }
        }
Exemplo n.º 15
0
 public static User CreateUser(string firstName, string lastName, string birthDate, string phoneNumber, string email)
 {
     User user = new User();
     user.FirstName = firstName;
     user.LastName = lastName;
     user.BirthDate = birthDate;
     user.PhoneNumber = phoneNumber;
     user.Email = email;
     //user.Id = ;
     return user;
 }
Exemplo n.º 16
0
 public Main(User u)
 {
     user = u;
     InitializeComponent();
     label5.Text = user.UserName;
     userName = user.UserName;
     UserInfo userinfo = new UserInfo(user);
     userinfo.TopLevel = false;
     userinfo.FormBorderStyle = FormBorderStyle.None;
     Info.Controls.Add(userinfo);
     userinfo.Show();
 }
Exemplo n.º 17
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Library.User user = userWeb.GetUsers().Single(g => g.Id == id);
            if (user == null)
            {
                return(HttpNotFound());
            }
            return(View(user));
        }
Exemplo n.º 18
0
 public void holdIt(User u)
 {
     if (isAvailable && !isOnHold)
     {
         currentUser = u;
         isAvailable = false;
         isOnHold = false;
         checkOutTime = DateTime.Now;
         Console.WriteLine(ISBN + " is on hold for " + currentUser.UserName + " at " + checkOutTime);
     }
     else
     {
         Console.WriteLine("This item can not be put on hold");
     }
 }
Exemplo n.º 19
0
 public int borrowBook(User user, Book book)
 {
     try
     {
         int tp = bookDAO.BorrowBooks(user, book);
         user.HadBorrow++;
         user.CountBorrow++;
         userDAO.updateUser(user);
         book.Num--;
         bookDAO.updateBook(book);
         return tp;
     }
     catch
     {
         return 0;
     }
 }
Exemplo n.º 20
0
        /// <summary>
        /// Se muestra al juez las opciones de respuestas, y se le pide que seleccione la ganadora.
        /// </summary>
        /// <returns></returns>
        private async void NotifyJudge2()
        {
            SingletonBot       bot = SingletonBot.Instance;
            IEnumerator <Card> iteratorCardWhite = bot.AskEnumeratorCardsAnswer();
            int i = 1;

            Library.User judge = (Library.User)bot.GetJudge();
            await Bot.SendTextMessageAsync(judge.ID, "Selecciona la carta ganadora. Ejemplo: Opción 1");

            while (iteratorCardWhite.MoveNext())
            {
                Card card = iteratorCardWhite.Current;
                await Bot.SendTextMessageAsync(judge.ID, "Opcion " + i + ": " + card.ToString());

                i++;
            }

            await Bot.SendTextMessageAsync(judge.ID, "Seleccione una carta: ");
        }
 public List<int> AddMutiFiles(List<string> fileNames, List<string> fileDescs, Library.Project project)
 {
     List<int> ids = new List<int>();
     List<File> files = new List<File>();
     User owner = new Library.User(1);
     int i = 0;
     try
     {
         foreach (String fn in fileNames)
         {
             File file = new File(fn, fileDescs[i], project);
             file.FileLock = 1;
             file.FileLockTime = DateTime.Now;
             file.VersionNr = 1;
             files.Add(file);
             i++;
         }
         var option = new TransactionOptions();
         option.IsolationLevel = IsolationLevel.ReadCommitted;
         using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, option))
         {
             foreach (File f in files)
             {
                 bool af = dbFile.AddFIle(f);
                 FileVersion fv = new FileVersion(f.Id.ToString(), f, f.VersionNr, owner);
                 bool version = dbFileVersion.AddFileVersion(fv);
                 if (!af && !version)
                 {
                     scope.Dispose();
                     break;
                 }
                 ids.Add(f.Id);
             }
             scope.Complete();
         }
         return ids;
     }
     catch (Exception e)
     {
         throw new Exception("Files not added to DB: \n" + e);
     }
 }
Exemplo n.º 22
0
        public ActionResult Login(Library.User user, string UserAccount, string Password)
        {
            //驗證帳號和密碼
            User loginUser = userWeb.CheckPassword(UserAccount, Password);

            if (loginUser != null)
            {
                SessionManagement.LoginUser = loginUser;
                Session["UserAccount"]      = loginUser.UserAccount;
                Session["Id"]        = loginUser.Id;
                Session["UserClass"] = loginUser.UserClass;
                Session["UserName"]  = loginUser.UserName;
                return(RedirectToAction("Index", "Message"));
            }
            else
            {
                ViewBag.Msg = "帳號或密碼輸入錯誤...";
                return(View());
            }
        }
Exemplo n.º 23
0
 public EditUser(User u)
 {
     user = u;
     InitializeComponent();
     UserName.Text = user.UserName;
     PassWord.Text = user.PassWord;
     if (user.Sex.Equals(radioButton1.Text))
     {
         radioButton1.Checked = true;
     }
     else
     {
         radioButton2.Checked = true;
     }
     if (user.IsAdmin.Equals(checkBox1.Text))
     {
         checkBox1.Checked = true;
     }
     Age.Text = user.Age.ToString();
 }
Exemplo n.º 24
0
        public ActionResult Login(Library.User user, string UserAccount, string Password)
        {
            //驗證帳號和密碼
            if (userWeb.CheckPassword(UserAccount, Password))
            {
                Session["UserAccount"] = UserAccount;
                var users = userWeb.GetUsers().ToList()
                            .First(x => x.UserAccount == UserAccount);

                Session["Id"]        = users.Id;
                Session["UserClass"] = users.UserClass;
                Session["UserName"]  = users.UserName;

                return(RedirectToAction("Index", "Message"));
            }
            else
            {
                ViewBag.Msg = "帳號或密碼輸入錯誤...";
                return(View());
            }
        }
Exemplo n.º 25
0
 private void login(object sender, EventArgs e)
 {
     user.UserName = textBox1.Text;
     user.PassWord = textBox2.Text;
     if (!manager.CheckUserNameExists(user.UserName))
     {
         MessageBox.Show("用户名不存在!请重新输入!");
         return;
     }
     if (manager.CheckUserValidate(user))
     {
         user = manager.getUser(user);
         MessageBox.Show("登陆成功!");
         Main f2 = new Main(user);
         f2.Show();
         this.Hide();
     }
     else
     {
         MessageBox.Show("密码不正确!登录失败!");
     }
 }
Exemplo n.º 26
0
 public int BorrowBooks(User u, Book b)
 {
     try
     {
         conn.Open();
         DateTime date = new DateTime();
         date = System.DateTime.Now;
         DateTime returnDate = new DateTime();
         returnDate = date.AddMonths(2);
         string sql = @"INSERT INTO [Library].[dbo].[Link]
        ([user_id]
        ,[book_id]
        ,[borrowDate]
        ,[returnDate])
      VALUES
        ('" + u.User_id + @"'
        ,'" + b.Book_id + @"'
        ,'" + date + @"'
        ,'" + returnDate + "')";
         sqlcom = new SqlCommand(sql, conn);
         object tp = sqlcom.ExecuteScalar();
         if (tp == null)
         {
             return 0;
         }
         else
         {
             return 1;
         }
     }
     catch
     {
         throw;
     }
     finally
     {
         conn.Close();
     }
 }
Exemplo n.º 27
0
        public ActionResult Edit([Bind(Include = "Id,UserAccount, UserClass, Email, Password, RePassword, UserName")] Library.User user)
        {
            user.Id = userWeb.GetUsers().Single(g => g.Id == user.Id).Id;

            if (!ModelState.IsValid)
            {
                return(View("Edit", user));
            }
            userWeb.SaveUser(user);
            if (SessionManagement.LoginUser != null)
            {
                Session.Remove(SessionManagement.LoginUser.UserName);
                SessionManagement.LoginUser.UserName = user.UserName;
            }
            if (SessionManagement.LoginUser.UserClass == 2)
            {
                return(RedirectToAction("Index", "User"));
            }
            else
            {
                return(RedirectToAction("Index", "Message"));
            }
        }
Exemplo n.º 28
0
        /// <summary>
        /// 明細頁
        /// </summary>
        /// <param name="id">會員Id</param>
        /// <returns></returns>
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Library.User user = userWeb.GetUsers().Single(g => g.Id == id);

            if (user == null)
            {
                return(HttpNotFound());
            }

            if (user.UserClass == 1)
            {
                ViewBag.UserClass = "管理員";
            }
            else
            {
                ViewBag.UserClass = "一般";
            }

            byte UserClass = 0;

            if (Session["Id"] != null)
            {
                byte.TryParse(Session["UserClass"].ToString(), out UserClass);
            }
            if (UserClass == 2)
            {
                return(View(user));
            }
            else
            {
                return(RedirectToAction("Index", "Message"));
            }
        }
Exemplo n.º 29
0
 public bool checkBookHadBorrow(User user, Book book)
 {
     return bookDAO.CheckBookHadBorrow(user,book);
 }
Exemplo n.º 30
0
 public int addUser(User user)
 {
     return userDAO.insertUser(user);
 }
Exemplo n.º 31
0
 public int updateUser(User user)
 {
     return userDAO.updateUser(user);
 }
Exemplo n.º 32
0
 public DataTable selectBooksByUser(User user)
 {
     try
     {
         return bookDAO.getBookToDataSetByUser(user).Tables[0];
     }
     catch
     {
         DataTable dt = new DataTable();
         return dt;
     }
 }
Exemplo n.º 33
0
 public int returnBook(User user, Book book)
 {
     try
     {
         int tp = bookDAO.ReturnBooks(user, book);
         user.HadBorrow--;
         userDAO.updateUser(user);
         book.Num++;
         bookDAO.updateBook(book);
         return tp;
     }
     catch
     {
         return 0;
     }
 }
Exemplo n.º 34
0
        public void issue(User u)
        {
            if (isAvailable)
            {
                currentUser = u;
                checkOutTime = DateTime.Now;
                checkInTime = DateTime.MinValue;
                isAvailable = false;
                isOnHold = false;
                Console.WriteLine(ISBN + " is issued to " + currentUser.UserName + " at " + checkOutTime);

            }
            else
            {
                Console.WriteLine(ISBN + " is not available to check-out");
            }
        }
Exemplo n.º 35
0
        //string path = "C:/Users/Andrew/Desktop/new_cse445/445Proj5/Assignment 5/WebStore/users.txt";
        public bool addUser(User newUser)
        {
            // Load all users
            try
            {
                string users = File.ReadAllText(path);

                if (users.Contains(newUser.getUsername()))
                {
                    return false;
                }
                users = users + newUser.toString() + "\n";

                //File.WriteAllText(users, @path);

                System.IO.StreamWriter output = new System.IO.StreamWriter(@"C:\Users.txt");
                //System.IO.StreamWriter output = new System.IO.StreamWriter(@path);
                output.WriteLine(users);
                output.Close();
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.GetType());

            }

            return true;
        }
Exemplo n.º 36
0
 public bool CheckUserValidate(User user)
 {
     return userDAO.checkUserValidate(user);
 }
Exemplo n.º 37
0
        public void DeleteUser(object obj, RoutedEventArgs args)
        {
            int index = 0;
            index = dataGrid.SelectedIndex;
            if (index != -1)
            {
                User data = new User();
                data = (User)dataGrid.SelectedItem;
                Console.WriteLine(index);
                Console.WriteLine(data.FirstName + " " + data.LastName + " " + data.BirthDate + " " + data.PhoneNumber + " " + data.Email);

                ProgramData.data.users.Remove(ProgramData.data.users.Single(user => user.FirstName == data.FirstName && user.LastName == data.LastName && user.BirthDate == data.BirthDate && user.PhoneNumber == data.PhoneNumber && user.Email == data.Email));

            }
            else
            {
                Console.WriteLine("none");
            }

            Refresh(null, null);
        }
Exemplo n.º 38
0
 public AddBookInfo(User u)
 {
     InitializeComponent();
 }
Exemplo n.º 39
0
 public int deleteUser(User user)
 {
     return userDAO.deleteUser(user);
 }
Exemplo n.º 40
0
        public User getUser(string username)
        {
            CryptoService.Service proxy = new CryptoService.Service();

            try
            {
                string[] users = File.ReadAllLines(path);

                for (int i = 0; i < users.Length; i++)
                {
                    string[] fields = users[i].Split(' ');
                    if (fields.Length == 3 && fields[1] == username)
                    {
                        string decrPass = proxy.Decrypt(fields[2]);
                        User user = new User(Convert.ToInt32(fields[0]), fields[1], decrPass);
                        return user;
                    }

                }

            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }

            return null;
        }
Exemplo n.º 41
0
 public User getUser(User user)
 {
     return userDAO.getUser(user);
 }
 private void comboBox_Users_SelectedIndexChanged(object sender, EventArgs e)
 {
     string username = comboBox_Users.SelectedItem.ToString();
     activeUser = userService.FindUserByUsername(username).FirstOrDefault();
 }
Exemplo n.º 43
0
        /// <summary>
        /// Maneja los mensajes que se envían al bot.
        /// </summary>
        /// <param name="message">El mensaje recibido</param>
        /// <returns></returns>
        private async Task HandleMessageReceived(Message message)
        {
            Console.WriteLine($"Received a message from {message.From.FirstName} saying: {message.Text}");
            SingletonBot bot      = SingletonBot.Instance;
            string       response = "";
            string       comand   = Analysis(message.Text);

            switch (comand)
            {
            case "/start":
                response = "Bienvenid@ a Cards Against Programming! ¿Quieres jugar? Responde sí o no";
                break;

            case "no":
                response = "Te lo pierdes! Esperamos verte pronto.";
                break;

            case "si":
            case "sí":
                response = "Excelente! Responde cómo quieres llamarte seguido de la palabra alias. Ejemplo: alias Carmen.";
                break;

            case "alias":
                try{
                    string userName = message.Text.Split(" ")[1];
                    bot.CreatUser(userName, message.Chat.Id);
                    bool isStart = bot.StartGame();
                    response = "Bien " + userName + "! Se creó tu alias correctamente.";

                    if (isStart)
                    {
                        NotifyPlayer();
                        NotifyJudge();
                        userLast = bot.AskCurrentPlayer();
                        NotifyPlayerBlackCardAndWhiteCards();
                    }
                }catch (UserException e)
                {
                    response = e.Message;
                }

                catch (IndexOutOfRangeException)
                {
                    response = "Che, te dije alias separado con un espacio";
                }

                catch (Exception)
                {
                    response = "Sabes que, no tengo ni idea que paso";
                }
                break;

            case "opcion":
            case "opción":
                try
                {
                    Library.User judge  = (Library.User)bot.GetJudge();
                    int          number = Convert.ToInt32(message.Text.Split(" ")[1]) - 1;
                    if (number < 0 || number > 9)
                    {
                        response = "Debes elegir una opción del 1 al 10. Elemplo: Opción 1";
                    }
                    else
                    {
                        if (bot.isAskNextPlayer())
                        {
                            userLast = bot.GetUserActually();
                            Card cardSelect = userLast.GetCard(number);
                            bot.AddAnswer(cardSelect);
                            //Siguiente jugador, si hay muestro sus cartas y la pregunta
                            NotifyPlayerBlackCardAndWhiteCards();
                        }
                        else
                        {
                            if (message.Chat.Id != judge.ID)
                            {
                                Card cardSelect = userLast.GetCard(number);
                                Console.WriteLine(cardSelect);
                                bot.AddAnswer(cardSelect);
                                //Mostrar las cartas de respuesta de cada jugador
                                NotifyJudge2();
                            }
                            else             //Responde el juez
                            {
                                Card cardWin = bot.CardSelectWhite(number);
                                notifyWin(cardWin);
                                bot.AskWinner(cardWin);
                                NotifyJudge();
                                userLast = bot.GetUserActually();
                                NotifyPlayerBlackCardAndWhiteCards();
                            }
                        }
                    }
                }

                catch (FormatException)
                {
                    response = "Debes elegir un número del 1 al 10. Elemplo: Opción 1";
                }

                break;

            default:
                response = "Disculpa, no se qué hacer con ese mensaje!";
                break;
            }

            // enviamos el texto de respuesta
            await Bot.SendTextMessageAsync(message.Chat.Id, response);
        }