示例#1
0
        public async Task Creat_card(part part)
        {
            await Task.Run(() =>
            {
                var num = 1;

                var kanon = Ico.getValue <db>().GetUnivdb().parts.ToList().Where(p => p.Id == part.Id).ToList().FirstOrDefault().card_kanoni.ToList().FirstOrDefault();
                if (kanon != null)
                {
                    Ico.getValue <db>().GetUnivdb().card_kanoni.Remove(kanon);
                    var ca = Ico.getValue <db>().GetUnivdb().cards.ToList().Where(c => c.Id == kanon.id_card).ToList().FirstOrDefault();
                    if (ca != null)
                    {
                        num = ca.num;
                        Ico.getValue <db>().GetUnivdb().cards.Remove(ca);
                        Ico.getValue <db>().savedb();
                    }
                }
                var cardn = Ico.getValue <db>().GetUnivdb().cards.ToList().Where(c => c.id_prosess == part.Id_Pro && c.year == Ico.getValue <Date>().GetNowDate().Id).OrderByDescending(c => c.num).ToList().FirstOrDefault();
                if (num == 1)
                {
                    if (cardn != null)
                    {
                        num = cardn.num + 1;
                    }
                }



                var d    = DateTime.Now;
                var name = "بطاقة إلتزام قانوني رقم " + num + " سنة " + d.Year;

                var card = new card()
                {
                    id_prosess = part.process.Id,
                    year       = Ico.getValue <Date>().GetNowDate().Id,
                    num        = num,
                    location   = Ico.getValue <IO>().CREATE_F_kanoni(part.process.location) + "\\" + name,
                    date       = DateTime.Now,
                };
                var kanoni = new card_kanoni()
                {
                    card      = card,
                    id_client = client.Id,
                    id_part   = part.Id,
                    cost      = part.Cost,
                    visa      = null
                };

                Ico.getValue <db>().GetUnivdb().cards.Add(card);
                Ico.getValue <db>().GetUnivdb().card_kanoni.Add(kanoni);
                Ico.getValue <db>().savedb();
                Card_kanoniExecl card_Kanoni = new Card_kanoniExecl(Ico.getValue <db>().GetUnivdb().card_kanoni.ToList().Where(c => c.id_part == part.Id).ToList().FirstOrDefault());
                card_Kanoni.CreateCard();

                Ico.getValue <ContentApp>().CancelSample4Dialog();
            });
        }
        public AddpartCardViewModel(part part, Action accept, Action Cancel)
        {
            this.namepart    = part.Name;
            this.cost        = part.Cost;
            this.nameprocess = part.process.Name;
            this.part        = part;
            clients          = Ico.getValue <db>().GetUnivdb().clients.ToList();

            savecommand = new Command(() => {
                accept();
                Task.Run(() => {
                    var cardn = Ico.getValue <db>().GetUnivdb().cards.ToList().Where(c => c.id_prosess == part.Id_Pro && c.year == Ico.getValue <Date>().GetNowDate().Id).OrderByDescending(c => c.num).ToList().FirstOrDefault();
                    var num   = 1;
                    if (cardn != null)
                    {
                        num = cardn.num + 1;
                    }


                    var d    = DateTime.Now;
                    var name = "بطاقة إلتزام قانوني رقم " + num + " سنة " + d.Year;

                    var card = new card()
                    {
                        id_prosess = part.process.Id,
                        year       = Ico.getValue <db>().GetUnivdb().years.ToList().LastOrDefault().Id,
                        num        = num,
                        location   = Ico.getValue <IO>().CREATE_F_kanoni(part.process.location) + "\\" + name,
                        date       = DateTime.Now,
                    };
                    var kanoni = new card_kanoni()
                    {
                        card      = card,
                        id_client = client.Id,
                        id_part   = part.Id,
                        cost      = part.Cost,
                        visa      = null
                    };

                    Ico.getValue <db>().GetUnivdb().cards.Add(card);
                    Ico.getValue <db>().GetUnivdb().card_kanoni.Add(kanoni);
                    Ico.getValue <db>().savedb();
                    Card_kanoniExecl card_Kanoni = new Card_kanoniExecl(Ico.getValue <db>().GetUnivdb().card_kanoni.ToList().Where(c => c.id_part == part.Id).ToList().FirstOrDefault());
                    card_Kanoni.CreateCard();

                    Cancel();
                });
            });
            Cancelcommand = new Command(() => {
                Cancel();
            });
            addclient = new Command(() => {
                Ico.getValue <ContentApp>().page = new AddClient();
            });
        }