示例#1
0
        private void buttonR_Click(object sender, EventArgs e, string userID, string username, string email)
        {
            //foreach (Label l in allNames)
            //    Console.WriteLine(l.Text);
            //foreach (TextBox ttt in allAmounts)
            //    Console.WriteLine(ttt.Text);

            List <string> objectsReserved = new List <string>();

            var combined = allNames.Zip(checkboxes, (n, w) => new { Name = n, Checked = w.Checked });

            foreach (var iterate in combined)
            {
                if (iterate.Checked)
                {
                    objectsReserved.Add(iterate.Name);
                }
            }
            //if (objectsReserved.Count>0)
            {
                Credentials credentials = new Credentials(objectsReserved, userID, username, email);
                //this.Hide();
                credentials.ShowDialog();

                ProductsForm refresh = new ProductsForm(username, userID, email);
                this.Hide();
                refresh.ShowDialog();
                this.Close();

                //Console.Write("comanda efectuata");
                //this.Close();
            }
        }
示例#2
0
        private void loginButton_Click(object sender, EventArgs e)
        {
            string user     = usernameTextBox.Text;
            string password = passwordTextBox.Text;

            var connectionBuilder = new SqlConnectionStringBuilder();

            connectionBuilder.DataSource     = "prjserver.database.windows.net";
            connectionBuilder.UserID         = "serveradmin";
            connectionBuilder.Password       = "******";
            connectionBuilder.InitialCatalog = "projectTesting";

            string    query   = "Select * from users;";
            DataTable results = new DataTable();

            using (var connection = new SqlConnection(connectionBuilder.ConnectionString))
                using (SqlCommand command = new SqlCommand(query, connection))
                    using (SqlDataAdapter dataAdapter = new SqlDataAdapter(command))
                        dataAdapter.Fill(results);


            foreach (DataRow row in results.Rows)
            {
                string validUserId   = row.Field <int>(0).ToString();
                string validUsername = row.Field <string>(1);
                string validPassword = row.Field <string>(2);
                string privilege     = row.Field <string>(3);
                string validEmail    = row.Field <string>(5);

                if (privilege == "client" &&
                    user == validUsername &&
                    password == validPassword)
                {
                    ProductsForm productsForm = new ProductsForm(validUsername,
                                                                 validUserId, validEmail);

                    this.Hide();
                    productsForm.ShowDialog();
                    this.Close();
                }

                if (privilege == "admin" &&
                    user == validUsername &&
                    password == validPassword)
                {
                    ProcessStartInfo sInfo = new ProcessStartInfo("https://web.powerapps.com/apps/def3ecb8-7bae-4345-8c2a-dcd9a809fc78");
                    Process.Start(sInfo);
                    this.Close();
                }
            }

            ////    string que = " INSERT INTO users (Username, Password) VALUES ('"+user+"', '"+password+"');" ;
            ////Connectt.Submit_Tsql_NonQuery(connection, "Insert", que);

            //SqlCommand command = connection.CreateCommand();
            //SqlTransaction transaction;

            //// Start a local transaction.
            //transaction = connection.BeginTransaction("SampleTransaction");

            //// Must assign both transaction object and connection
            //// to Command object for a pending local transaction
            //command.Connection = connection;
            //command.Transaction = transaction;

            //    command.CommandText =
            //        " INSERT INTO users (Username, Password) VALUES ('" + user + "', '" + password + "');";
            //    command.ExecuteNonQuery();
            //    // Attempt to commit the transaction.
            //    transaction.Commit();
            //    Console.WriteLine("Both records are written to database.");

            //    //Connectt.Submit_Tsql_NonQuery(connection, "3 - Inserts", query);
        }
