예제 #1
0
        private void lstQueue_MouseDown(object sender, MouseEventArgs e)
        {
            var item = lstQueue.GetItemAt(e.X, e.Y);

            if (item != null)
            {
                if (e.Button == MouseButtons.Right)
                {
                    var     orders = (IEnumerable <IConstructionOrder>)item.Tag;
                    var     order  = orders.First();                // all condensed orders should be for same template anyway
                    Control report = null;
                    string  title  = null;
                    if (order.Template is IDesign)
                    {
                        var design = (IDesign)order.Template;
                        report = new DesignReport(design);
                        title  = design.Name;
                    }
                    else if (order.Template is FacilityTemplate)
                    {
                        var ft = (FacilityTemplate)order.Template;
                        report = new FacilityReport(ft);
                        title  = ft.Name;
                    }

                    if (report != null)
                    {
                        var form = report.CreatePopupForm(title);
                        this.ShowChildForm(form);
                    }
                }
            }
        }
예제 #2
0
        private void lstUpgrades_MouseDown(object sender, MouseEventArgs e)
        {
            var item = lstUpgrades.GetItemAt(e.X, e.Y);

            if (item != null)
            {
                if (e.Button == MouseButtons.Left)
                {
                    // how many to add?
                    var amount = 1;
                    if (ModifierKeys.HasFlag(Keys.Shift))
                    {
                        amount *= 10;
                    }
                    if (ModifierKeys.HasFlag(Keys.Control))
                    {
                        amount *= 100;
                    }

                    var upgrade = (FacilityUpgrade)item.Tag;

                    for (int i = 0; i < amount; i++)
                    {
                        var order = new UpgradeFacilityOrder(upgrade);
                        ConstructionQueue.Orders.Add(order);
                        var cmd = new AddOrderCommand
                                  (
                            ConstructionQueue,
                            order
                                  );
                        newCommands.Add(cmd);
                    }
                    BindQueueListView();
                    IEnumerable <FacilityTemplate> templates;
                    if (chkOnlyLatest.Checked)
                    {
                        templates = Empire.Current.UnlockedItems.OfType <FacilityTemplate>().Where(f => f.Cost.Any()).OnlyLatestVersions(f => f.Family);
                    }
                    else
                    {
                        templates = Empire.Current.UnlockedItems.OfType <FacilityTemplate>().Where(f => f.Cost.Any());
                    }
                    BindUpgradeListView(templates);
                }
                else if (e.Button == MouseButtons.Right)
                {
                    var facil  = (FacilityUpgrade)item.Tag;
                    var report = new FacilityReport(facil);
                    var form   = report.CreatePopupForm(facil.New.Name);
                    FindForm().ShowChildForm(form);
                }
            }
        }
