Exemple #1
0
        private void SaveCraft()
        {
            int    i;
            string sx, ssx;

            if (sn == "")
            {
                if (iy != 0)
                {
                    sn = $"Model of {iy} y.";
                }
                else
                {
                    if ((stt.IndexOf("SEE") < 0) && (stt.Trim() != "") && was_year)
                    {
                        sn = "???";
                    }
                }
            }

            if (sn == "")
            {
                ResetCraft();
            }
            else
            {
                ssx = ReadLn2();
                sx  = ssx.ToUpper();
                if (sx.IndexOf("</TABLE>") < 0)
                {
                    GFileI--;
                    cnt++;
                    var craft = new Crafts()
                    {
                        Source = "5"
                    };
                    if (iy == 0)
                    {
                        ss = stt;
                        i  = (" " + ss + "  ").IndexOf("19");
                        if (i < 0)
                        {
                            i = (" " + ss + "  ").IndexOf("20");
                        }
                        while (i >= 0)
                        {
                            if (
                                IsDigit(ss[i + 1]) &&
                                IsDigit(ss[i + 2]) &&
                                (!IsDigit(ss[i - 2])) &&
                                (!IsDigit(ss[i + 3])))
                            {
                                iy = int.Parse(ss.Substring(i - 1, 4));
                                if ((iy > 1902) && (iy < 2010))
                                {
                                    craft.IYear = iy;
                                    break;
                                }
                            }
                            ss = ss.Substring(i);
                            i  = (" " + ss + "  ").IndexOf("19");
                            if (i < 0)
                            {
                                i = (" " + ss + "  ").IndexOf("20");
                            }
                        }
                    }
                    else
                    {
                        craft.IYear = iy;
                    }
                    craft.Construct = sc1;
                    craft.Name      = sn.Length > 100 ? sn.Substring(0, 100) : sn;
                    //FieldByName("Country").AsString := "США";
                    craft.CText = stt.Trim();
                    _ctx.Crafts.Add(craft);
                    _ctx.SaveChanges();

                    for (i = 0; i < ls.Count; i++)
                    {
                        if (File.Exists($"{imagesPath}Images5\\{lp[i]}"))
                        {
                            var p = new Pics()
                            {
                                CraftId = craft.CraftId,
                                ArtId   = artId,
                                Path    = lp[i],
                                Text    = ls[i]
                            };
                            _ctx.Pics.Add(p);
                        }
                    }
                    _ctx.SaveChanges();
                    ResetCraft();
                }
            }
        }
