Exemple #1
0
        private void searchMembersButtonClick(object sender, EventArgs e)
        {
            try
            {
                sport.Close();
                SearchMembersForm p = new SearchMembersForm();
                p.ShowDialog();
                sport.Open();
            }
            catch (Exception ex)
            {
                List <Label> Labels = new List <Label>();
                Labels.Add(MyLabel.SetOKLabel("General Error"));
                Labels.Add(MyLabel.SetOKLabel(ex.Message));

                List <Button> Buttons = new List <Button>();
                Buttons.Add(MyButton.SetOKThemeButton());
                MyMessageBox.Show(
                    Labels,
                    "",
                    Buttons,
                    MyImage.SetFailed());
            }
        }
Exemple #2
0
        private void reportFormButtonClick(object sender, EventArgs e)
        {
            try
            {
                sport.Close();
                InformationForm ev = new InformationForm("0");
                ev.ShowDialog();
                sport.Open();
            }
            catch (Exception ex)
            {
                List <Label> Labels = new List <Label>();
                Labels.Add(MyLabel.SetOKLabel("General Error"));
                Labels.Add(MyLabel.SetOKLabel(ex.Message));

                List <Button> Buttons = new List <Button>();
                Buttons.Add(MyButton.SetOKThemeButton());
                MyMessageBox.Show(
                    Labels,
                    "",
                    Buttons,
                    MyImage.SetFailed());
            }
        }
Exemple #3
0
        private void GetMembers()
        {
            try
            {
                using (SqlConnection connection = new SqlConnection(
                           global::GymMembershipSystem.Properties.Settings.Default.GymMembershipSystemDatabase))
                {
                    using (SqlCommand cmd2 = new SqlCommand("SELECT id, Name, Surname, Address, PhoneNumber, CardId, TypeId," +
                                                            " NumOfEntrances, Gender, LastEntrance FROM Member", connection))
                    {
                        cmd2.CommandType = CommandType.Text;
                        connection.Open();
                        SqlDataReader dr = cmd2.ExecuteReader();
                        while (dr.Read())
                        {
                            long     id           = Convert.ToInt32(dr["id"]);
                            string   name         = dr["Name"].ToString();
                            string   surname      = dr["Surname"].ToString();
                            string   address      = dr["Address"].ToString();
                            string   phonenum     = dr["PhoneNumber"].ToString();
                            string   typeid       = dr["TypeId"].ToString();
                            int      numofentr    = Convert.ToInt32(dr["NumOfEntrances"]);
                            Int64    cardid       = Convert.ToInt64(dr["CardId"]);
                            DateTime lastEntrance = Convert.ToDateTime(dr["LastEntrance"]);
                            string   gender       = dr["Gender"].ToString();

                            DateTime expDate = method.GetExpirationDate(id);

                            PartialMember newMember = new PartialMember();

                            newMember.Name           = name;
                            newMember.Surname        = surname;
                            newMember.Address        = address;
                            newMember.PhoneNumber    = phonenum;
                            newMember.TypeId         = typeid;
                            newMember.NumOfEntrances = numofentr;
                            newMember.ExpirationDate = expDate;
                            newMember.CardId         = cardid;
                            newMember.LastEntrance   = lastEntrance;
                            newMember.Gender         = gender;
                            if (gender.Trim() == "Female")
                            {
                                female++;
                            }
                            else
                            {
                                male++;
                            }
                            newMember.id        = id;
                            newMember.NumOfDays = method.GetNumberOfEntrances(cardid.ToString());
                            members.Add(newMember);
                        }

                        label9.Text  = members.Count.ToString();
                        label2.Text  = male.ToString();
                        label10.Text = female.ToString();
                        connection.Close();
                    }
                }
                populate();
            }
            catch (Exception ex)
            {
                List <Label> Labels = new List <Label>();
                Labels.Add(MyLabel.SetOKLabel("General Error"));
                Labels.Add(MyLabel.SetOKLabel(ex.Message));

                List <Button> Buttons = new List <Button>();
                Buttons.Add(MyButton.SetOKThemeButton());
                MyMessageBox.Show(
                    Labels,
                    "",
                    Buttons,
                    MyImage.SetFailed());
            }
        }