예제 #3
0
        private void lstFacilities_MouseDown(object sender, MouseEventArgs e)
        {
            var item = lstFacilities.GetItemAt(e.X, e.Y);

            if (item != null)
            {
                if (e.Button == MouseButtons.Left)
                {
                    // how many to add?
                    var amount = 1;
                    if (ModifierKeys.HasFlag(Keys.Shift))
                    {
                        amount *= 10;
                    }
                    if (ModifierKeys.HasFlag(Keys.Control))
                    {
                        amount *= 100;
                    }

                    var template = (FacilityTemplate)item.Tag;
                    for (int i = 0; i < amount; i++)
                    {
                        var order = new ConstructionOrder <Facility, FacilityTemplate> {
                            Template = template
                        };
                        ConstructionQueue.Orders.Add(order);
                        var cmd = new AddOrderCommand
                                  (
                            ConstructionQueue,
                            order
                                  );
                        newCommands.Add(cmd);
                    }
                    BindQueueListView();
                }
                else if (e.Button == MouseButtons.Right)
                {
                    var facil  = (FacilityTemplate)item.Tag;
                    var report = new FacilityReport(facil);
                    var form   = report.CreatePopupForm(facil.Name);
                    FindForm().ShowChildForm(form);
                }
            }
        }
        public ActionResult DownloadAllFacility([Bind(Include = "Region")] Facility facility)
        {
            if (string.IsNullOrEmpty(facility.Region))
            {
                ModelState.AddModelError("", "Please Select Region.");
                return(View(facility));
            }
            FacilityReport  facilityReport = new FacilityReport();
            ApplicationUnit unit           = new ApplicationUnit();

            List <Model.Facility> dbFacilities = unit.Facilities.GetAll()
                                                 .Include(b => b.Buildings)
                                                 .Include(d => d.DeedsInfo)
                                                 .Include(p => p.ResposiblePerson)
                                                 .Include("Location.GPSCoordinates")
                                                 .Include("Location.BoundryPolygon")
                                                 .Where(ss => ss.Status == "Submitted" && ss.Location.Region.Trim().ToLower() == facility.Region.Trim().ToLower())
                                                 .ToList();

            if (dbFacilities.Count() == 0)
            {
                ModelState.AddModelError("", "No Facilities Found For Selected Region.");
                return(null);
            }
            else
            {
                using (var memoryStream = new MemoryStream())
                {
                    using (ZipArchive ziparchive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true))
                    {
                        foreach (var item in dbFacilities)
                        {
                            Model.OriginalData dbOriginalData = unit.OriginalDatas.GetAll().Where(o => o.VENUS_CODE.Trim().ToLower() == item.ClientCode.Trim().ToLower()).FirstOrDefault();
                            string             filePath       = facilityReport.GenerateFacilityReport(item, dbOriginalData);
                            ziparchive.CreateEntryFromFile(filePath, item.ClientCode + ".pdf");
                        }
                    }
                    DeleteAllFile();
                    return(File(memoryStream.ToArray(), "application/zip", "facilities.zip"));
                }
            }
        }
        // GET: Facility/Edit/5
        //[HttpPost]
        //[ValidateAntiForgeryToken]
        public ActionResult DownloadFacility(string clientCode)
        {
            FacilityReport  facilityReport = new FacilityReport();
            ApplicationUnit unit           = new ApplicationUnit();

            Model.Facility dbFacility = unit.Facilities.GetAll()
                                        .Include(b => b.Buildings)
                                        .Include(d => d.DeedsInfo)
                                        .Include(c => c.Portfolio)
                                        .Include(p => p.ResposiblePerson)
                                        .Include("Location.GPSCoordinates")
                                        .Include("Location.BoundryPolygon")
                                        .Where(f => f.ClientCode.ToLower() == clientCode.ToLower()).FirstOrDefault();
            if (dbFacility == null)
            {
                return(RedirectToAction("Index"));
            }

            Model.OriginalData dbOriginalData = unit.OriginalDatas.GetAll()
                                                .Where(o => o.VENUS_CODE.Trim().ToLower()
                                                       == dbFacility.ClientCode.Trim().ToLower())
                                                .FirstOrDefault();

            string filePath = facilityReport.GenerateFacilityReport(dbFacility, dbOriginalData);

            using (var webClient = new WebClient())
            {
                if (!System.IO.File.Exists(filePath))
                {
                    return(null);
                }
                byte[] file = webClient.DownloadData(filePath);
                DeleteAllFile();
                return(File(file, MediaTypeNames.Application.Pdf));
            }
        }
예제 #6
0
        private static void GenerateReport()
        {
            FacilityReport  facilityReport = new FacilityReport();
            ApplicationUnit unit           = new ApplicationUnit();

            List <Facility> facilities = unit.Facilities.GetAll()
                                         .Include(b => b.Buildings)
                                         .Include(d => d.DeedsInfo)
                                         .Include(c => c.Portfolio)
                                         .Include(p => p.ResposiblePerson)
                                         .Include("Location.GPSCoordinates")
                                         .Include("Location.BoundryPolygon")
                                         .ToList();

            //facility.ClientCode== "N14000000003740000000000000" || facility.ClientCode== "R22000000004960000000000000"
            //|| facility.ClientCode == "N14000000006110000000000000" ||
            foreach (var facility in facilities)
            {
                if (facility.ClientCode == "H21005000022300000000000000" || facility.ClientCode == "H21000000001280000000000000")
                {
                    //string facilityLocation = facilityReport.GenerateFacilityReport(facility);
                }
            }
        }
