Ejemplo n.º 1
0
        public AdminStats()
        {
            InitializeComponent();
            database = new file_dataclassesDataContext();
            var get_users = from u in database.users
                            select new { u.u_id, u.login, u.first_name, u.last_name, u.email, u.join_date };
            UsersGridView1.DataSource = get_users;

            var get_actions = from a in database.actions
                              select new { a.a_id, a.u_id, a.act_type, a.action_time, a.fi_id };
            ActionGridView1.DataSource = get_actions;
        }
Ejemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            file_dataclassesDataContext database = new file_dataclassesDataContext();
               /* var log_data = from u in database.users
                           where u.login == textBox1.Text && u.password == textBox2.Text
                           select new { u.u_id };*/
            SqlConnection conn = new SqlConnection("Data Source=.\\SQLSRVR;AttachDbFilename=G:\\GitHub\\mmnote\\Data_base\\Data_base\\files_db.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");

            SqlDataReader log_data = null;
            var ex = 0;
            string quer = "select u_id from users where login = '******' and password = '******'";

            try
            {
                conn.Open();

                SqlCommand cmd = new SqlCommand(quer, conn);

                log_data = cmd.ExecuteReader();

                while(log_data.Read())
                {
                    ex++;
                    uid = (int)log_data[0];
                }

            }
            finally
            {
                if (conn != null) conn.Close();
            }

            if (ex == 0)
            {
                label3.Text = "Inncorect login or password!";
                return;
            }
            action log_act = new action
            {
                u_id = uid,
                act_type = "LOG",
                action_time = DateTime.Now
            };
            database.actions.InsertOnSubmit(log_act);
            database.SubmitChanges();
            Close();
        }
Ejemplo n.º 3
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != "")
            {

                var get_money = from m in pay_doc.Element("payments").Elements("userdata").Elements("u_paid")
                                where (string)m.Attribute("idp").Value == user_id.ToString()
                                select m;

                foreach (var m in get_money)
                {
                    money = Convert.ToInt32(m.Value);
                }

                money++;

                var inc = max_files + 5;
                max_files += 5;
                XElement ref_to_files =  pay_doc.Element("payments").Elements("userdata").Elements("u_files")
                                            .Where(id => (string)id.Attribute("idf").Value == user_id.ToString()).FirstOrDefault();

                ref_to_files.SetValue(inc.ToString());

                XElement ref_to_paid = pay_doc.Element("payments").Elements("userdata").Elements("u_paid")
                                            .Where(id => (string)id.Attribute("idp").Value == user_id.ToString()).FirstOrDefault();

                ref_to_paid.SetValue(money.ToString());

                pay_doc.Save("Payments.xml");
                file_dataclassesDataContext database = new file_dataclassesDataContext();
                action pay_act = new action
                {
                    u_id = user_id,
                    act_type = "PAY",
                    action_time = DateTime.Now
                };
                database.actions.InsertOnSubmit(pay_act);
                database.SubmitChanges();

                Close();
            }
            else
            {
                MessageBox.Show("Invalid code!", "Error");
                return;
            }
        }
Ejemplo n.º 4
0
        private void button1_Click(object sender, EventArgs e)
        {
            file_dataclassesDataContext database = new file_dataclassesDataContext();

            var if_exist = from u in database.users
                           where u.login == textBox1.Text
                           select new { u.u_id };
            var ex = 0;
            foreach (var u in if_exist)
            {
                ex++;

            }
            if (ex != 0)
            {
                statuslabel.Text = "This login is used!";
                return;
            }
            if (textBox2.Text != textBox3.Text)
            {
                statuslabel.Text = "Password boxes are not equal!";
                return;
            }
            using (var trans = new TransactionScope())
            {
                DateTime teraz = DateTime.Now;
                user register_new = new user
                {
                    login = textBox1.Text,
                    password = textBox2.Text,
                    first_name = textBox4.Text,
                    last_name = textBox5.Text,
                    email = textBox6.Text,
                    join_date = teraz
                };
                database.users.InsertOnSubmit(register_new);

                try
                {
                    database.SubmitChanges();
                }
                catch (Exception)
                {

                }
                var get_uid = from usr in database.users
                              where usr.login == textBox1.Text
                              select new { usr.u_id };

                foreach (var usr in get_uid)
                {
                    user_id = usr.u_id;
                }
                action reg_act = new action
                {
                    u_id = user_id,
                    act_type = "REG",
                    action_time = teraz
                };
                database.actions.InsertOnSubmit(reg_act);
                database.SubmitChanges();
                trans.Complete();
            }
            if (user_id != 0)
            {
                XDocument pay_doc = XDocument.Load("Payments.xml");

                pay_doc.Element("payments").Add(new XElement("userdata",
                                                                new XElement("u_files", "5", new XAttribute("idf", user_id.ToString()))));

                pay_doc.Element("payments").Elements("userdata").Elements("u_files")
                    .Where(u_f => u_f.Attribute("idf").Value == user_id.ToString()).FirstOrDefault()
                    .AddAfterSelf(new XElement("u_paid", "0", new XAttribute("idp", user_id.ToString())));
                pay_doc.Save("Payments.xml");
            }
            Close();
        }