Exemple #4
0
        private void button3_Click(object sender, EventArgs e)
        {
            members.Clear();
            string genderCheckBox = "";
            string query          = "";

            if (radioButton5.Checked)
            {
                genderCheckBox = "Male";
            }
            else if (radioButton6.Checked)
            {
                genderCheckBox = "Female";
            }

            if (genderCheckBox != "")
            {
                query = "SELECT id, Name, Surname, CardId, TypeId, NumOfEntrances, Gender, " +
                        "LastEntrance, PhoneNumber, Address FROM Member WHERE (Name LIKE '%' + @d + '%' OR Surname LIKE '%' +  @d +'%') AND Gender = @g";
            }
            else
            {
                query = "SELECT id, Name, Surname, CardId, TypeId, NumOfEntrances, Gender, " +
                        "LastEntrance, PhoneNumber, Address FROM Member WHERE Name LIKE '%' + @d + '%' OR Surname LIKE '%' +  @d +'%'";
            }
            try
            {
                using (SqlConnection connection = new SqlConnection(
                           global::GymMembershipSystem.Properties.Settings.Default.GymMembershipSystemDatabase))
                {
                    using (SqlCommand cmd2 = new SqlCommand(query, connection))
                    {
                        cmd2.Parameters.AddWithValue("@d", name.Text);
                        if (genderCheckBox != "")
                        {
                            cmd2.Parameters.AddWithValue("@g", genderCheckBox);
                        }
                        cmd2.CommandType = CommandType.Text;
                        connection.Open();
                        SqlDataReader dr = cmd2.ExecuteReader();
                        while (dr.Read())
                        {
                            int      id2          = Convert.ToInt32(dr["id"]);
                            string   name         = dr["Name"].ToString();
                            string   surname      = dr["Surname"].ToString();
                            string   address      = dr["Address"].ToString();
                            string   phonenum     = dr["PhoneNumber"].ToString();
                            string   typeid       = dr["TypeId"].ToString();
                            int      numofentr    = Convert.ToInt32(dr["NumOfEntrances"]);
                            Int64    cardid       = Convert.ToInt64(dr["CardId"]);
                            DateTime lastEntrance = Convert.ToDateTime(dr["LastEntrance"]);
                            string   gender       = dr["Gender"].ToString();

                            DateTime expDate = method.GetExpirationDate(id2);

                            PartialMember newMember = new PartialMember();

                            newMember.Name           = name;
                            newMember.Surname        = surname;
                            newMember.Address        = address;
                            newMember.PhoneNumber    = phonenum;
                            newMember.TypeId         = typeid;
                            newMember.NumOfEntrances = numofentr;
                            newMember.ExpirationDate = expDate;
                            newMember.CardId         = cardid;
                            newMember.LastEntrance   = lastEntrance;
                            newMember.Gender         = gender;
                            newMember.id             = id2;
                            newMember.NumOfDays      = method.GetNumberOfEntrances(cardid.ToString());
                            members.Add(newMember);
                        }

                        connection.Close();
                    }
                }
                populate();
            }
            catch (Exception ex)
            {
                List <Label> Labels = new List <Label>();
                Labels.Add(MyLabel.SetOKLabel("General Error"));
                Labels.Add(MyLabel.SetOKLabel(ex.Message));

                List <Button> Buttons = new List <Button>();
                Buttons.Add(MyButton.SetOKThemeButton());
                MyMessageBox.Show(
                    Labels,
                    "",
                    Buttons,
                    MyImage.SetFailed());
            }
        }
Exemple #5
0
        private void GetInfo()
        {
            try
            {
                int i = Convert.ToInt32(globalId);

                using (SqlConnection connection = new SqlConnection(
                           global::GymMembershipSystem.Properties.Settings.Default.GymMembershipSystemDatabase))
                {
                    using (SqlCommand cmd2 = new SqlCommand("SELECT Name, Surname, CardId, Address, PhoneNumber, TypeId, NumOfEntrances, Gender, " +
                                                            "LastEntrance FROM Member WHERE id=@id", connection))
                    {
                        connection.Open();
                        cmd2.CommandType = CommandType.Text;
                        cmd2.Parameters.AddWithValue("@id", i);

                        SqlDataReader dr = cmd2.ExecuteReader();
                        while (dr.Read())
                        {
                            string   name1           = dr["Name"].ToString();
                            string   surname1        = dr["Surname"].ToString();
                            string   address1        = dr["Address"].ToString();
                            string   phoneno1        = dr["PhoneNumber"].ToString();
                            string   typeid1         = dr["TypeId"].ToString();
                            long     cardId1         = Convert.ToInt64(dr["CardId"]);
                            int      numofentrances1 = Convert.ToInt32(dr["NumOfEntrances"]);
                            DateTime lastEntr        = Convert.ToDateTime(dr["LastEntrance"]);
                            string   gender1         = dr["Gender"].ToString();

                            DateTime z = methods.GetExpirationDate(i);
                            if (lastEntr.Date != DateTime.Today)
                            {
                                numofentrances1++;
                                methods.WriteEntrance(i, numofentrances1, name1, surname1);
                            }
                            string date = z.Day + "/" + z.Month + "/" + z.Year;
                            methods.WriteLastEntrance(i);
                            lastEntr = DateTime.Now;


                            panel1.Visible = true;
                            label14.Text   = name1;
                            label8.Text    = surname1;
                            label4.Text    = gender1;
                            label24.Text   = address1;
                            label22.Text   = phoneno1;
                            label21.Text   = date;
                            label20.Text   = cardId1.ToString();
                            label15.Text   = typeid1;
                            label17.Text   = numofentrances1.ToString();


                            a.Name           = name1;
                            a.Surname        = surname1;
                            a.Address        = address1;
                            a.PhoneNumber    = phoneno1;
                            a.TypeId         = typeid1;
                            a.NumOfEntrances = numofentrances1;
                            a.ExpirationDate = z;
                            a.CardId         = cardId1;
                            a.LastEntrance   = lastEntr;
                            a.Gender         = gender1;
                            a.id             = i;
                        }
                    }
                    connection.Close();
                }
            }
            catch (Exception ex)
            {
                List <Label> Labels = new List <Label>();
                Labels.Add(MyLabel.SetOKLabel("General Error"));
                Labels.Add(MyLabel.SetOKLabel(ex.Message));

                List <Button> Buttons = new List <Button>();
                Buttons.Add(MyButton.SetOKThemeButton());
                MyMessageBox.Show(
                    Labels,
                    "",
                    Buttons,
                    MyImage.SetFailed());
            }
        }