예제 #7
0
        public void Bind()
        {
            pnlDetails.Controls.Clear();
            lstRequired.Initialize(16, 16);
            lstUnlocks.Initialize(32, 32);

            Cursor = Cursors.WaitCursor;

            if (Context == null)
            {
                // display all items with no strict prereqs
                lblPrereqs.Text = "Root Items";

                var items = AllItems.Where(i => !i.UnlockRequirements.Any(r => r.IsStrict));
                foreach (var item in items)
                {
                    lstRequired.AddItemWithImage(item.ResearchGroup, item.Name, item, item.Icon);
                }
            }
            else
            {
                lblPrereqs.Text = "Prerequisites";

                if (Context is Trait)
                {
                    // display trait
                    var trait = (Trait)Context;
                    lblDetailsHeader.Text = trait.Name;
                    var lblInfo = new Label();
                    lblInfo.Text = "Cost: " + trait.Cost.Value.ToUnitString(true) + " racial points\n" + trait.Description;
                    lblInfo.Dock = DockStyle.Fill;
                    pnlDetails.Controls.Add(lblInfo);

                    // display what's unlocked
                    // note: this won't catch scripted unlocks!
                    var unlocks = AllItems.Where(u => u.UnlockRequirements.OfType <EmpireTraitRequirement>().Any(r => r.RequiredOrForbidden && r.Trait == trait));
                    foreach (var unlock in unlocks.OrderBy(u => u.UnlockRequirements.Count()))
                    {
                        lstUnlocks.AddItemWithImage(unlock.ResearchGroup, unlock.Name, unlock, unlock.Icon);
                    }
                    // HACK - racial tech requirements are special
                    foreach (var a in trait.Abilities.Where(a => a.Rule.Name == "Tech Area"))
                    {
                        foreach (var tech in Mod.Current.Technologies.Where(t => t.RacialTechID == a.Value1))
                        {
                            if (tech.UnlockRequirements.Count() == 1)
                            {
                                var req = tech.UnlockRequirements.Single();
                                if (req is TechnologyRequirement)
                                {
                                    var tr = (TechnologyRequirement)req;
                                    lstUnlocks.AddItemWithImage(tech.ResearchGroup, tech.Name + " (with " + tr.Technology + " L" + tr.Level + ")", tech, tech.Icon);
                                }
                                else if (req is EmpireTraitRequirement)
                                {
                                    var tr = (EmpireTraitRequirement)req;
                                    lstUnlocks.AddItemWithImage(tech.ResearchGroup, tech.Name + " (with " + tr.Trait + ")", tech, tech.Icon);
                                }
                                else
                                {
                                    lstUnlocks.AddItemWithImage(tech.ResearchGroup, tech.Name + " (with 1 other requirement)", tech, tech.Icon);
                                }
                            }
                            else if (tech.UnlockRequirements.Count() > 1)
                            {
                                lstUnlocks.AddItemWithImage(tech.ResearchGroup, tech.Name + " (with " + tech.UnlockRequirements.Count() + " other requirements)", tech, tech.Icon);
                            }
                            else                             // no other prereqs
                            {
                                lstUnlocks.AddItemWithImage(tech.ResearchGroup, tech.Name, tech, tech.Icon);
                            }
                        }
                    }
                }
                else
                {
                    foreach (var req in Context.UnlockRequirements)
                    {
                        if (req is TechnologyRequirement)
                        {
                            var tr = (TechnologyRequirement)req;
                            lstRequired.AddItemWithImage(tr.Technology.ResearchGroup, tr.Technology.Name + " L" + tr.Level, tr.Technology, tr.Technology.Icon);
                        }
                        else if (req is EmpireTraitRequirement)
                        {
                            var tr = (EmpireTraitRequirement)req;
                            lstRequired.AddItemWithImage(tr.Trait.ResearchGroup, tr.Trait.Name, tr.Trait, tr.Trait.Icon);
                        }
                        else
                        {
                            lstRequired.AddItemWithImage("Miscellaneous", req.Description, req, null);
                        }
                    }

                    if (Context is Technology)
                    {
                        // display technology
                        var tech = (Technology)Context;
                        lblDetailsHeader.Text = tech.Name;
                        var lblInfo = new Label();
                        lblInfo.Text = "First Level: " + tech.LevelCost.ToUnitString(true) + " research points\n" + tech.Description;
                        lblInfo.Dock = DockStyle.Fill;
                        pnlDetails.Controls.Add(lblInfo);

                        // display racial trait prereqs
                        if (tech.RacialTechID != null && tech.RacialTechID.Trim() != "0")
                        {
                            var traits = Mod.Current.Traits.Where(t => t.Abilities.Any(a => a.Rule != null && a.Rule.Name == "Tech Area" && a.Value1 == tech.RacialTechID));
                            if (traits.Count() == 1)
                            {
                                var trait = traits.Single();
                                lstRequired.AddItemWithImage(trait.ResearchGroup, trait.Name, trait, trait.Icon);
                            }
                            else if (traits.Count() > 1)
                            {
                                lstRequired.AddItemWithImage(traits.First().ResearchGroup, string.Join(" or ", traits.Select(t => t.Name).ToArray()), traits, null);
                            }
                        }

                        // display what's unlocked
                        // note: this won't catch scripted unlocks!
                        var unlocks = AllItems.Select(u =>
                        {
                            var req = u.UnlockRequirements.OfType <TechnologyRequirement>().Where(r => r.Technology == tech).WithMax(r => r.Level).FirstOrDefault();
                            if (req != null)
                            {
                                IEnumerable <Trait> traits;
                                if (u is Technology)
                                {
                                    traits = Mod.Current.Traits.Where(t => t.Abilities.Any(a => a.Rule != null && a.Rule.Name == "Tech Area" && a.Value1 == tech.RacialTechID));
                                }
                                else
                                {
                                    traits = Enumerable.Empty <Trait>();
                                }
                                return(new
                                {
                                    Item = u,
                                    Level = req.Level,
                                    Others = u.UnlockRequirements.ExceptSingle(req),
                                    Traits = traits,
                                });
                            }
                            else
                            {
                                return(null);
                            }
                        }).Where(u => u != null);
                        foreach (var unlock in unlocks.OrderBy(u => u.Level).ThenBy(u => u.Others.Count()))
                        {
                            string suffix;
                            if (unlock.Others.Count() == 0)
                            {
                                if (unlock.Traits.Count() == 0)
                                {
                                    suffix = "";
                                }
                                else
                                {
                                    suffix = " (with " + string.Join(" or ", unlock.Traits.Select(t => t.Name).ToArray());
                                }
                            }
                            else if (unlock.Others.Count() == 1 && unlock.Others.Single() is TechnologyRequirement)
                            {
                                var other = (TechnologyRequirement)unlock.Others.Single();
                                if (unlock.Traits.Count() == 0)
                                {
                                    suffix = " (with " + other.Technology + " L" + other.Level + ")";
                                }
                                else
                                {
                                    suffix = " (with " + string.Join(" or ", unlock.Traits.Select(t => t.Name).ToArray() + ", and " + other.Technology + " L" + other.Level);
                                }
                            }
                            else if (unlock.Others.Count() == 1 && unlock.Others.Single() is EmpireTraitRequirement)
                            {
                                var other = (EmpireTraitRequirement)unlock.Others.Single();
                                if (unlock.Traits.Count() == 0)
                                {
                                    suffix = " (with " + other.Trait + ")";
                                }
                                else
                                {
                                    suffix = " (with " + other.Trait + ", and " + unlock.Traits.Select(t => t.Name).ToArray();
                                }
                            }
                            else
                            {
                                suffix = " (with " + unlock.Others.Count() + " other requirements";
                            }
                            lstUnlocks.AddItemWithImage("L" + unlock.Level, unlock.Item.Name + suffix, unlock.Item, unlock.Item.Icon);
                        }
                    }
                    else if (Context is IHull)
                    {
                        // display hull
                        var hull = (IHull)Context;
                        lblDetailsHeader.Text = hull.Name;
                        // TODO - hull report
                        var lblInfo = new Label();
                        lblInfo.Text = hull.Size.Kilotons() + " " + hull.VehicleTypeName + " hull\n" + hull.Description;
                        lblInfo.Dock = DockStyle.Fill;
                        pnlDetails.Controls.Add(lblInfo);
                    }
                    else if (Context is ComponentTemplate)
                    {
                        // display component
                        var ct = (ComponentTemplate)Context;
                        lblDetailsHeader.Text = ct.Name;
                        var report = new ComponentReport(ct);
                        report.Dock = DockStyle.Fill;
                        pnlDetails.Controls.Add(report);
                    }
                    else if (Context is Mount)
                    {
                        // display mount
                        var m = (Mount)Context;
                        lblDetailsHeader.Text = m.Name;
                        var report = new MountReport(m);
                        report.Dock = DockStyle.Fill;
                        pnlDetails.Controls.Add(report);
                    }
                    else if (Context is FacilityTemplate)
                    {
                        // display facility
                        var ft = (FacilityTemplate)Context;
                        lblDetailsHeader.Text = ft.Name;
                        var report = new FacilityReport(ft);
                        report.Dock = DockStyle.Fill;
                        pnlDetails.Controls.Add(report);
                    }
                }
            }

            Cursor = Cursors.Default;
        }