示例#3
0
        public ProductsForm(string username, string userID, string email)
        {
            InitializeComponent();
            welcomeLabel.Text = username + " !";

            var connectionBuilder = new SqlConnectionStringBuilder();

            connectionBuilder.DataSource     = "prjserver.database.windows.net";
            connectionBuilder.UserID         = "serveradmin";
            connectionBuilder.Password       = "******";
            connectionBuilder.InitialCatalog = "projectTesting";
            DataTable dataTable = new DataTable();

            string query = "select productName, quantity, productID from products;";

            using (var connection = new SqlConnection(connectionBuilder.ConnectionString))
                using (var command = new SqlCommand(query, connection))
                    using (var dataAdapter = new SqlDataAdapter(command))
                        dataAdapter.Fill(dataTable);

            int counter               = 1;
            int startLeft             = 43;
            int startTop              = 98;
            int validationOfCheckings = 0;

            loginButton.Click += (sender, EventArgs) => { buttonR_Click(sender, EventArgs, userID, username, email); };

            prevOrders.Click += (sender, EventArgs) => { prevOrders_Click(sender, EventArgs, userID); };

            foreach (DataRow row in dataTable.Rows)
            {
                connectionBuilder                          = new SqlConnectionStringBuilder();
                connectionBuilder.DataSource               = "prjserver.database.windows.net";
                connectionBuilder.UserID                   = "serveradmin";
                connectionBuilder.Password                 = "******";
                connectionBuilder.InitialCatalog           = "projectTesting";
                connectionBuilder.MultipleActiveResultSets = true;

                using (var connection = new SqlConnection(connectionBuilder.ConnectionString))
                {
                    connection.Open();

                    string productID        = row.Field <string>(0);
                    int    productsQuantity = row.Field <int>(1);

                    SqlCommand cmd = new SqlCommand("select * from bookings where IDuser='******' and IDproduct='" + row.Field <int>(2) + "';", connection);
                    SqlDataReader reader = cmd.ExecuteReader();

                    Panel panel = new Panel(); //what is this
                    panel.BorderStyle = BorderStyle.FixedSingle;
                    panel.Name        = "panel" + counter;
                    panel.Size        = new Size(120, 80);
                    panel.Location    = new Point((startLeft + (counter - 1) % 3 * 160), startTop + ((counter - 1) / 3) * 100);
                    panel.BackColor   = Color.FromArgb(35, panel.BackColor);
                    this.Controls.Add(panel);

                    Label productIDLabel      = new Label(); //l1
                    Label productsNumberLabel = new Label(); //l2

                    productIDLabel.Text           = productID;
                    productsNumberLabel.Text      = productsQuantity > 0 ? "Quantity: " + productsQuantity.ToString() : "Not available";
                    productIDLabel.ForeColor      = Color.White;
                    productsNumberLabel.ForeColor = Color.White;
                    panel.Controls.Add(productIDLabel);
                    panel.Controls.Add(productsNumberLabel);
                    productsNumberLabel.Top = productIDLabel.Top + 25;

                    if (productsQuantity > 0)
                    {
                        if (!reader.Read())
                        {
                            // The command returns Row(s)
                            allNames.Add(row.Field <int>(2).ToString());

                            //TextBox t = new TextBox();
                            //t.Size = new Size(23, 23);
                            //t.Location = new Point(28, 53);
                            //t.Text = "0";
                            //allAmounts.Add(t);

                            CheckBox reserve = new CheckBox();
                            reserve.Size      = new Size(98, 21);
                            reserve.Location  = new Point(3, 52);
                            reserve.Text      = "Reserve";
                            reserve.ForeColor = Color.White;
                            panel.Controls.Add(reserve);
                            checkboxes.Add(reserve);

                            //Button b1 = new Button();
                            //b1.Size = new Size(23, 23);
                            //b1.Location = new Point(3, 52);
                            //b1.Text = "-";
                            //b1.Name = "but" + counter + "1";
                            //b1.Click += (sender, EventArgs) => { buttonMinus_Click(sender, EventArgs, l2, t); };
                            //Button b2 = new Button();
                            //b2.Size = new Size(23, 23);
                            //b2.Location = new Point(53, 52);
                            //b2.Text = "+";
                            //b2.Name = "but" + counter + "2";
                            //b2.Click += (sender, EventArgs) => { buttonPlus_Click(sender, EventArgs, l2, t); };
                            //b1.Name = "text" + counter;

                            //NumericUpDown nup = new NumericUpDown();
                            //nup.Dock = System.Windows.Forms.DockStyle.Bottom;
                            //nup.ValueChanged += (sender, EventArgs) => {
                            //    int temp = Int32.Parse(l2.Text);
                            //    //if (nup.Value < 0)
                            //    //   return;
                            //    l2.Text = (temp - nup.Value).ToString();

                            //};
                            //p.Controls.Add(nup);

                            //p.Controls.Add(b1);
                            //p.Controls.Add(b2);
                            //p.Controls.Add(t);
                        }
                        else
                        {
                            if (reader.GetDateTime(3) >= DateTime.Now)
                            {
                                /*delivery calendar*/
                                MonthCalendar monthCalendar1 = new MonthCalendar();
                                DateTime      projectStart   = new DateTime(reader.GetDateTime(2).Year, reader.GetDateTime(2).Month, reader.GetDateTime(2).Day);
                                DateTime      projectEnd     = new DateTime(reader.GetDateTime(3).Year, reader.GetDateTime(3).Month, reader.GetDateTime(3).Day);
                                monthCalendar1.SelectionRange = new SelectionRange(projectStart, projectEnd);
                                monthCalendar1.SelectionStart = projectStart;
                                monthCalendar1.SelectionEnd   = projectEnd;
                                monthCalendar1.Left           = (this.ClientSize.Width - monthCalendar1.Width) / 2;
                                monthCalendar1.Top            = (this.ClientSize.Height - monthCalendar1.Height) / 2;


                                this.Controls.Add(monthCalendar1);
                                monthCalendar1.Hide();
                                monthCalendar1.Parent.Controls.SetChildIndex(monthCalendar1, 1);
                                productIDLabel.MouseEnter += new EventHandler(Calendar_MouseEnter);
                                productIDLabel.MouseLeave += new EventHandler(Calendar_MouseLeave);

                                Button remove = new Button();
                                remove.Size      = new Size(98, 21);
                                remove.Location  = new Point(3, 52);
                                remove.Text      = "Cancel order";
                                remove.ForeColor = Color.Black;
                                remove.BackColor = Color.White;
                                panel.Controls.Add(remove);
                                remove.Click += (sender, EventArgs) =>
                                {
                                    using (var connectionRemove = new SqlConnection(connectionBuilder.ConnectionString))
                                    {
                                        connectionRemove.Open();

                                        using (DbCommand command = new SqlCommand("Delete from bookings where IDuser='******' and IDproduct='" + row.Field <int>(2) + "';"))
                                        {
                                            command.Connection = connectionRemove;
                                            command.ExecuteNonQuery();
                                        }

                                        using (DbCommand command = new SqlCommand("Update products set quantity=quantity+1 where productID='" + row.Field <int>(2) + "';"))
                                        {
                                            command.Connection = connectionRemove;
                                            command.ExecuteNonQuery();
                                        }
                                    }
                                    ProductsForm refresh = new ProductsForm(username, userID, email);
                                    this.Hide();
                                    refresh.ShowDialog();
                                    this.Close();
                                };
                            }
                            else
                            {
                                if (!reader.GetBoolean(5))
                                {
                                    Button confirm = new Button();
                                    confirm.Size      = new Size(98, 21);
                                    confirm.Location  = new Point(3, 52);
                                    confirm.Text      = "Confirm";
                                    confirm.ForeColor = Color.Black;
                                    confirm.BackColor = Color.White;
                                    panel.Controls.Add(confirm);



                                    confirm.Click += (sender, EventArgs) =>
                                    {
                                        connectionBuilder                          = new SqlConnectionStringBuilder();
                                        connectionBuilder.DataSource               = "prjserver.database.windows.net";
                                        connectionBuilder.UserID                   = "serveradmin";
                                        connectionBuilder.Password                 = "******";
                                        connectionBuilder.InitialCatalog           = "projectTesting";
                                        connectionBuilder.MultipleActiveResultSets = true;

                                        using (var connectionUpdate = new SqlConnection(connectionBuilder.ConnectionString))
                                        {
                                            connectionUpdate.Open();


                                            using (DbCommand commandUpdate = new SqlCommand("update bookings set confirmation='True' where IDuser='******' and IDproduct='" + row.Field <int>(2) + "';"))
                                            //using (DbCommand commandUpdate = new SqlCommand("delete from bookings where IDuser='******' and IDproduct='"+row.Field<int>(2)+"';"))
                                            {
                                                commandUpdate.Connection = connectionUpdate;
                                                commandUpdate.ExecuteNonQuery();
                                            }
                                        }
                                        //// Create the Outlook application by using inline initialization.
                                        //Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();

                                        ////Create the new message by using the simplest approach.
                                        //Microsoft.Office.Interop.Outlook.MailItem oMsg = (MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);

                                        ////Add a recipient.
                                        //// TODO: Change the following recipient where appropriate.
                                        //Microsoft.Office.Interop.Outlook.Recipient oRecip = (Microsoft.Office.Interop.Outlook.Recipient)oMsg.Recipients.Add("*****@*****.**");
                                        //        oRecip.Resolve();

                                        ////Set the basic properties.
                                        //oMsg.Subject = "Confirmation";
                                        //        oMsg.Body = "The employee, picked up his order. This is a confirmation for the admin regarding the reservation of " + System.Environment.NewLine;

                                        //        using (var connection2 = new SqlConnection(connectionBuilder.ConnectionString))
                                        //        {
                                        //            connection2.Open();

                                        //            SqlCommand cmd2 = new SqlCommand("select productName from products where productID='" + row.Field<int>(2) + "';", connection2);
                                        //            SqlDataReader reader2 = cmd2.ExecuteReader();
                                        //            reader2.Read();
                                        //            string Message = "- " + reader2.GetString(0) + System.Environment.NewLine;
                                        //            oMsg.Body += Message;//to be fixed
                                        //        }

                                        ////Add an attachment.
                                        //// TODO: change file path where appropriate
                                        ////String sSource = "C:\\setupxlg.txt";
                                        ////String sDisplayName = "MyFirstAttachment";
                                        ////int iPosition = (int)oMsg.Body.Length + 1;
                                        ////int iAttachType = (int)Outlook.OlAttachmentType.olByValue;
                                        ////Microsoft.Office.Interop.Outlook.Attachment oAttach = oMsg.Attachments.Add(sSource, iAttachType, iPosition, sDisplayName);

                                        //// If you want to, display the message.
                                        //// oMsg.Display(true);  //modal

                                        ////Send the message.
                                        //oMsg.Save();
                                        //        oMsg.Send();

                                        ////Explicitly release objects.
                                        //oRecip = null;
                                        ////oAttach = null;
                                        //oMsg = null;
                                        //        oApp = null;

                                        ProductsForm refresh = new ProductsForm(username, userID, email);
                                        this.Hide();
                                        refresh.ShowDialog();
                                        this.Close();
                                    };
                                }
                                else
                                {
                                    Label nopermission = new Label();
                                    nopermission.Size      = new Size(98, 21);
                                    nopermission.Location  = new Point(3, 52);
                                    nopermission.Text      = "No permission";
                                    nopermission.ForeColor = Color.White;
                                    nopermission.BackColor = Color.Transparent;
                                    panel.Controls.Add(nopermission);
                                }
                            }
                        }
                    }
                    counter++;
                }
            }
        }