예제 #1
0
        private void create_Click(object sender, EventArgs e)
        {
            string text1   = textBox1.Text;
            string text2   = textBox2.Text;
            string text3   = textBox3.Text;
            string text4   = textBox4.Text;
            bool   proceed = true;

            //create button run check before submission
            errorlabel.Visible = false;
            //is anything blank?
            if (text1 == null || text2 == null || text3 == null || text4 == null)
            {
                //something is blank
                errorlabel.Text = "*A text entry was left blank";
                proceed         = false;
            }
            //check if account key is correct
            if (text1 == "fblaRocks!")
            {
                proceed = true;
            }
            else
            {
                proceed = false;
            }


            //check if passwords match
            if (text3 == text4)
            {
                //passwords match
            }
            else
            {
                //passwords do not match
                proceed            = false;
                errorlabel.Text    = "*Passwords do not match";
                errorlabel.Visible = true;
            }
            string location  = null;
            string location2 = null;

            //if its passed all the tests save user information & continue to login screen
            //username cannot previously exist, check
            if (proceed == true)
            {
                Excel.Application myExcelApp;
                Excel.Workbooks   myExcelWorkbooks;
                Excel.Workbook    myExcelWorkbook;
                object            misValue = System.Reflection.Missing.Value;
                Console.WriteLine("stuff has been created");
                myExcelApp               = new Excel.Application();
                myExcelApp.Visible       = false;
                myExcelApp.DisplayAlerts = false;
                myExcelWorkbooks         = myExcelApp.Workbooks;
                Console.WriteLine("More stuff has been created lljlkjlj");
                string fileName = "C:\\fblaManager\\fblaLogins.xls";

                myExcelWorkbook = myExcelWorkbooks.Open(fileName, misValue, misValue, misValue, "lambda3b", misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue);
                Excel.Worksheet myExcelWorksheet = (Excel.Worksheet)myExcelWorkbook.ActiveSheet;
                string          userData         = "hey";
                string          loc = null;
                x = 1;
                while (userData != "" || x == 1)
                {
                    Console.WriteLine(x + " time");
                    loc      = "A" + x;
                    userData = myExcelWorksheet.get_Range(loc, misValue).Formula.ToString();
                    if (userData != text2)
                    {
                        //this one isnt the username
                    }
                    else
                    {
                        //this one IS the username, username already exists!
                        Console.WriteLine("username already exists!");
                        proceed            = false;
                        errorlabel.Text    = "*User name already exists";
                        errorlabel.Visible = true;
                        break;
                    }
                    x = x + 1;
                }

                if (proceed == true)
                {
                    x         = x - 1;
                    location  = "A" + x;
                    location2 = "B" + x;
                    myExcelWorksheet.get_Range(location, misValue).Formula  = text2;
                    myExcelWorksheet.get_Range(location2, misValue).Formula = text3;
                    myExcelWorkbook.Save();
                }
                //close everything out

                Console.WriteLine("All Done :)");
                myExcelApp.Quit();
                if (proceed == true)
                {
                    login nl = new login();
                    nl.Show();
                    Close();
                }
            }
        }
