Пример #1
0
        public ViewModel()
        {
            addDataEMP();

            AddCommandSubdivision = new DelegateCommand <List <object> >(i =>
            {
                int id            = (i[0].ToString() != "") ? Convert.ToInt32(i[0]) : 1;
                string name       = i[1].ToString();
                Employee employee = (i[2] != null) ? (Employee)i[2] : null;

                if (name.ToString().Trim() != "")
                {
                    subdivision.AddValueToDB(id, name, employee);
                    subdivision.AddValue(id, name, employee);
                    addDataEMP();
                }
            });
            RemoveCommandSubdivision = new DelegateCommand <List <object> >(i =>
            {
                if ((int)i[0] != -1)
                {
                    int index = (int)i[0];
                    int id    = Convert.ToInt32(i[1]);

                    subdivision.RemoveValueInDB(index, id);
                    subdivision.RemoveValue(index);
                    addDataEMP();
                }
            });
            ChangeCommandSubdivision = new DelegateCommand <List <object> >(i =>
            {
                if ((int)i[0] != -1)
                {
                    int index         = (int)i[0];
                    int id            = Convert.ToInt32(i[1]);
                    string name       = (i[2].ToString().Trim() != "") ? i[2].ToString() : "";
                    Employee employee = (i[3] != null) ? (Employee)i[3] : null;

                    if (name.Trim() != "")
                    {
                        subdivision.ChangeValueInDB(index, id, name, employee);
                        subdivision.ChangeValue(index, id, name, employee);
                        addDataEMP();
                    }
                }
            });



            RemoveCommandEmployee = new DelegateCommand <List <object> >(i =>
            {
                if ((int)i[0] != -1)
                {
                    int index = (int)i[0];
                    int id    = Convert.ToInt32(i[1]);

                    employee.RemoveValueInDB(index, id);
                    employee.RemoveValue(index);
                    addDataEMP();
                }
            });
            ChangeCommandEmployee = new DelegateCommand <List <object> >(i =>
            {
                if ((int)i[0] != -1)
                {
                    int index               = (int)i[0];
                    int id                  = Convert.ToInt32(i[1]);
                    string name             = (i[2].ToString().Trim() != "") ? i[2].ToString() : "";
                    string lastName         = (i[3].ToString().Trim() != "") ? i[3].ToString() : "";
                    string secondName       = (i[4].ToString().Trim() != "") ? i[4].ToString() : "";
                    DateTime birthDate      = (i[5] != null) ? (DateTime)i[5] : DateTime.MinValue;
                    Enum gender             = (i[6] != null) ? (Gender)i[6] : (Enum)None.none;
                    Subdivision subdivision = (i[7] != null) ? (Subdivision)i[7] : null;

                    if (name.Trim() != "" && lastName.Trim() != "" && secondName.Trim() != "" && birthDate != DateTime.MinValue && subdivision != null)
                    {
                        employee.ChangeValueInDB(index, id, name, lastName, secondName, birthDate, (Gender)gender, subdivision);
                        employee.ChangeValue(index, id, name, lastName, secondName, birthDate, (Gender)gender, subdivision);
                        addDataEMP();
                    }
                }
            });
            AddCommandEmployee = new DelegateCommand <List <object> >(i =>
            {
                int id                  = (i[0].ToString() != "") ? Convert.ToInt32(i[0]) : 1;
                string name             = (i[1].ToString().Trim() != "") ? i[1].ToString() : "";
                string lastName         = (i[2].ToString().Trim() != "") ? i[2].ToString() : "";
                string secondName       = (i[3].ToString().Trim() != "") ? i[3].ToString() : "";
                DateTime birthDate      = (i[4] != null) ? (DateTime)i[4] : DateTime.MinValue;
                Enum gender             = (i[5] != null) ? (Gender)i[5] : (Enum)None.none;
                Subdivision subdivision = (i[6] != null) ? (Subdivision)i[6] : null;

                if (name.Trim() != "" &&
                    lastName.Trim() != "" &&
                    secondName.Trim() != "" &&
                    birthDate != DateTime.MinValue &&
                    //Enum.IsDefined(typeof(Gender), i[4]) &&
                    subdivision != null)
                {
                    employee.AddValueToDB(name, lastName, secondName, birthDate, (Gender)gender, subdivision);
                    employee.AddValue(id, name, lastName, secondName, birthDate, (Gender)gender, subdivision);
                    addDataEMP();
                }
            });
        }