Ejemplo n.º 5
0
 private void login_KeyPress(object sender, KeyPressEventArgs e)
 {
     if (e.KeyChar == (char)Keys.Enter)
     {
         file_dataclassesDataContext database = new file_dataclassesDataContext();
         var log_data = from u in database.users
                        where u.login == textBox1.Text && u.password == textBox2.Text
                        select new { u.u_id };
         var ex = 0;
         foreach (var u in log_data)
         {
             ex++;
             uid = u.u_id;
         }
         if (ex == 0)
         {
             label3.Text = "Inncorect login or password!";
             return;
         }
         action log_act = new action
         {
             u_id = uid,
             act_type = "LOG",
             action_time = DateTime.Now
         };
         database.actions.InsertOnSubmit(log_act);
         database.SubmitChanges();
         Close();
     }
 }
Ejemplo n.º 6
0
 private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
 {
     if (e.KeyChar == (char)Keys.Enter)
     {
         file_dataclassesDataContext database = new file_dataclassesDataContext();
         var log_data = from u in database.users
                        where u.login == textBox1.Text && u.password == textBox2.Text
                        select new { u.u_id };
         var ex = 0;
         foreach (var u in log_data)
         {
             ex++;
             uid = u.u_id;
         }
         if (ex == 0)
         {
             label3.Text = "Inncorect login or password!";
             return;
         }
         Close();
     }
 }
Ejemplo n.º 7
0
        public Form1()
        {
            InitializeComponent();
            database = new file_dataclassesDataContext();
            login log = new login();
            Application.Run(log);
            userid = log.uid;
            log.Dispose();
            if (userid == 0) { to_close = true; return; }

            var get_name = from u in database.users
                           where u.u_id == userid
                           select new { u.first_name, u.last_name };

            string fn = "";
            string ln = "";
            foreach (var u in get_name)
            {
                fn = u.first_name;
                ln = u.last_name;
            }

            this.Text
                = "FilesManager user: "******" " + ln;
               //LINQ to XML
               pay_doc = XDocument.Load("Payments.xml");
               var max_files = from fi in pay_doc.Elements("payments").Elements("userdata").Elements()
                           where (string)fi.Attribute("idf") == userid.ToString()
                           select fi;
               //max_files = max_files;

               foreach (var fi in max_files)
               {
               mf = Convert.ToInt32(fi.Value);
               }
            //ADO.NET code
            connect = new SqlConnection("Data Source=.\\SQLSRVR;AttachDbFilename=G:\\GitHub\\mmnote\\Data_base\\Data_base\\files_db.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");

            SqlDataReader get_files = null;

            try
            {
                connect.Open();

                string command_str = "select f_id, path, add_time from files where u_id = " + userid.ToString();

                SqlCommand gf = new SqlCommand(command_str, connect);

                get_files = gf.ExecuteReader();

                ArrayList elements = new ArrayList();

                while (get_files.Read())
                {
                    ToGridFiles fi = new ToGridFiles();
                    fi.ID = (int)get_files[0];
                    fi.Path = get_files[1].ToString();
                    fi.Time = (DateTime)get_files[2];
                    elements.Add(fi);
                    act_f++;
                }

                FilesGridView1.DataSource = elements;
                FilesGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);

            }
            finally
            {
                if (get_files != null) get_files.Close();
                if (connect != null) connect.Close();
            }

            //-------------------------

            //LINQ
            var get_friends = from fl in database.friends
                              where fl.u2_id == userid
                              select fl.u1_id;

            foreach (var fl in get_friends)
            {
                var to_list = from u in database.users
                              where u.u_id == fl
                              select u.login;
                foreach (var l in to_list)
                {
                    friendsListBox.Items.Add(l);
                }
            }
            var toFilesCounter = mf-act_f;
            FilesCounterLabel.Text = "Files left: " + toFilesCounter.ToString();
            get_xml_stats();

            List<Data_base.UserRegisterResult> reg_date = database.UserRegister(userid).ToList();

            foreach (var r in reg_date)
            {
                RegDateLabel.Text = "Registration of " + r.login.ToString() + ": " + r.join_date.ToString();
            }
            UpdateHistory();
            UserInfo();

            //dla admina
            if (userid == 1) button3.Visible = true;
        }