Exemplo n.º 1
0
        public List <MobileVM> InPutDatabase()
        {
            MobaileArray = new List <MobileVM>();
            i            = 0;
            //foreach (var item in MobaileArray)
            //{
            //    MobaileArray.Remove(item);
            //}
            //MobaileArray.Clear();


            SqlQueryMobile SqlQueryMobileMod = new SqlQueryMobile();

            var MobileList = SqlQueryMobileMod.GetMobileList(UserId);


            foreach (var item in MobileList)
            {
                MobileVM vm = new MobileVM();
                vm.Number = item.Id;
                vm.Name   = item.Name;
                //vm.BrandName = item.BrandN.Name;
                vm.ProductionDate = item.ProductionDate;
                vm.Weight         = item.Weight;
                vm.Otg            = item.Otg;
                //vm.Networks = item.Network.Networks;

                SqlQueryBrand SQbrand = new SqlQueryBrand();
                var           Brand   = SQbrand.GetBrandName(item.BrandId);
                vm.BrandName = Brand.Name;

                SqlQueryNetworkMobile SQMobileNetwork = new SqlQueryNetworkMobile();
                var NetworkCl = SQMobileNetwork.GetMobileNetwork(item);
                vm.Networks = NetworkCl.Networks.ToArray();

                SqlQueryMobileImage SQMobileImage = new SqlQueryMobileImage();
                var ImageCl = SQMobileImage.GetMobileImage(item);
                vm.Image = new ImageMobile(ImageCl.ImageAddress);
                MobaileArray.Add(vm);
                i++;
                length = i;
            }
            return(MobaileArray);
        }
Exemplo n.º 2
0
        public void BuildMobile()
        {
            MobileVM MobileModel = new MobileVM();

            MobileModel.Networks = new NetworkEnum?[3];

            MobileModel.Networks[0] = G2;
            MobileModel.Networks[1] = G3;
            MobileModel.Networks[2] = G4;

            MobileModel.Name           = Name1;
            MobileModel.BrandName      = BrandName;
            MobileModel.ProductionDate = Convert.ToDateTime(dateTimePicker1.Text);
            MobileModel.Weight         = Weight;
            MobileModel.Otg            = Otg;

            if (i != length)
            {
                MobileModel.Image = new ImageMobile(MobaileArray[length].Image.FileNameAddress);
            }
            else
            {
                MobileModel.Image = new ImageMobile(MobileImage);
            }

            if (MobileModel.Name != "")
            {
                Mobile MobileDB = new Mobile();
                MobileDB.Name = MobileModel.Name;
                //MobileDB.BrandN = new Brand(MobileModel.BrandName);
                MobileDB.ProductionDate = MobileModel.ProductionDate;
                MobileDB.Weight         = MobileModel.Weight;
                MobileDB.Otg            = MobileModel.Otg;

                Brand brandDB = new Brand();
                brandDB.Name = MobileModel.BrandName;

                Network NetworkDB = new Network();
                NetworkDB = new Network(MobileModel.Networks);

                Database.Mobile.Image ImageDB = new Database.Mobile.Image();

                MobileModel.Image = new ImageMobile(MobileModel.Image.FileNameAddress);
                ImageDB           = new Database.Mobile.Image(MobileModel.Image.FileNameAddress);

                if (length == i)
                {
                    SqlQueryBrand SQbrand = new SqlQueryBrand();
                    MobileDB.BrandId = SQbrand.GetBrandId(brandDB);

                    SqlQueryMobile SQMobile = new SqlQueryMobile();
                    SQMobile.InsertMobile(MobileDB, UserId);

                    SqlQueryImage SQImage = new SqlQueryImage();
                    SQImage.InsertImage(ImageDB);

                    SqlQueryMobileImage SQMobileImage = new SqlQueryMobileImage();
                    SQMobileImage.InsertId(MobileDB, ImageDB);

                    if (NetworkDB.Networks[0].HasValue)
                    {
                        int G2 = 0;
                        SqlQueryNetworkMobile SQMobileNetwork = new SqlQueryNetworkMobile();
                        SQMobileNetwork.InsertId(MobileDB, NetworkDB, G2);
                    }
                    if (NetworkDB.Networks[1].HasValue)
                    {
                        int G3 = 1;
                        SqlQueryNetworkMobile SQMobileNetwork = new SqlQueryNetworkMobile();
                        SQMobileNetwork.InsertId(MobileDB, NetworkDB, G3);
                    }
                    if (NetworkDB.Networks[2].HasValue)
                    {
                        int G4 = 2;
                        SqlQueryNetworkMobile SQMobileNetwork = new SqlQueryNetworkMobile();
                        SQMobileNetwork.InsertId(MobileDB, NetworkDB, G4);
                    }
                    var Image  = SQImage.GetImage(ImageDB);
                    var Mobile = SQMobile.GetMobile(MobileDB);
                }
                else if (length != i)
                {
                    int id = MobaileArray[length].Number;
                    MobileDB.Id = id;
                    SqlQueryMobile SqlQueryMobileMod = new SqlQueryMobile();

                    SqlQueryBrand SQbrand = new SqlQueryBrand();
                    MobileDB.BrandId = SQbrand.GetBrandId(brandDB);

                    SqlQueryMobileMod.UpdateMobile(MobileDB, UserId);

                    SqlQueryMobileImage SQMI = new SqlQueryMobileImage();
                    var ImageinPut           = SQMI.GetMobileImage(MobileDB);

                    SqlQueryImage SQImage = new SqlQueryImage();
                    SQImage.UpdateImage(ImageDB, ImageinPut);

                    SqlQueryNetworkMobile SQNM = new SqlQueryNetworkMobile();
                    SQNM.DeleteNetwork(MobileDB);

                    if (NetworkDB.Networks[0].HasValue)
                    {
                        int G2 = 0;
                        SqlQueryNetworkMobile SQMobileNetwork = new SqlQueryNetworkMobile();
                        SQMobileNetwork.InsertId(MobileDB, NetworkDB, G2);
                    }
                    if (NetworkDB.Networks[1].HasValue)
                    {
                        int G3 = 1;
                        SqlQueryNetworkMobile SQMobileNetwork = new SqlQueryNetworkMobile();
                        SQMobileNetwork.InsertId(MobileDB, NetworkDB, G3);
                    }
                    if (NetworkDB.Networks[2].HasValue)
                    {
                        int G4 = 2;
                        SqlQueryNetworkMobile SQMobileNetwork = new SqlQueryNetworkMobile();
                        SQMobileNetwork.InsertId(MobileDB, NetworkDB, G4);
                    }
                    //MobaileArray = new List<MobileVM>();
                    //MobaileArray.Clear();
                    //MobaileArray[length] = MobileModel;
                    length = i;
                }
            }

            textBoxName.Clear();
            listBoxBrand.ClearSelected();
            textBoxWeight.Clear();
            buttonBack.Enabled    = true;
            buttonForward.Enabled = true;
            chBox2g.Checked       = false;
            chBox3g.Checked       = false;
            chBox4g.Checked       = false;
            chBoxOtg.Checked      = false;
            InPutDatabase();
        }