Exemple #2
0
        public void LoadOld(AiKEntities ctx, string _imagesPath, Label lInfo)
        {
            if (!(MessageBox.Show("Load 3-4?", "Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes))
            {
                return;
            }

            ctx.Database.ExecuteSqlCommand("Delete from Pics where CraftId in (Select CraftId from Crafts where Source in ('3', '4'))");
            ctx.Database.ExecuteSqlCommand("Delete from Crafts where Source in ('3', '4')");

            var text3 = File.ReadAllText("E:\\Live\\Avia\\Text3.dat", Encoding.GetEncoding("windows-1251"));
            var text4 = File.ReadAllText("E:\\Live\\Avia\\Text4.dat", Encoding.GetEncoding("windows-1251"));

            var artId3 = ctx.Arts.Where(x => x.Mag == "Site3").Single().ArtId;
            var artId4 = ctx.Arts.Where(x => x.Mag == "Site4").Single().ArtId;

            var cnt    = 0;
            var crafts = ctx.CraftsOld.Where(x => x.Source == 3 || x.Source == 4).ToList();

            foreach (var craft in crafts)
            {
                lInfo.Text = (++cnt).ToString();
                Application.DoEvents();

                var newCraft = new Crafts()
                {
                    Construct = craft.Construct,
                    Name      = craft.Name,
                    Country   = craft.Country,
                    IYear     = craft.IYear,
                    Vert      = craft.Vert,
                    Uav       = craft.UAV,
                    Glider    = craft.Glider,
                    Source    = craft.Source.ToString(),
                    Type      = craft.Type
                };
                if ((craft.TxtBeg ?? 0) > 0)
                {
                    newCraft.CText = (craft.Source == 3 ? text3 : text4).Substring(craft.TxtBeg.Value, craft.TxtEnd.Value - craft.TxtBeg.Value);
                }
                ctx.Crafts.Add(newCraft);
                ctx.SaveChanges();

                var prms = ctx.ParamsOld.Where(x => x.CraftId == craft.ID).ToList();
                if (prms.Any())
                {
                    var s = "\n\n";
                    foreach (var prm in prms)
                    {
                        s += $"\n{prm.ParamName}\t{prm.ParamData}";
                    }
                    newCraft.CText += s;
                }

                var pics = ctx.PicsOld.Where(x => x.CraftID == craft.ID).ToList();
                foreach (var pic in pics)
                {
                    var newPic = new Pics()
                    {
                        ArtId   = craft.Source == 3 ? artId3 : artId4,
                        CraftId = newCraft.CraftId,
                        NNN     = pic.PictID,
                        Path    = pic.Picture
                    };
                    if ((pic.TxtBeg ?? 0) > 0)
                    {
                        newPic.Text = (craft.Source == 3 ? text3 : text4).Substring(pic.TxtBeg.Value, pic.TxtEnd.Value - pic.TxtBeg.Value);
                    }
                    ctx.Pics.Add(newPic);
                }
                ctx.SaveChanges();

                Util.DetachAllEntities(ctx);
            }

            lInfo.Text = "";
            MessageBox.Show("OK");
        }
Exemple #3
0
        public void Load1(AiKEntities ctx, string _imagesPath, Label lInfo)
        {
            _lInfo = lInfo;
            if (!(MessageBox.Show("Load Airwar?", "Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes))
            {
                return;
            }

            ctx.Database.ExecuteSqlCommand("Delete From dbo.WordLinks From dbo.WordLinks wl join dbo.Pics p on wl.PicId = p.PicId join dbo.Crafts c on c.CraftId = p.CraftId where c.Source = '1'");
            ctx.Database.ExecuteSqlCommand("Delete From dbo.WordLinks From dbo.WordLinks wl join dbo.Crafts c on c.CraftId = wl.CraftId where c.Source = '1'");
            ctx.Database.ExecuteSqlCommand("Delete From dbo.Pics From dbo.Pics p join dbo.Crafts c on c.CraftId = p.CraftId where c.Source = '1'");
            ctx.Database.ExecuteSqlCommand("Delete From dbo.Crafts where Source = '1'");
            ctx.Database.Connection.Close();
            ctx.Database.Connection.Open();

            var artId = ctx.Arts.Where(x => x.Name == "Airwar").Single().ArtId;

            using (var M = File.CreateText(_imagesPath + "Bads.txt"))
            {
                ls  = new List <string>();
                lc  = new List <string>();
                lcc = new List <string>();
                lct = new List <string>();
                string sName;
                int    i, j;

                var dirs = Directory.GetDirectories(_imagesPath + "Source1\\Pages\\enc", "*.");
                foreach (var dir in dirs)
                {
                    var files = Directory.GetFiles(dir, "*.html");
                    foreach (var file in files)
                    {
                        _lInfo.Text = file;
                        Application.DoEvents();
                        try
                        {
                            s = File.ReadAllText(file, Encoding.GetEncoding("KOI8-R"));
                            lc.Clear();
                            lcc.Clear();
                            lct.Clear();
                            su = s.ToUpper();
                            i  = s.IndexOf("flags_small");
                            if (i < 0)
                            {
                                M.WriteLine($"No flag_small: {file}");
                                continue;
                            }
                            TrimAll(i);
                            i = s.IndexOf(">");
                            TrimAll(i + 1);
                            i     = su.IndexOf("</TR");
                            sName = StrNoTags(s.Substring(0, i));
                            if (string.IsNullOrEmpty(sName))
                            {
                                M.WriteLine($"Bad name: {file}");
                                continue;
                            }
                            var craft = new Crafts()
                            {
                                Source = "1",
                                Name   = ClearString(sName)
                            };
                            var dirName = Path.GetFileName(dir).ToUpper();
                            if ((dirName.Length == 2 && dirName[1] == 'H') || dirName == "HELI")
                            {
                                craft.Vert = true;
                                //craft.Craft = False;
                            }
                            else
                            {
                                craft.Vert = false;
                                //craft.Craft = True;
                            }
                            if (dirName == "GLIDER")
                            {
                                craft.Uav    = false;
                                craft.Glider = true;
                                //craft.MM = False;
                            }
                            else if (dirName == "BPLA")
                            {
                                craft.Uav    = true;
                                craft.Glider = false;
                                //craft.MM = False;
                            }
                            else
                            {
                                craft.Uav    = false;
                                craft.Glider = false;
                                //craft.MM = True;
                            }

                            var k = su.IndexOf("<IMG SRC");
                            if (k < 0)
                            {
                                M.WriteLine($"Pic?: {file}");
                                ///!!!??? or continue???
                                continue;
                            }
                            var kk = su.IndexOf(".JPG", k);
                            var kl = su.IndexOf(".GIF", k);
                            if ((kk == 0) && (kl == 0))
                            {
                                M.WriteLine($"Pic??: {file}");
                                ///!!!??? or continue???
                                continue;
                            }
                            if ((kk > kl) || (kk < 0))
                            {
                                if (kl >= 0)
                                {
                                    kk = kl;
                                }
                            }
                            ss = s.Substring(k + 8, kk - k - 3);
                            ss = ss.Replace("\"", "");
                            k  = ss.ToUpper().IndexOf("/IMAGE/");
                            if (k < 0)
                            {
                                M.WriteLine($"Pic???: {file}");
                                ///!!!??? or continue???
                                continue;
                            }
                            ss = ss.Substring(k + 7);
                            ls.Add(ss);
                            lc.Add(ss);
                            lcc.Add("");
                            lct.Add("f");

                            i = s.IndexOf("Разработчик:");
                            if (i < 0)
                            {
                                M.WriteLine($"No construct: {file}");
                                continue;
                            }
                            TrimAll(i);
                            i = s.IndexOf("<");
                            TrimAll(i);
                            i     = su.IndexOf("</TR>");
                            sName = StrNoTags(s.Substring(0, i));
                            if (string.IsNullOrEmpty(sName))
                            {
                                M.WriteLine($"Bad construct: {file}");
                                continue;
                            }
                            craft.Construct = sName;
                            i = s.IndexOf("Страна:");
                            if (i < 0)
                            {
                                M.WriteLine($"No country: {file}");
                                continue;
                            }
                            TrimAll(i);
                            i = s.IndexOf("<");
                            TrimAll(i);
                            i     = su.IndexOf("</TR>");
                            sName = StrNoTags(s.Substring(0, i)).Trim();
                            if (string.IsNullOrEmpty(sName))
                            {
                                M.WriteLine($"Bad country: {file}");
                                continue;
                            }
                            if (sName.IndexOf(",") >= 0)
                            {
                                sName = "International";
                            }
                            if (sName.Length == 4)
                            {
                                if (sName[0] == sName[1] && sName[1] == sName[2])
                                {
                                    sName = "СССР";
                                }
                            }
                            if (sName.Length > 20)
                            {
                                M.WriteLine($"Too long country: {file}\n{sName}");
                                sName = sName.Substring(0, 20).Trim();
                            }
                            craft.Country = sName;
                            i             = s.IndexOf("Первый полет:");
                            if (i >= 0)
                            {
                                TrimAll(i);
                                i = s.IndexOf("<");
                                TrimAll(i);
                                i     = su.IndexOf("</TR>");
                                sName = StrNoTags(s.Substring(0, i));
                                if (!string.IsNullOrEmpty(sName))
                                {
                                    i = sName.IndexOf("?");
                                    if (i >= 0)
                                    {
                                        sName = sName.Substring(0, i);
                                        //FieldByName('YearBad').AsBoolean := True;
                                    }
                                    try
                                    {
                                        craft.IYear = int.Parse(sName);
                                    }
                                    catch { }
                                }
                            }
                            i = s.IndexOf("Тип:");
                            if (i < 0)
                            {
                                i = s.IndexOf("Type:");
                                if (i < 0)
                                {
                                    i = s.IndexOf("Тип :");
                                    if (i < 0)
                                    {
                                        i = s.IndexOf("Type :");
                                        if (i < 0)
                                        {
                                            M.WriteLine($"No type: {file}");
                                            //continue;
                                        }
                                    }
                                }
                            }
                            TrimAll(i);
                            i = s.IndexOf("<");
                            TrimAll(i);
                            i     = su.IndexOf("</TR>");
                            sName = StrNoTags(ClearString(s.Substring(0, i)));
                            if (string.IsNullOrEmpty(sName))
                            {
                                M.WriteLine($"Bad type: {file}");
                                //continue;
                            }
                            craft.Type = sName;
                            i          = su.IndexOf("<TABLE");
                            TrimAll(i);
                            i = su.IndexOf(">");
                            TrimAll(i + 1);
                            i = su.IndexOf("<TABLE");
                            TrimAll(i);
                            i = su.IndexOf(">");
                            TrimAll(i + 1);
                            i = su.IndexOf("<TABLE");
                            TrimAll(i);
                            i = su.IndexOf(">");
                            TrimAll(i + 1);
                            i = su.IndexOf("<TABLE");
                            if (i < 0)
                            {
                                M.WriteLine($"No text: {file}");
                                //continue;
                            }
                            text = DoWriteText(i);
                            while (true)
                            {
                                i     = su.IndexOf("<TABLE");
                                j     = su.IndexOf("</TABLE");
                                sName = su.Substring(0, j);
                                if (sName.IndexOf("TAB_CORNER_RIGHT.GIF") >= 0)
                                {
                                    break;
                                }
                                TrimAll(j);
                                i     = su.IndexOf("<TABLE");
                                text += DoWriteText(i);
                            }
                            while (i >= 0)
                            {
                                var finish = GetTable(0, M, file);
                                TrimAll(finish);
                                i = su.IndexOf("<TABLE", 0);
                            }
                            craft.CText = text;

                            ctx.Crafts.Add(craft);
                            ctx.SaveChanges();

                            for (i = 0; i < lc.Count; i++)
                            {
                                var pic = new Pics()
                                {
                                    //Source = "1"
                                    CraftId = craft.CraftId,
                                    ArtId   = artId,
                                    Path    = lc[i].Replace("/", "\\"),
                                    Type    = lct[i],
                                    NType   = Util.GetNType(lct[i])
                                };
                                ctx.Pics.Add(pic);
                                if (!string.IsNullOrEmpty(lcc[i]))
                                {
                                    pic.Text = WriteTextX(lcc[i]);
                                }
                                ctx.SaveChanges();
                            }
                            //MessageBox.Show("XXX!");
                            Util.DetachAllEntities(ctx);
                        }
                        catch (Exception e)
                        {
                            M.WriteLine($"Exception in {file}:\n{e.Message}");
                            //MessageBox.Show(file + "\n" + e.Message);
                        }
                    }
                }
            }
            _lInfo.Text = "";
            MessageBox.Show("OK!");
        }