示例#1
0
        private void btnAdminAddUser_Click(object sender, EventArgs e)
        {
            myDel methods = RechargeGDV;

            methods += ResetTxt;

            try
            {
                string   name             = txtAdminName.Text;
                string   lastName         = txtAdminLname.Text;
                string   pass             = txtAdminPass.Text;
                string   dui              = txtAdminDUI.Text;
                DateTime dateTime         = dtpAdminBirth.Value;
                string   sqlFormattedDate = dateTime.ToString("yyyy-MM-dd");
                int      dept             = cmbAdminDept.SelectedIndex + 1;

                if (name.Equals("") || pass.Equals("") || dui.Equals(""))
                {
                    MessageBox.Show("Asegúrese de ingresar correctamente la información.");
                }
                else
                {
                    UserDAO.CreateUser(pass, name, lastName, dui, sqlFormattedDate, dept);
                    MessageBox.Show("Usuario creado correctamente.\nAsegúrese de guardar la contraseña.");
                    methods.Invoke();
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show("Asegúrese de ingresar correctamente la información.");
            }
        }
示例#2
0
        public void DoEvent(string Address)
        {
            Random rnd = new Random();

            FireDel?.Invoke("Вызов принят", DateTime.Now);
            FireDel?.Invoke("Бригада выехала на ", DateTime.Now);
            for (int i = 0; i < rnd.Next(10, 30); i++)
            {
                Thread.Sleep(50);
                Console.Write(".");
            }
            Console.WriteLine("");
            FireDel?.Invoke("Бригада приехала", DateTime.Now);
            for (int i = 0; i < rnd.Next(10, 30); i++)
            {
                Thread.Sleep(50);
                Console.Write(".");
            }
            Console.WriteLine("");
            FireDel?.Invoke("Пожар потушен ", DateTime.Now);
        }
示例#3
0
        delegate void Operation(int num); //method that returns void and receive a number

        static void Main(string[] args)
        {
            myDel del = new myDel(sayHello);

            //how to invoke delegate:
            del.Invoke(); //will invoke sayHello
            //syntax sugar of above
            myDel del2 = sayHello;

            del2(); //instead of invoke
            //how to chaindelegates
            Operation op = Double;

            op += Triple; //concat also the triple method
            op(2);        //will invoke Double and Triple

            /*
             * ======================================
             * Anonymous Methods & Lambda Expressions
             * ======================================
             */
            Operation op2 = (num) => { Console.WriteLine(num); };//sugar syntax that let us avoid form declaring a method

            /*
             * ======================================
             * Generic Delegates
             * ======================================
             */
            //- Let us avoid of declaring a Delegate Type  (for ex as we declared above Operation and myDel types)
            //Action - doesn't have a return value
            Action <int> action;//can contain methods that doesnt return value and has int as input

            action = Double;
            action(2);               //will print 4
            action += Triple;        //concating another method
            action(3);               //will print 6 and then 9
            //Func - does have return value
            Func <int, string> func; //can contain methods that return string value and has int as input

            func = (int num) => { return(num.ToString()); };
            //action and func can have many inputs as we want
            Action <int, string, double> action2 = (num, s, d) => Console.WriteLine($"{num}{s}{d}");;

            Console.ReadKey();
        }
示例#4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter a number:");
            int number = 0;

            try {
                string num = Console.ReadLine();
                number = Convert.ToInt32(num);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine("Hello World!");

            myDel addd = (x) => x + 10;

            Console.WriteLine($"The number {number} plus 10  is {addd.Invoke(number)}");

            myDel power = delegate(int x) { return(Math.Pow(x, 10)); };

            Console.WriteLine($"The number {number} to power 10 is {power.Invoke(number)}");
        }