예제 #2
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (y == 0)
            {
                label1.Text = "Loading...";
            }
            else if (y == 10)
            {
                label1.Text = "Loading.";
            }
            else if (y == 20)
            {
                label1.Text = "Loading..";
            }
            else if (y == 30)
            {
                label1.Text = "Loading...";
            }
            else if (y == 40)
            {
                label1.Text = "Loading.";
            }
            else if (y == 50)
            {
                label1.Text = "Loading..";
                y           = -10;
            }

            y = y + 10;
            if (x == 0)
            {
                System.Threading.Thread.Sleep(1000);
                x = 2;
            }
            if (File.Exists(path) == true && File.Exists(path2))
            {
                //do nothing everything should be in place
                Console.WriteLine("File exists, proceeding");

                //TESTING
            }
            else
            {
                label1.Text = "Preforming First Time Setup...";
                Console.WriteLine("File does not exist, writing file...");
                //directory may not exit
                if (System.IO.Directory.Exists(direct) == true)
                {
                    //directory exists
                    Console.WriteLine("Directory exists");
                }
                else
                {
                    //directory does not exist
                    Console.WriteLine("Directory does not exist, creating...");
                    System.IO.Directory.CreateDirectory(direct);
                    Console.WriteLine("Directory has been created");
                }


                //System.IO.File.Create("C:\\fblaManager\\fblaDatabase.xls"); DOES NOT WORK
                Excel.Application startup = new Excel.Application();
                startup.Visible       = false;
                startup.DisplayAlerts = false;
                Excel.Workbooks startWorkbooks;
                Excel.Workbook  startWorkbook;
                Excel.Worksheet startWorksheet;


                object misValue2 = System.Reflection.Missing.Value;
                startWorkbooks = startup.Workbooks;
                startWorkbook  = startup.Workbooks.Add(misValue2);
                Excel.XlSaveAsAccessMode save = Excel.XlSaveAsAccessMode.xlNoChange;
                startWorkbook.SaveAs("C:\\fblaManager\\fblaDatabase.xls", misValue2, "lambda3b", misValue2, misValue2, misValue2, save, misValue2, misValue2, misValue2, misValue2, misValue2);
                startWorkbook.SaveAs("C:\\fblaManager\\fblaLogins.xls", misValue2, "lambda3b", misValue2, misValue2, misValue2, save, misValue2, misValue2, misValue2, misValue2, misValue2);
                startWorksheet      = (Excel.Worksheet)startWorkbook.ActiveSheet;
                startWorksheet.Name = "fblaData";
                startWorkbook.Save();
                startWorkbook.Close();
                startup.Quit();
                Console.WriteLine("Were good to go");
                progressBar1.Increment(9);
                //setting up file
                Console.WriteLine("Testing write");
                Excel.Application myExcelApp;
                Excel.Workbooks   myExcelWorkbooks;
                Excel.Workbook    myExcelWorkbook;
                object            misValue = System.Reflection.Missing.Value;
                Console.WriteLine("stuff has been created");
                myExcelApp         = new Excel.Application();
                myExcelApp.Visible = false;

                myExcelWorkbooks = myExcelApp.Workbooks;
                Console.WriteLine("More stuff has been created lljlkjlj");
                string fileName = "C:\\fblaManager\\fblaDatabase.xls";
                //setting file information
                myExcelWorkbook = myExcelWorkbooks.Open(fileName, misValue, misValue, misValue, "lambda3b", misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue);
                Excel.Worksheet myExcelWorksheet = (Excel.Worksheet)myExcelWorkbook.ActiveSheet;

                Console.WriteLine("whoa even more stuff)");
                Console.WriteLine("All Done part 1");

                //writing to file
                myExcelWorksheet.get_Range("A1", misValue).Formula = "MemberNumber";
                myExcelWorksheet.get_Range("B1", misValue).Formula = "First";
                myExcelWorksheet.get_Range("C1", misValue).Formula = "Last";
                myExcelWorksheet.get_Range("D1", misValue).Formula = "School";
                myExcelWorksheet.get_Range("E1", misValue).Formula = "Grade";
                myExcelWorksheet.get_Range("F1", misValue).Formula = "State";
                myExcelWorksheet.get_Range("G1", misValue).Formula = "Email";
                myExcelWorksheet.get_Range("H1", misValue).Formula = "YearJoined";
                myExcelWorksheet.get_Range("I1", misValue).Formula = "Active";
                myExcelWorksheet.get_Range("J1", misValue).Formula = "MoneyOwed";
                //this changes the cell value in C2 to "New Value";

                myExcelWorkbook.Save();
                myExcelWorkbook.Close();
                Console.WriteLine("All Done :)");
                myExcelApp.Quit();

                /* FOR READING
                 * string cellFormulaAsString = myExcelWorksheet.get_Range("A2", misValue).Formula.ToString();
                 * //this puts the formula in Cell A2 or text depending whats in it in the string.
                 */
            }

            progressBar1.Increment(3);
            if (progressBar1.Value == 100)
            {
                System.Threading.Thread.Sleep(1000);
                this.Visible = false;
                login f2 = new login();
                f2.Show();
                timer1.Stop();
            }
        }