Exemple #6
0
        private void button3_Click(object sender, EventArgs e)
        {
            if (label8.Text == "")
            {
                List <Label> Labels = new List <Label>();
                Labels.Add(MyLabel.SetOKLabel("General Error"));
                Labels.Add(MyLabel.SetOKLabel("Please enter location: "));

                List <Button> Buttons = new List <Button>();
                Buttons.Add(MyButton.SetOKThemeButton());
                MyMessageBox.Show(
                    Labels,
                    "",
                    Buttons,
                    MyImage.SetFailed());
            }
            else
            {
                try
                {
                    using (SqlConnection connection = new SqlConnection(global::GymMembershipSystem.Properties.Settings.Default.GymMembershipSystemDatabase))
                    {
                        using (SqlCommand command = new SqlCommand("UPDATE Settings SET COMM=@c,PATH=@p WHERE Id=1 ", connection))
                        {
                            int x = comboBox1.SelectedIndex + 1;
                            command.Parameters.AddWithValue("@c", x);
                            command.Parameters.AddWithValue("@p", label8.Text);
                            command.Connection.Open();

                            if (command.ExecuteNonQuery().ToString() == "1")
                            {
                                List <Label> Labels = new List <Label>();
                                Labels.Add(MyLabel.SetOKLabel("Settings Changed Successfully"));
                                Labels.Add(MyLabel.SetOKLabel("Settings changed"));

                                List <Button> Buttons = new List <Button>();
                                Buttons.Add(MyButton.SetOKThemeButton());
                                MyMessageBox.Show(
                                    Labels,
                                    "",
                                    Buttons,
                                    MyImage.SetSuccess());
                            }
                            else
                            {
                                List <Label> Labels = new List <Label>();
                                Labels.Add(MyLabel.SetOKLabel("Settings change Failed"));
                                Labels.Add(MyLabel.SetOKLabel("Settings not changed"));

                                List <Button> Buttons = new List <Button>();
                                Buttons.Add(MyButton.SetOKThemeButton());
                                MyMessageBox.Show(
                                    Labels,
                                    "",
                                    Buttons,
                                    MyImage.SetSuccess());

                                command.Connection.Close();
                                this.Close();
                            }
                        }
                    }
                }

                catch (Exception ex)
                {
                    List <Label> Labels = new List <Label>();
                    Labels.Add(MyLabel.SetOKLabel("General Error"));
                    Labels.Add(MyLabel.SetOKLabel(ex.Message));

                    List <Button> Buttons = new List <Button>();
                    Buttons.Add(MyButton.SetOKThemeButton());
                    MyMessageBox.Show(
                        Labels,
                        "",
                        Buttons,
                        MyImage.SetFailed());
                }
            }
        }
