Exemple #1
0
        /// <summary>
        /// Method implements delete functionality.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void DeleteRow(object sender, DoWorkEventArgs e)
        {
            Thread.Sleep(2000);
            if (row == null)
            {
                return;
            }
            foreach (var m in MainWindowViewModels)
            {
                if (m.Employee.Manager.Id == row.Employee.Id)
                {
                    m.Employee.Manager = null;
                }
            }
            var con = new SqlConnection(ConnectionString);

            con.Open();
            var cmd = new SqlCommand("delete from tblEmployee where EmployeeID = @EmployeeID;", con);

            cmd.Parameters.AddWithValue("@EmployeeID", row.Employee.Id);
            cmd.ExecuteNonQuery();
            LogActions.LogDeleteEmployee(row.Employee);
            //Object is removed from ongoing list.
            App.Current.Dispatcher.Invoke((Action) delegate
            {
                MainWindowViewModels.Remove(row);
            });
            con.Close();
            con.Dispose();
            var messageBoxResult = System.Windows.MessageBox.Show("Delete Successfull", "Notification");
        }
        public Alternation1()
        {
            InitializeComponent();
            ViewModel = Resources["ViewModels"] as MainWindowViewModels;

            if (ViewModel == null)
            {
                throw new NullReferenceException("ViewModels 不可以为 NULL");
            }
        }
Exemple #3
0
        public MainWindow()
        {
            InitializeComponent();

            var image      = new BitmapImage(new Uri("/Resources/dog.jpg", UriKind.Relative));
            var viewModels = new MainWindowViewModels()
            {
                Image = image,
            };

            this.DataContext = viewModels;
        }
        public MainWindow()
        {
            InitializeComponent();

            DataContext = new MainWindowViewModels();

            SampleTreeView.AllowDrop = true;
            SampleTreeView.PreviewMouseLeftButtonDown += SampleTreeViewOnPreviewMouseLeftButtonDown;
            SampleTreeView.PreviewMouseLeftButtonUp   += SampleTreeViewOnPreviewMouseLeftButtonUp;
            SampleTreeView.PreviewMouseMove           += SampleTreeViewOnPreviewMouseMove;
            SampleTreeView.Drop     += SampleTreeViewOnDrop;
            SampleTreeView.DragOver += SampleTreeViewOnDragOver;
        }
Exemple #5
0
        /// <summary>
        /// A method that consolidates a viewmodel
        /// Default Mode, 1 item to 1 item
        /// </summary>
        /// <param name="model">
        /// Target viewmodel to be consolidated
        /// </param>
        public static void Consolidate(MainWindowViewModels model)
        {
            foreach (LedgerItem bankitem in model.BankLedger)
            {
                foreach (LedgerItem companyitem in model.CompanyLedger)
                {
                    //Console.WriteLine("正在比较");
                    //Console.WriteLine(bankitem);
                    //Console.WriteLine(companyitem);
                    if (companyitem.Paired) //如果已经被同步了,跳过。
                    {
                        continue;
                    }
                    if (
                        (Math.Abs(bankitem.DebitRemain - companyitem.DebitRemain) < 0.00001d)
                        )
                    { //如果两者的差值小于0.00001则视为一样
                        ConsolidatedPair pair = new ConsolidatedPair(
                            new ObservableCollection <LedgerItem> {
                            companyitem
                        },
                            new ObservableCollection <LedgerItem> {
                            bankitem
                        });                                //
                        model.MatchedCollection.Add(pair); //添加
                        //model.BankLedger.Remove(bankitem); //删减 ! 在循环中不可以修改被循环集合的内容
                        //model.BankLedger.Remove(companyitem); //删减
                        //TODO: 需要在 LedgerItem 中添加两个属性,第一个贷方余额,第二个是 paired 布尔函数。
                        companyitem.Paired = true;
                        bankitem.Paired    = true;
                    }
                }
            }
            //清理所有Paired为true的对象
            var bankitemNotPaired = from i in model.BankLedger
                                    where i.Paired = true
                                                     select i;

            for (int i = 0; i < bankitemNotPaired.Count(); i++)
            {
                model.BankLedger.Remove(bankitemNotPaired.ToArray()[i]);
            }
            var companyitemNotPaired = from i in model.CompanyLedger
                                       where i.Paired = true
                                                        select i;

            for (int i = 0; i < companyitemNotPaired.Count(); i++)
            {
                model.CompanyLedger.Remove(companyitemNotPaired.ToArray()[i]);
            }
        }