예제 #8
0
        public async Task <ActionResult> LoadResourcesByFacility()
        {
            var model  = new DashboardViewModel();
            var userId = int.Parse(Session["LoggedInUserId"].ToString());

            var Baseurl = GetURL();

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(Baseurl);
                client.DefaultRequestHeaders.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                var apiURL = "/api/Values/GetUserFacilitiesByUserId/" + userId;

                HttpResponseMessage Res = await client.GetAsync(apiURL);

                if (Res.IsSuccessStatusCode)
                {
                    var result = await Res.Content.ReadAsStringAsync();

                    var response = new ResponseHelper();
                    var output   = response.fixListResult(result);

                    var data = JsonConvert.DeserializeObject <List <UserFacility> >(output);

                    foreach (var d in data)
                    {
                        var fr = new FacilityReport();
                        fr.FacilityId   = d.FacilityId;
                        fr.FacilityName = d.Facility.Name;

                        using (var client_new = new HttpClient())
                        {
                            client_new.BaseAddress = new Uri(Baseurl);
                            client_new.DefaultRequestHeaders.Clear();
                            client_new.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                            var apiURL_new = "/api/Values/GetResourceVerificationByFacilityId/" + d.FacilityId;

                            HttpResponseMessage Res_new = await client_new.GetAsync(apiURL_new);

                            if (Res_new.IsSuccessStatusCode)
                            {
                                var result_new = await Res_new.Content.ReadAsStringAsync();

                                var response_new = new ResponseHelper();
                                var output_new   = response_new.fixListResult(result_new);

                                var data_new = JsonConvert.DeserializeObject <List <ResourceReport> >(output_new);

                                foreach (var r in data_new)
                                {
                                    if (!r.Verified && !r.Missing)
                                    {
                                        fr.ResourceReport.Add(r);
                                    }
                                }
                            }
                        }

                        model.FacilityReport.Add(fr);
                    }
                }
            }

            return(PartialView("PartialViews/_data", model));
        }