Exemple #7
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (visibilitylevel == 1)
            {
                if (formbox1.Text != password)
                {
                    formbox1.Text = "";
                    formbox2.Text = "";
                    formbox3.Text = "";

                    label1.Text = "Password is incorrect!";
                    errorProvider1.SetError(formbox1, "Password is incorrect");
                }
                else if (formbox2.Text.Length <= 5)
                {
                    formbox2.Text = "";
                    formbox3.Text = "";
                    errorProvider1.SetError(formbox1, "");
                    label1.Text = "Password has to be longer than 5 characters!";
                    errorProvider1.SetError(formbox2, "Password has to be longer than 5 characters!");
                }
                else if (formbox2.Text != formbox3.Text)
                {
                    formbox2.Text = "";
                    formbox3.Text = "";
                    label1.Text   = "Passwords aren't equal!";
                    errorProvider1.SetError(formbox2, "Passwords aren't equal!");
                    errorProvider1.SetError(formbox3, "Passwords aren't equal!");
                }
                else
                {
                    try
                    {
                        label1.Text = "";
                        errorProvider1.SetError(formbox2, "");
                        errorProvider1.SetError(formbox3, "");
                        using (SqlConnection connection = new SqlConnection(global::GymMembershipSystem.Properties.Settings.Default.GymMembershipSystemDatabase))
                        {
                            using (SqlCommand command = new SqlCommand("UPDATE Admin SET password=@s WHERE username='******'", connection))
                            {
                                command.Parameters.AddWithValue("@s", formbox2.Text);
                                command.Connection.Open();

                                if (command.ExecuteNonQuery().ToString() == "1")
                                {
                                    List <Label> Labels = new List <Label>();
                                    Labels.Add(MyLabel.SetOKLabel("Password Change"));
                                    Labels.Add(MyLabel.SetOKLabel("Password changed successfully"));

                                    List <Button> Buttons = new List <Button>();
                                    Buttons.Add(MyButton.SetOKThemeButton());
                                    MyMessageBox.Show(
                                        Labels,
                                        "",
                                        Buttons,
                                        MyImage.SetSuccess());
                                }
                                else
                                {
                                    List <Label> Labels = new List <Label>();
                                    Labels.Add(MyLabel.SetOKLabel("Password Change"));
                                    Labels.Add(MyLabel.SetOKLabel("Password Change failed"));

                                    List <Button> Buttons = new List <Button>();
                                    Buttons.Add(MyButton.SetOKThemeButton());
                                    MyMessageBox.Show(
                                        Labels,
                                        "",
                                        Buttons,
                                        MyImage.SetFailed());
                                }

                                formbox1.Text = "";
                                formbox2.Text = "";
                                formbox3.Text = "";

                                command.Connection.Close();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        List <Label> Labels = new List <Label>();
                        Labels.Add(MyLabel.SetOKLabel("General Error"));
                        Labels.Add(MyLabel.SetOKLabel(ex.Message));

                        List <Button> Buttons = new List <Button>();
                        Buttons.Add(MyButton.SetOKThemeButton());
                        MyMessageBox.Show(
                            Labels,
                            "",
                            Buttons,
                            MyImage.SetFailed());
                    }
                }
            }
            else if (visibilitylevel == 2)
            {
                if (authLevel == "2")
                {
                    try
                    {
                        using (SqlConnection connection2 = new SqlConnection(
                                   global::GymMembershipSystem.Properties.Settings.Default.GymMembershipSystemDatabase))
                        {
                            using (SqlCommand cmd = new SqlCommand("INSERT INTO Admin(username, password, authLevel)" +
                                                                   "VALUES(@username, @password, @authLevel)", connection2))
                            {
                                cmd.Parameters.AddWithValue("@username", formbox1.Text);
                                cmd.Parameters.AddWithValue("@password", formbox2.Text);
                                cmd.Parameters.AddWithValue("@authLevel", formbox3.Text);

                                cmd.Connection.Open();

                                if (cmd.ExecuteNonQuery().ToString() == "1")
                                {
                                    List <Label> Labels = new List <Label>();
                                    Labels.Add(MyLabel.SetOKLabel("Created new superuser"));
                                    Labels.Add(MyLabel.SetOKLabel("New superuser created successfully"));

                                    List <Button> Buttons = new List <Button>();
                                    Buttons.Add(MyButton.SetOKThemeButton());
                                    MyMessageBox.Show(
                                        Labels,
                                        "",
                                        Buttons,
                                        MyImage.SetSuccess());


                                    formbox1.Text = "";
                                    formbox2.Text = "";
                                    formbox3.Text = "";
                                }
                            }

                            connection2.Close();
                        }
                    }
                    catch (Exception ex)
                    {
                        List <Label> Labels = new List <Label>();
                        Labels.Add(MyLabel.SetOKLabel("General Error"));
                        Labels.Add(MyLabel.SetOKLabel(ex.Message));

                        List <Button> Buttons = new List <Button>();
                        Buttons.Add(MyButton.SetOKThemeButton());
                        MyMessageBox.Show(
                            Labels,
                            "",
                            Buttons,
                            MyImage.SetFailed());
                    }
                }
                else
                {
                    List <Label> Labels = new List <Label>();
                    Labels.Add(MyLabel.SetOKLabel("Unavailable"));
                    Labels.Add(MyLabel.SetOKLabel("You don't have the Auth Level of 1"));

                    List <Button> Buttons = new List <Button>();
                    Buttons.Add(MyButton.SetOKThemeButton());
                    MyMessageBox.Show(
                        Labels,
                        "",
                        Buttons,
                        MyImage.SetFailed());
                }
            }
        }
Exemple #8
0
        public static string Show(List <Label> Labels = null, string Title = "", List <Button> Buttons = null, PictureBox Image = null)
        {
            if (Labels == null)
            {
                Labels = new List <Label>();
            }
            if (Labels.Count == 0)
            {
                Labels.Add(MyLabel.Set(""));
            }
            if (Buttons == null)
            {
                Buttons = new List <Button>();
            }
            if (Buttons.Count == 0)
            {
                Buttons.Add(MyButton.Set("OK"));
            }
            List <Button> buttons = new List <Button>(Buttons);

            buttons.Reverse();

            int ImageWidth   = 0;
            int ImageHeight  = 0;
            int LabelWidth   = 0;
            int LabelHeight  = 0;
            int ButtonWidth  = 0;
            int ButtonHeight = 0;
            int TotalWidth   = 0;
            int TotalHeight  = 0;

            MyMessageBox mb = new MyMessageBox();

            mb.Text = Title;

            //Image
            if (Image != null)
            {
                mb.Controls.Add(Image);
                Image.MaximumSize = new Size(150, 300);
                ImageWidth        = Image.Width + Image.Margin.Horizontal;
                ImageHeight       = Image.Height + Image.Margin.Vertical;
            }

            //Labels
            List <int> il = new List <int>();

            mb.panText.Location = new Point(9 + ImageWidth, 35);
            foreach (Label l in Labels)
            {
                mb.panText.Controls.Add(l);
                l.Location    = new Point(200, 50);
                l.MaximumSize = new Size(480, 2000);
                il.Add(l.Width);
            }
            int mw = Labels.Max(x => x.Width);

            il.ToString();
            Labels.ForEach(l => l.MinimumSize = new Size(Labels.Max(x => x.Width), 1));
            mb.panText.Height      = Labels.Sum(l => l.Height);
            mb.panText.MinimumSize = new Size(Labels.Max(x => x.Width) + mb.ScrollBarWidth(Labels), ImageHeight);
            mb.panText.MaximumSize = new Size(Labels.Max(x => x.Width) + mb.ScrollBarWidth(Labels), 300);
            LabelWidth             = mb.panText.Width;
            LabelHeight            = mb.panText.Height;

            //Buttons
            foreach (Button b in buttons)
            {
                mb.panButtons.Controls.Add(b);
                b.Location = new Point(3, 3);
                b.TabIndex = Buttons.FindIndex(i => i.Text == b.Text);
                b.Click   += new EventHandler(mb.Button_Click);
            }
            ButtonWidth  = mb.panButtons.Width;
            ButtonHeight = mb.panButtons.Height;

            //Set Widths
            if (ButtonWidth > ImageWidth + LabelWidth)
            {
                Labels.ForEach(l => l.MinimumSize = new Size(ButtonWidth - ImageWidth - mb.ScrollBarWidth(Labels), 1));
                mb.panText.Height      = Labels.Sum(l => l.Height);
                mb.panText.MinimumSize = new Size(Labels.Max(x => x.Width) + mb.ScrollBarWidth(Labels), ImageHeight);
                mb.panText.MaximumSize = new Size(Labels.Max(x => x.Width) + mb.ScrollBarWidth(Labels), 300);
                LabelWidth             = mb.panText.Width;
                LabelHeight            = mb.panText.Height;
            }
            TotalWidth = ImageWidth + LabelWidth;

            //Set Height
            TotalHeight = LabelHeight + ButtonHeight;

            mb.panButtons.Location = new Point(TotalWidth - ButtonWidth + 9, mb.panText.Location.Y + mb.panText.Height + 10);

            mb.Size = new Size(TotalWidth + 25, TotalHeight + 47);
            mb.ShowDialog();
            return(mb.Result);
        }
Exemple #9
0
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                if (cardIdLabel.Text == "______________________")
                {
                    List <Label> Labels = new List <Label>();
                    Labels.Add(MyLabel.SetOKLabel("Card doesn't exist"));
                    Labels.Add(MyLabel.SetOKLabel("Please put your card to the scanner"));

                    List <Button> Buttons = new List <Button>();
                    Buttons.Add(MyButton.SetOKThemeButton());
                    MyMessageBox.Show(
                        Labels,
                        "",
                        Buttons,
                        MyImage.SetFailed());
                    sport.Write("#ERROR: Card doesn't exist!\n");
                }
                else if (pictureBox1.BackgroundImage == null)
                {
                    List <Label> Labels = new List <Label>();
                    Labels.Add(MyLabel.SetOKLabel("Image is empty"));
                    Labels.Add(MyLabel.SetOKLabel("Please upload your image"));

                    List <Button> Buttons = new List <Button>();
                    Buttons.Add(MyButton.SetOKThemeButton());
                    MyMessageBox.Show(
                        Labels,
                        "",
                        Buttons,
                        MyImage.SetFailed());
                    sport.Write("#ERROR: Image is empty!\n");
                }
                else if (radioButton2.Checked == false && radioButton3.Checked == false)
                {
                    List <Label> Labels = new List <Label>();
                    Labels.Add(MyLabel.SetOKLabel("Card type empty"));
                    Labels.Add(MyLabel.SetOKLabel("Please select a card type"));

                    List <Button> Buttons = new List <Button>();
                    Buttons.Add(MyButton.SetOKThemeButton());
                    MyMessageBox.Show(
                        Labels,
                        "",
                        Buttons,
                        MyImage.SetFailed());
                    sport.Write("#ERROR: Card type is empty!\n");
                }
                else if (radioButton5.Checked == false && radioButton6.Checked == false)
                {
                    List <Label> Labels = new List <Label>();
                    Labels.Add(MyLabel.SetOKLabel("Gender is empty"));
                    Labels.Add(MyLabel.SetOKLabel("Please select a gender!"));

                    List <Button> Buttons = new List <Button>();
                    Buttons.Add(MyButton.SetOKThemeButton());
                    MyMessageBox.Show(
                        Labels,
                        "",
                        Buttons,
                        MyImage.SetFailed());
                    sport.Write("#ERROR: Gender is empty!\n");
                }
                else if (methods.CheckId(cardIdLabel.Text) == false)
                {
                    List <Label> Labels = new List <Label>();
                    Labels.Add(MyLabel.SetOKLabel("Card already exists!"));
                    Labels.Add(MyLabel.SetOKLabel("There is a card in the database!"));

                    List <Button> Buttons = new List <Button>();
                    Buttons.Add(MyButton.SetOKThemeButton());
                    MyMessageBox.Show(
                        Labels,
                        "",
                        Buttons,
                        MyImage.SetFailed());
                    sport.Write("#ERROR: Already a member!\n");
                }

                else
                {
                    using (SqlConnection connection = new SqlConnection(
                               global::GymMembershipSystem.Properties.Settings.Default.GymMembershipSystemDatabase))
                    {
                        using (SqlCommand command = new SqlCommand("INSERT INTO Member(Name,Surname,Address,PhoneNumber,CardId,TypeId,NumOfEntrances,Gender,LastEntrance)" +
                                                                   "VALUES(@Name,@Surname,@Address,@PhoneNumber,@CardId,@TypeId,@NumOfEntrances, @Gender, @LastEntrance)", connection))
                        {
                            string cardType = " ";
                            string gender   = " ";
                            if (radioButton2.Checked == true)
                            {
                                cardType = "Student";
                            }
                            if (radioButton3.Checked == true)
                            {
                                cardType = "Work";
                            }
                            if (radioButton5.Checked == true)
                            {
                                gender = "Male";
                            }
                            if (radioButton6.Checked == true)
                            {
                                gender = "Female";
                            }

                            command.Parameters.AddWithValue("Name", name.Text);
                            command.Parameters.AddWithValue("Surname", surname.Text);
                            command.Parameters.AddWithValue("Address", address.Text);
                            command.Parameters.AddWithValue("PhoneNumber", phoneno.Text);
                            command.Parameters.AddWithValue("Cardid", Convert.ToInt64(cardIdLabel.Text));
                            command.Parameters.AddWithValue("TypeId", cardType);
                            command.Parameters.AddWithValue("NumOfEntrances", 1);
                            command.Parameters.AddWithValue("Gender", gender);
                            command.Parameters.AddWithValue("LastEntrance", DateTime.Now);


                            command.Connection.Open();

                            if (command.ExecuteNonQuery().ToString() == "1")
                            {
                                List <Label> Labels = new List <Label>();
                                Labels.Add(MyLabel.SetOKLabel("Member insertion."));
                                Labels.Add(MyLabel.SetOKLabel("Member insertion passed."));

                                List <Button> Buttons = new List <Button>();
                                Buttons.Add(MyButton.SetOKThemeButton());
                                MyMessageBox.Show(
                                    Labels,
                                    "",
                                    Buttons,
                                    MyImage.SetSuccess());
                                if (cardType == "Student")
                                {
                                    sport.Write("#SUCCS: Your membership is 40 KM!\n");
                                }
                                else
                                {
                                    sport.Write("#SUCCS: Your membership is 50 KM!\n");
                                }
                            }
                            else
                            {
                                List <Label> Labels = new List <Label>();
                                Labels.Add(MyLabel.SetOKLabel("Member insertion."));
                                Labels.Add(MyLabel.SetOKLabel("Member insertion failed."));

                                List <Button> Buttons = new List <Button>();
                                Buttons.Add(MyButton.SetOKThemeButton());
                                MyMessageBox.Show(
                                    Labels,
                                    "",
                                    Buttons,
                                    MyImage.SetFailed());
                            }
                            command.Connection.Close();
                        }
                        int p = methods.GetMemberId(cardIdLabel.Text);

                        using (SqlCommand command2 = new SqlCommand("INSERT INTO Account(PaymentDate,ExpirationDate,Price,Name,Surname,MemberId)" +
                                                                    "VALUES(@PaymentDate,@ExpirationDate,@Price,@Name,@Surname,@MemberId)", connection))
                        {
                            command2.Parameters.AddWithValue("PaymentDate", DateTime.Today);
                            command2.Parameters.AddWithValue("ExpirationDate", DateTime.Today.AddDays(30 * (monthsno.SelectedIndex + 1)));
                            command2.Parameters.AddWithValue("Price", price.Text);
                            command2.Parameters.AddWithValue("Name", name.Text);
                            command2.Parameters.AddWithValue("Surname", surname.Text);
                            command2.Parameters.AddWithValue("MemberId", p);
                            command2.Connection.Open();

                            command2.ExecuteNonQuery();

                            command2.Connection.Close();
                        }
                        using (SqlCommand command3 = new SqlCommand("INSERT INTO Report(MemberId,EntranceDate,Name,Surname) VALUES(@MemberId,@EntranceDate,@Name,@Surname)", connection))
                        {
                            command3.Parameters.AddWithValue("@MemberId", p);
                            command3.Parameters.AddWithValue("@EntranceDate", DateTime.Now);
                            command3.Parameters.AddWithValue("@Name", name.Text);
                            command3.Parameters.AddWithValue("@Surname", surname.Text);

                            command3.Connection.Open();
                            command3.ExecuteNonQuery();

                            command3.Connection.Close();
                        }

                        using (SqlCommand cmd4 = new SqlCommand("SELECT PATH FROM Settings", connection))
                        {
                            cmd4.CommandType = CommandType.Text;
                            cmd4.Connection.Open();
                            SqlDataReader dr = cmd4.ExecuteReader();
                            while (dr.Read())
                            {
                                path = dr["PATH"].ToString();
                            }
                            cmd4.Connection.Close();
                        }

                        saveImage();
                        this.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                List <Label> Labels = new List <Label>();
                Labels.Add(MyLabel.SetOKLabel("General error"));
                Labels.Add(MyLabel.SetOKLabel(ex.Message));

                List <Button> Buttons = new List <Button>();
                Buttons.Add(MyButton.SetOKThemeButton());
                MyMessageBox.Show(
                    Labels,
                    "",
                    Buttons,
                    MyImage.SetFailed());
            }
        }
Exemple #10
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            string tmp       = "";
            string authLevel = "";

            try
            {
                using (SqlConnection connection = new SqlConnection(
                           global::GymMembershipSystem.Properties.Settings.Default.GymMembershipSystemDatabase))
                {
                    using (SqlCommand cmd = new SqlCommand("SELECT password, authLevel FROM Admin WHERE username=@user", connection))
                    {
                        cmd.CommandType = CommandType.Text;
                        cmd.Parameters.AddWithValue("@user", userBox.Text);

                        connection.Open();

                        SqlDataReader o = cmd.ExecuteReader();
                        if (o != null)
                        {
                            while (o.Read())
                            {
                                tmp       = o["password"].ToString();
                                authLevel = o["authLevel"].ToString();
                            }
                        }
                        connection.Close();
                    }
                }

                if (passBox.Text != tmp || tmp == "")
                {
                    List <Label> Labels = new List <Label>();
                    Labels.Add(MyLabel.SetOKLabel("Login Failed!"));
                    Labels.Add(MyLabel.SetOKLabel("Incorrect Username/Password"));

                    List <Button> Buttons = new List <Button>();
                    Buttons.Add(MyButton.SetOKThemeButton());
                    MyMessageBox.Show(
                        Labels,
                        "",
                        Buttons,
                        MyImage.SetFailed());
                    userBox.Text = "";
                    passBox.Text = "";
                }
                else
                {
                    List <Label> Labels = new List <Label>();
                    Labels.Add(MyLabel.SetOKLabel("Successfull Login!"));
                    Labels.Add(MyLabel.SetOKLabel("Welcome Back " + userBox.Text + "!"));

                    List <Button> Buttons = new List <Button>();
                    Buttons.Add(MyButton.SetOKThemeButton());
                    MyMessageBox.Show(
                        Labels,
                        "",
                        Buttons,
                        MyImage.SetSuccess());

                    HomeForm h = new HomeForm(authLevel, userBox.Text);
                    h.MaximizeBox = false;
                    h.MinimizeBox = false;
                    this.Hide();
                    h.ShowDialog();
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                List <Label> Labels = new List <Label>();
                Labels.Add(MyLabel.SetOKLabel("General Error"));
                Labels.Add(MyLabel.SetOKLabel(ex.Message));

                List <Button> Buttons = new List <Button>();
                Buttons.Add(MyButton.SetOKThemeButton());
                MyMessageBox.Show(
                    Labels,
                    "",
                    Buttons,
                    MyImage.SetFailed());
            }
        }
Exemple #11
0
        private void HomeForm_Load(object sender, EventArgs e)
        {
            timer1.Start();
            try
            {
                using (SqlConnection connection = new SqlConnection(global::GymMembershipSystem.Properties.Settings.Default.GymMembershipSystemDatabase))
                {
                    bool tmp = false;
                    using (SqlCommand cmd = new SqlCommand("SELECT PATH FROM Settings WHERE Id=1", connection))
                    {
                        cmd.CommandType = CommandType.Text;

                        connection.Open();

                        object o = cmd.ExecuteScalar();
                        if (o != null)
                        {
                            if (o.ToString() == "")
                            {
                                tmp = true;
                            }
                            else
                            {
                                tmp = false;
                            }
                        }
                        else
                        {
                            tmp = true;
                        }

                        cmd.Connection.Close();
                    }
                    if (tmp)
                    {
                        using (SqlCommand command = new SqlCommand("UPDATE Settings SET PATH=@p WHERE Id=1 ", connection))
                        {
                            string wanted_path = Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory()));

                            command.Parameters.AddWithValue("@p", wanted_path);
                            command.Connection.Open();
                            command.ExecuteNonQuery();

                            command.Connection.Close();
                        }
                    }
                }

                sport.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);

                sport.Open();
            }
            catch (Exception ex)
            {
                List <Label> Labels = new List <Label>();
                Labels.Add(MyLabel.SetOKLabel("General Error"));
                Labels.Add(MyLabel.SetOKLabel(ex.Message));

                List <Button> Buttons = new List <Button>();
                Buttons.Add(MyButton.SetOKThemeButton());
                MyMessageBox.Show(
                    Labels,
                    "",
                    Buttons,
                    MyImage.SetFailed());
            }
        }