Exemple #6
0
        private async void App_OnStartup(object sender, StartupEventArgs e)
        {
            CancellationTokenSource cancellationTokenSource = new();
            InformWindowViewModels  informVm = new(cancellationTokenSource);

            informVm.ExitAppEvent += InformVM_ExitAppEvent;
            InformationWindow informWindows = new()
            {
                DataContext = informVm
            };

            informWindows.Show();
            ConnectionServiceClient client      = new();
            UserServiceClient       userService = new();
            MuvoServiceClient       muvo        = new();

            ListMuvo = await MuvoServiceClient.GetMuvoList(cancellationTokenSource.Token);

            MainWindow main = new()
            {
                DataContext = new MainWindowViewModels
                {
                    ConnectionStatus = await client.ConnectionCheck(cancellationTokenSource.Token),
                    UserStatus       = (await UserServiceClient.GetStatusUser
                                            (cancellationTokenSource.Token)).ToString("G")
                }
            };

            main.Show();
            informWindows.Close();
        }

        private void InformVM_ExitAppEvent()
        {
            Shutdown(0);
        }
    }
Exemple #7
0
        /// <summary>
        /// Method for filling out previously mentioned collection
        /// </summary>
        public void FillList()
        {
            using (SqlConnection conn = new SqlConnection(ConnectionString))
            {
                SqlCommand query = new SqlCommand("select * from tblEmployee e " +
                                                  "join tblLocation l on e.LocationID = l.LocationID " +
                                                  "join tblSector s on e.SectorID = s.SectorID", conn);
                conn.Open();
                SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(query);
                DataTable      dataTable      = new DataTable();
                sqlDataAdapter.Fill(dataTable);

                if (MainWindowViewModels == null)
                {
                    MainWindowViewModels = new ObservableCollection <MainWindowModel>();
                }

                foreach (DataRow row in dataTable.Rows)
                {
                    MainWindowModel m = new MainWindowModel
                    {
                        Employee = new Employee
                        {
                            Id                 = int.Parse(row[0].ToString()),
                            FirstName          = row[1].ToString(),
                            LastName           = row[2].ToString(),
                            JMBG               = row[3].ToString(),
                            DateOfBirth        = DateTime.Parse(row[4].ToString()),
                            Gender             = char.Parse(row[5].ToString()),
                            RegistrationNumber = row[6].ToString(),
                            PhoneNumber        = row[7].ToString(),
                            Manager            = new Employee()
                        },
                        Location = new Location
                        {
                            Id      = int.Parse(row[11].ToString()),
                            Adress  = row[12].ToString(),
                            Town    = row[13].ToString(),
                            Country = row[14].ToString()
                        },
                        Sector = new Sector
                        {
                            Id    = int.Parse(row[15].ToString()),
                            Title = row[16].ToString()
                        },
                        ManagerId = int.Parse(row[10].ToString())
                    };
                    m.Employee.Location = m.Location;
                    m.Employee.Sector   = m.Sector;
                    MainWindowViewModels.Add(m);
                    employees.Add(m.Employee);
                }
            }
            //Loop added to ensure each employee gets a manager if it has one.
            foreach (var m in MainWindowViewModels)
            {
                foreach (Employee e in employees)
                {
                    if (m.ManagerId == e.Id)
                    {
                        m.Employee.Manager = e;
                    }
                }
            }
        }