예제 #1
0
        private void UPDATEDATABASE()
        {
            database = new Database1Entities();

            clientDataGrid.ItemsSource = database.Clients.ToArray();

            //Select last selected clientrow
            if (lastSelectedItemId > -1)
            {
                if (database.Clients.Where(c => c.Id == lastSelectedItemId).FirstOrDefault() != null)
                {
                    var item = ((KFIRKK.Client[])clientDataGrid.ItemsSource).Where(c => c.Id == lastSelectedItemId).FirstOrDefault();
                    clientDataGrid.SelectedItem = item;
                }
            }
            SortEveryting();
        }
예제 #2
0
 private void WorkDelete_Click(object sender, RoutedEventArgs e)
 {
     if (workDataGrid.SelectedItem != null)
     {
         if (MessageBox.Show("האם אתה בטוח שאתה רוצה למחוק?", "אזהרה", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
         {
             using (Database1Entities database = new Database1Entities())
             {
                 var    id  = ((Work)workDataGrid.SelectedItem).Id;
                 Client c   = database.Works.Where(w => w.Id == id).FirstOrDefault().Client;
                 var    sum = database.Works.Where(w => w.Id == id).FirstOrDefault().PointsSum;
                 c.Units -= (double)sum;
                 database.Works.Remove(database.Works.Where(w => w.Id == id).FirstOrDefault());
                 database.SaveChanges();
                 UPDATEDATABASE();
                 UPDATEYEARLY();
             }
         }
     }
 }
예제 #3
0
        private void MenuItem_Click_1(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show("האם אתה בטוח שאתה רוצה למחוק?", "אזהרה", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
            {
                if (clientDataGrid.SelectedItem != null)
                {
                    int id = ((Client)clientDataGrid.SelectedItem).Id;
                    using (Database1Entities database = new Database1Entities())
                    {
                        var c = database.Clients.Where(w => w.Id == id).FirstOrDefault();
                        database.Logs.RemoveRange(c.Logs);
                        database.Works.RemoveRange(c.Works);
                        database.TransferLogs.RemoveRange(c.TransferLogs);
                        database.Clients.Remove(c);

                        database.SaveChanges();
                        UPDATEDATABASE();
                        UPDATEYEARLY();
                    }
                }
            }
        }
예제 #4
0
        private void UPDATEYEARLY()
        {
            using (Database1Entities database = new Database1Entities())
            {
                List <SumShnati> listDohShnati = new List <SumShnati>();
                for (int i = 0; i < 12; i++)
                {
                    var sDate   = new DateTime(year, i + 1, 1);
                    var eDate   = sDate.AddMonths(1).AddMinutes(-1);
                    var works   = database.Works.Where(w => w.Date >= sDate && w.Date <= eDate).ToArray();
                    var wCredit = 0m;
                    var wCash   = 0m;
                    foreach (var item in works)
                    {
                        //Tattoo
                        if (item.TattooPrice != null)
                        {
                            if (item.TattooPriceType != null)
                            {
                                if (item.TattooPriceType == false)
                                {
                                    wCash += item.TattooPrice.Value;
                                }
                                else
                                {
                                    wCredit += item.TattooPrice.Value;
                                }
                            }
                            else
                            {
                                wCash += item.TattooPrice.Value;
                            }
                        }
                        //Piercing
                        if (item.PiercingPrice != null)
                        {
                            if (item.PiercingPriceType != null)
                            {
                                if (item.PiercingPriceType == false)
                                {
                                    wCash += item.PiercingPrice.Value;
                                }
                                else
                                {
                                    wCredit += item.PiercingPrice.Value;
                                }
                            }
                            else
                            {
                                wCash += item.PiercingPrice.Value;
                            }
                        }

                        //Misha
                        if (item.MishaPrice != null)
                        {
                            if (item.MishaPriceType != null)
                            {
                                if (item.MishaPriceType == false)
                                {
                                    wCash += item.MishaPrice.Value;
                                }
                                else
                                {
                                    wCredit += item.MishaPrice.Value;
                                }
                            }
                            else
                            {
                                wCash += item.MishaPrice.Value;
                            }
                        }
                        //Neckle
                        if (item.NecklePrice != null)
                        {
                            if (item.NecklePriceType != null)
                            {
                                if (item.NecklePriceType == false)
                                {
                                    wCash += item.NecklePrice.Value;
                                }
                                else
                                {
                                    wCredit += item.NecklePrice.Value;
                                }
                            }
                            else
                            {
                                wCash += item.NecklePrice.Value;
                            }
                        }
                    }

                    //Add row to list
                    listDohShnati.Add(new SumShnati()
                    {
                        date        = sDate,
                        t           = works.Where(w => w.TattooCount != 0 && w.TattooCount != null).Select(w => (int)w.TattooCount).Sum(),
                        tprice      = works.Where(w => w.TattooPrice != 0 && w.TattooPrice != null).Select(w => (int)w.TattooPrice).Sum(),
                        p           = works.Where(w => w.PiercingCount != 0 && w.PiercingCount != null).Select(w => (int)w.PiercingCount).Sum(),
                        pprice      = works.Where(w => w.PiercingPrice != 0 && w.PiercingPrice != null).Select(w => (int)w.PiercingPrice).Sum(),
                        m           = works.Where(w => w.MishaCount != 0 && w.MishaCount != null).Select(w => (int)w.MishaCount).Sum(),
                        mprice      = works.Where(w => w.MishaPrice != 0 && w.MishaPrice != null).Select(w => (int)w.MishaPrice).Sum(),
                        n           = works.Where(w => w.NeckleCount != 0 && w.NeckleCount != null).Select(w => (int)w.NeckleCount).Sum(),
                        nprice      = works.Where(w => w.NecklePrice != 0 && w.NecklePrice != null).Select(w => (int)w.NecklePrice).Sum(),
                        credit      = wCredit,
                        cash        = wCash,
                        alltogather = wCash + wCredit,
                    });
                }

                //Update datagrid
                dg.ItemsSource = listDohShnati.ToArray();
                dg.Items.Refresh();
            }
        }