Exemple #12
0
        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                using (SqlConnection connection = new SqlConnection(
                           global::GymMembershipSystem.Properties.Settings.Default.GymMembershipSystemDatabase))
                {
                    using (SqlCommand command2 = new SqlCommand("INSERT INTO Account(PaymentDate,ExpirationDate,Price,Name,Surname,MemberId)" +
                                                                "VALUES(@PaymentDate,@ExpirationDate,@Price,@Name,@Surname,@MemberId)", connection))
                    {
                        int x = Convert.ToInt32(noofmonthslabel.Text);

                        command2.Parameters.AddWithValue("PaymentDate", DateTime.Today);
                        command2.Parameters.AddWithValue("ExpirationDate", Convert.ToDateTime(membershipuntil.Text));
                        command2.Parameters.AddWithValue("Price", pricelabel.Text);
                        command2.Parameters.AddWithValue("Name", namelabel.Text);
                        command2.Parameters.AddWithValue("Surname", surnamelabel.Text);
                        command2.Parameters.AddWithValue("MemberId", b.id);
                        command2.Connection.Open();

                        if (command2.ExecuteNonQuery().ToString() == "1")
                        {
                            List <Label> Labels = new List <Label>();
                            Labels.Add(MyLabel.SetOKLabel("Membership extension."));
                            Labels.Add(MyLabel.SetOKLabel("Successfully Passed"));

                            List <Button> Buttons = new List <Button>();
                            Buttons.Add(MyButton.SetOKThemeButton());
                            MyMessageBox.Show(
                                Labels,
                                "",
                                Buttons,
                                MyImage.SetSuccess());
                        }
                        else
                        {
                            List <Label> Labels = new List <Label>();
                            Labels.Add(MyLabel.SetOKLabel("Membership extension."));
                            Labels.Add(MyLabel.SetOKLabel("Failed."));

                            List <Button> Buttons = new List <Button>();
                            Buttons.Add(MyButton.SetOKThemeButton());
                            MyMessageBox.Show(
                                Labels,
                                "",
                                Buttons,
                                MyImage.SetFailed());
                        }
                        command2.Connection.Close();
                        this.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                List <Label> Labels = new List <Label>();
                Labels.Add(MyLabel.SetOKLabel("Membership extension."));
                Labels.Add(MyLabel.SetOKLabel(ex.Message));

                List <Button> Buttons = new List <Button>();
                Buttons.Add(MyButton.SetOKThemeButton());
                MyMessageBox.Show(
                    Labels,
                    "",
                    Buttons,
                    MyImage.SetFailed());
            }
        }
Exemple #13
0
        private void GetInfo()
        {
            try
            {
                Int64 i = Convert.ToInt64(id);

                using (SqlConnection connection = new SqlConnection(
                           global::GymMembershipSystem.Properties.Settings.Default.GymMembershipSystemDatabase))
                {
                    using (SqlCommand cmd = new SqlCommand("SELECT id FROM Member WHERE CardId=@CardId", connection))
                    {
                        cmd.CommandType = CommandType.Text;
                        cmd.Parameters.AddWithValue("@CardId", i);
                        connection.Open();

                        object o = cmd.ExecuteScalar();
                        if (o != null)
                        {
                            string city = o.ToString();
                            int    k    = Convert.ToInt32(city);
                            using (SqlCommand cmd2 = new SqlCommand("SELECT Name, Surname, Address, PhoneNumber, TypeId, NumOfEntrances, Gender, " +
                                                                    "LastEntrance FROM Member WHERE id=@id", connection))
                            {
                                cmd2.CommandType = CommandType.Text;
                                cmd2.Parameters.AddWithValue("@id", k);

                                SqlDataReader dr = cmd2.ExecuteReader();
                                while (dr.Read())
                                {
                                    string   name1           = dr["Name"].ToString();
                                    string   surname1        = dr["Surname"].ToString();
                                    string   address1        = dr["Address"].ToString();
                                    string   phoneno1        = dr["PhoneNumber"].ToString();
                                    string   typeid1         = dr["TypeId"].ToString();
                                    int      numofentrances1 = Convert.ToInt32(dr["NumOfEntrances"]);
                                    DateTime lastEntr        = Convert.ToDateTime(dr["LastEntrance"]);
                                    string   gender1         = dr["Gender"].ToString();

                                    DateTime z = methods.GetExpirationDate(k);
                                    if (lastEntr.Date != DateTime.Today)
                                    {
                                        numofentrances1++;
                                        methods.WriteEntrance(k, numofentrances1, name1, surname1);
                                    }
                                    methods.WriteLastEntrance(k);
                                    lastEntr = DateTime.Now;


                                    a.Name           = name1;
                                    a.Surname        = surname1;
                                    a.Address        = address1;
                                    a.PhoneNumber    = phoneno1;
                                    a.TypeId         = typeid1;
                                    a.NumOfEntrances = numofentrances1;
                                    a.ExpirationDate = z;
                                    a.CardId         = i;
                                    a.LastEntrance   = lastEntr;
                                    a.Gender         = gender1;
                                    a.id             = k;
                                }
                            }
                        }
                        connection.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                List <Label> Labels = new List <Label>();
                Labels.Add(MyLabel.SetOKLabel("General Error"));
                Labels.Add(MyLabel.SetOKLabel(ex.Message));

                List <Button> Buttons = new List <Button>();
                Buttons.Add(MyButton.SetOKThemeButton());
                MyMessageBox.Show(
                    Labels,
                    "",
                    Buttons,
                    MyImage.SetFailed());
            }
        }