private void ResourcesFilter_Load(object sender, EventArgs e)
        {
            string date;

            dgwResources.Rows.Clear();
            foreach (Resource res in MainForm.resources.Values)
            {
                date = res.Discovered.ToString(MainForm.dateFormat);

                if (res.ApproxDiscovered != null)
                {
                    date = res.ApproxDiscovered.ToString();
                }

                dgwResources.Rows.Add(new object[] { res.ID, res.Name,
                                                     date, res.Cost.ToString("C"), res.Important, res.Renewable,
                                                     Resource.FrequencyToString(res.Frequency), Resource.UnitToString(res.Unit) });
                dgwResources.Rows[dgwResources.Rows.Count - 1].Tag = res;
            }
            if (dgwResources.Rows.Count > 0)
            {
                dgwResources.CurrentCell = dgwResources.Rows[0].Cells[0];
                dgwResources_SelectionChanged(dgwResources, EventArgs.Empty);
            }
        }
Exemple #2
0
        private void btnAddResource_Click(object sender, EventArgs e)
        {
            NewResourceForm addForm = new NewResourceForm();

            addForm.ShowDialog();

            if (addForm.DialogResult == DialogResult.OK)
            {
                Resource res  = addForm.GetResource();
                string   date = res.Discovered.ToString(MainForm.dateFormat);

                if (res.ApproxDiscovered != null)
                {
                    date = res.ApproxDiscovered.ToString();
                }

                MainForm.resources.Add(res.ID, res);
                MainForm.addedResources.Add(res.ID);
                dgwResources.Rows.Add(new object[] { res.ID, res.Name, date,
                                                     res.Cost.ToString("C"), res.Important, res.Renewable,
                                                     Resource.FrequencyToString(res.Frequency), Resource.UnitToString(res.Unit) });
                dgwResources.Rows[dgwResources.Rows.Count - 1].Tag = res;
                dgwResources.CurrentCell = dgwResources.Rows[dgwResources.Rows.Count - 1].Cells[0];
                dgwResources_SelectionChanged(dgwResources, EventArgs.Empty);
            }
        }
        private void TableReload(List <Resource> list)
        {
            string date;

            currentResources = list;

            dgwResources.Rows.Clear();
            foreach (Resource res in currentResources)
            {
                date = res.Discovered.ToString(MainForm.dateFormat);

                if (res.ApproxDiscovered != null)
                {
                    date = res.ApproxDiscovered.ToString();
                }

                dgwResources.Rows.Add(new object[] { res.SecondID, res.Name,
                                                     date, res.Cost.ToString("C"), res.Important, res.Renewable,
                                                     Resource.FrequencyToString(res.Frequency), Resource.UnitToString(res.Unit) });
                dgwResources.Rows[dgwResources.Rows.Count - 1].Tag = res;
            }
            if (dgwResources.Rows.Count > 0)
            {
                dgwResources.CurrentCell = dgwResources.Rows[0].Cells[0];
                dgwResources_SelectionChanged(dgwResources, EventArgs.Empty);
            }

            chbId.Checked   = false;
            chbName.Checked = false;
            chbType.Checked = false;

            txtSearch.Text = "";
        }
        private void txtSearch_TextChanged(object sender, EventArgs e)
        {
            string date;

            if (!filterOn)
            {
                currentResources = MainForm.resources.Values.ToList();
            }

            if (txtSearch.Text.Equals("") || !(chbId.Checked || chbName.Checked || chbType.Checked))
            {
                dgwResources.Rows.Clear();
                foreach (Resource res in currentResources)
                {
                    date = res.Discovered.ToString(MainForm.dateFormat);

                    if (res.ApproxDiscovered != null)
                    {
                        date = res.ApproxDiscovered.ToString();
                    }
                    dgwResources.Rows.Add(new object[] { res.SecondID, res.Name,
                                                         date, res.Cost.ToString("C"), res.Important, res.Renewable,
                                                         Resource.FrequencyToString(res.Frequency), Resource.UnitToString(res.Unit) });
                    dgwResources.Rows[dgwResources.Rows.Count - 1].Tag = res;
                }
                if (dgwResources.Rows.Count > 0)
                {
                    dgwResources.CurrentCell = dgwResources.Rows[0].Cells[0];
                    dgwResources_SelectionChanged(dgwResources, EventArgs.Empty);
                }
            }
            else
            {
                dgwResources.Rows.Clear();
                foreach (Resource res in currentResources)
                {
                    if ((res.SecondID.Contains(txtSearch.Text) && chbId.Checked) ||
                        (res.Name.Contains(txtSearch.Text) && chbName.Checked) ||
                        (res.Type.SecondID.Contains(txtSearch.Text) && chbType.Checked))
                    {
                        date = res.Discovered.ToString(MainForm.dateFormat);

                        if (res.ApproxDiscovered != null)
                        {
                            date = res.ApproxDiscovered.ToString();
                        }

                        dgwResources.Rows.Add(new object[] { res.SecondID, res.Name,
                                                             date, res.Cost.ToString("C"), res.Important, res.Renewable,
                                                             Resource.FrequencyToString(res.Frequency), Resource.UnitToString(res.Unit) });
                        dgwResources.Rows[dgwResources.Rows.Count - 1].Tag = res;
                    }
                }
                if (dgwResources.Rows.Count > 0)
                {
                    dgwResources.CurrentCell = dgwResources.Rows[0].Cells[0];
                    dgwResources_SelectionChanged(dgwResources, EventArgs.Empty);
                }
            }
        }
        public ResourceItem(Resource r)
        {
            ID               = r.ID;
            SecondID         = r.SecondID;
            Description      = r.Description;
            Type             = r.Type;
            Name             = r.Name;
            Frequency        = r.Frequency;
            Renewable        = r.Renewable;
            Exploatable      = r.Exploatable;
            Important        = r.Important;
            Cost             = r.Cost;
            Discovered       = r.Discovered;
            Unit             = r.Unit;
            IconFileName     = r.IconFileName;
            Tags             = r.Tags;
            IconFileName     = r.IconFileName;
            UnitName         = Resource.UnitToString(Unit);
            FrequencyName    = Resource.FrequencyToString(Frequency);
            TypeName         = r.Type.ID;
            ApproxDiscovered = r.ApproxDiscovered;

            TagIds = new List <string>();
            foreach (string key in Tags.Keys)
            {
                TagIds.Add(key);
            }
        }
Exemple #6
0
 private void dgwResources_SelectionChanged(object sender, EventArgs e)
 {
     if (dgwResources.SelectedRows.Count == 0)
     {
         txtId.Text        = "";
         txtFrequency.Text = "";
         txtName.Text      = "";
         txtUnit.Text      = "";
     }
     else
     {
         Resource res = (Resource)dgwResources.SelectedRows[0].Tag;
         if (res != null)
         {
             txtId.Text        = res.Id;
             txtFrequency.Text = Resource.FrequencyToString(res.Frequency);
             txtName.Text      = res.Name;
             txtUnit.Text      = Resource.UnitToString(res.Unit);
         }
     }
 }
Exemple #7
0
        private void btnEditResource_Click(object sender, EventArgs e)
        {
            if (dgwResources.SelectedRows.Count > 0)
            {
                NewResourceForm erf = new NewResourceForm((Resource)dgwResources.SelectedRows[0].Tag);
                erf.ShowDialog();

                if (erf.DialogResult == DialogResult.OK)
                {
                    foreach (DataGridViewRow row in dgwResources.SelectedRows)
                    {
                        if (row.Selected)
                        {
                            Resource res  = erf.GetResource();
                            String   date = res.Discovered.ToString(MainForm.dateFormat);

                            if (res.ApproxDiscovered != null)
                            {
                                date = res.ApproxDiscovered.ToString();
                            }

                            int index = dgwResources.Rows.IndexOf(row);
                            dgwResources.Rows.RemoveAt(index);
                            dgwResources.Rows.Insert(index, new object[] { res.ID, res.Name, date,
                                                                           res.Cost.ToString("C"), res.Important, res.Renewable,
                                                                           Resource.FrequencyToString(res.Frequency), Resource.UnitToString(res.Unit) });
                            dgwResources.Rows[index].Tag = res;
                            dgwResources.CurrentCell     = dgwResources.Rows[index].Cells[0];
                            MainForm.resources.Remove(res.ID);
                            MainForm.resources.Add(res.ID, res);
                            break;
                        }
                    }
                    dgwResources_SelectionChanged(dgwResources, EventArgs.Empty);
                }
            }
        }
        private void btnFilter_Click(object sender, EventArgs e)
        {
            string date;

            double.TryParse(txtCostMin.Text, out minCost);
            double.TryParse(txtCostMax.Text, out maxCost);

            List <Resource>        result  = new List <Resource>();
            IEnumerable <Resource> result1 = from res in MainForm.resources.Values
                                             where ((!txtID.Enabled || txtID.Text.Equals(res.ID)) &&
                                                    (!txtName.Enabled || txtName.Text.Equals(res.Name)) &&
                                                    (!chbIsImportant.Enabled || chbIsImportant.Checked == res.Important) &&
                                                    (!chbIsRenewable.Enabled || chbIsRenewable.Checked == res.Renewable) &&
                                                    (!cmbFrequency.Enabled ||
                                                     (cmbFrequency.SelectedItem != null &&
                                                      cmbFrequency.SelectedItem.Equals(Resource.FrequencyToString(res.Frequency)))) &&
                                                    (!cmbUnit.Enabled ||
                                                     (cmbUnit.SelectedItem != null &&
                                                      cmbUnit.SelectedItem.Equals(Resource.UnitToString(res.Unit)))) &&
                                                    (!txtCostMax.Enabled || (minCost <= res.Cost && res.Cost <= maxCost)) &&
                                                    (!cmbType.Enabled ||
                                                     (cmbType.SelectedItem != null &&
                                                      cmbType.SelectedItem.Equals(res.Type.ID))) &&
                                                    (!dtpMax.Enabled ||
                                                     (dtpMax.Value.CompareTo(res.Discovered) >= 0 &&
                                                      dtpMin.Value.CompareTo(res.Discovered) <= 0)))
                                             // exploation
                                             // tags
                                             select res;

            dgwResources.Rows.Clear();

            if (chbTags.Checked)
            {
                bool contains;
                foreach (Resource res in result1)
                {
                    contains = true;
                    foreach (string tagId in tags)
                    {
                        if (!res.Tags.ContainsKey(tagId))
                        {
                            contains = false;
                        }
                    }
                    if (contains)
                    {
                        result.Add(res);
                    }
                }
            }
            else
            {
                result = result1.ToList();
            }

            foreach (Resource res in result)
            {
                date = res.Discovered.ToString(MainForm.dateFormat);

                if (res.ApproxDiscovered != null)
                {
                    date = res.ApproxDiscovered.ToString();
                }
                dgwResources.Rows.Add(new object[] { res.ID, res.Name,
                                                     date, res.Cost.ToString("C"), res.Important, res.Renewable,
                                                     Resource.FrequencyToString(res.Frequency), Resource.UnitToString(res.Unit) });
                dgwResources.Rows[dgwResources.Rows.Count - 1].Tag = res;
            }
            if (dgwResources.Rows.Count > 0)
            {
                dgwResources.CurrentCell = dgwResources.Rows[0].Cells[0];
                dgwResources_SelectionChanged(dgwResources, EventArgs.Empty);
            }
        }
Exemple #9
0
        private void btnFilter_Click(object sender, EventArgs e)
        {
            formIsValid = true;
            this.ValidateChildren();

            if (!formIsValid)
            {
                return;
            }

            string date;

            double.TryParse(txtCostMin.Text, out minCost);
            double.TryParse(txtCostMax.Text, out maxCost);

            resources.Clear();
            IEnumerable <Resource> result1 = from res in MainForm.resources.Values
                                             where ((!txtID.Enabled || txtID.Text.Equals(res.SecondID)) &&
                                                    (!txtName.Enabled || txtName.Text.Equals(res.Name)) &&
                                                    (!chbIsImportant.Enabled || chbIsImportant.Checked == res.Important) &&
                                                    (!chbIsRenewable.Enabled || chbIsRenewable.Checked == res.Renewable) &&
                                                    (!cmbFrequency.Enabled ||
                                                     (cmbFrequency.SelectedItem != null &&
                                                      cmbFrequency.SelectedItem.Equals(Resource.FrequencyToString(res.Frequency)))) &&
                                                    (!cmbUnit.Enabled ||
                                                     (cmbUnit.SelectedItem != null &&
                                                      cmbUnit.SelectedItem.Equals(Resource.UnitToString(res.Unit)))) &&
                                                    (!txtCostMax.Enabled || (minCost <= res.Cost && res.Cost <= maxCost)) &&
                                                    (!cmbType.Enabled ||
                                                     (cmbType.SelectedItem != null &&
                                                      cmbType.SelectedItem.Equals(res.Type.SecondID)))
                                             //&& (!dtpMax.Enabled
                                             //    || (dtpMax.Value.CompareTo(res.Discovered) >= 0
                                             //    && dtpMin.Value.CompareTo(res.Discovered) <= 0
                                             //    && res.ApproxDiscovered == null)))
                                                    )
                                             // exploation
                                             select res;

            dgwResources.Rows.Clear();

            if (chbTags.Checked)
            {
                bool contains;
                foreach (Resource res in result1)
                {
                    contains = true;
                    foreach (string tagId in tags)
                    {
                        if (!res.Tags.ContainsKey(tagId))
                        {
                            contains = false;
                        }
                    }
                    if (contains)
                    {
                        resources.Add(res);
                    }
                }
            }
            else
            {
                resources = result1.ToList();
            }

            if (chbDate.Checked)
            {
                for (int i = 0; i < resources.Count; i++)
                {
                    if (rbtDateMax1.Checked)
                    {
                        if (resources[i].ApproxDiscovered == null)
                        {
                            if (dtpMax.Value.CompareTo(resources[i].Discovered) < 0)
                            {
                                resources.RemoveAt(i);
                                i--;
                                continue;
                            }
                        }
                        else
                        {
                            if (resources[i].ApproxDiscovered.GetMinYear() > dtpMax.Value.Year)
                            {
                                resources.RemoveAt(i);
                                i--;
                                continue;
                            }
                        }
                    }
                    else
                    {
                        if (resources[i].ApproxDiscovered == null)
                        {
                            if (resources[i].Discovered.Year > approxDateMax.GetMaxYear())
                            {
                                resources.RemoveAt(i);
                                i--;
                                continue;
                            }
                        }
                        else
                        {
                            if (resources[i].ApproxDiscovered.GetMinYear() > approxDateMax.GetMaxYear())
                            {
                                resources.RemoveAt(i);
                                i--;
                                continue;
                            }
                        }
                    }

                    if (rbtDateMin1.Checked)
                    {
                        if (resources[i].ApproxDiscovered == null)
                        {
                            if (dtpMin.Value.CompareTo(resources[i].Discovered) > 0)
                            {
                                resources.RemoveAt(i);
                                i--;
                                continue;
                            }
                        }
                        else
                        {
                            if (resources[i].ApproxDiscovered.GetMaxYear() < dtpMin.Value.Year)
                            {
                                resources.RemoveAt(i);
                                i--;
                                continue;
                            }
                        }
                    }
                    else
                    {
                        if (resources[i].ApproxDiscovered == null)
                        {
                            if (resources[i].Discovered.Year < approxDateMin.GetMinYear())
                            {
                                resources.RemoveAt(i);
                                i--;
                                continue;
                            }
                        }
                        else
                        {
                            if (resources[i].ApproxDiscovered.GetMaxYear() < approxDateMin.GetMaxYear())
                            {
                                resources.RemoveAt(i);
                                i--;
                                continue;
                            }
                        }
                    }
                }
            }

            foreach (Resource res in resources)
            {
                date = res.Discovered.ToString(MainForm.dateFormat);

                if (res.ApproxDiscovered != null)
                {
                    date = res.ApproxDiscovered.ToString();
                }
                dgwResources.Rows.Add(new object[] { res.SecondID, res.Name,
                                                     date, res.Cost.ToString("C"), res.Important, res.Renewable,
                                                     Resource.FrequencyToString(res.Frequency), Resource.UnitToString(res.Unit) });
                dgwResources.Rows[dgwResources.Rows.Count - 1].Tag = res;
            }
            if (dgwResources.Rows.Count > 0)
            {
                dgwResources.CurrentCell = dgwResources.Rows[0].Cells[0];
                dgwResources_SelectionChanged(dgwResources, EventArgs.Empty);
            }
        }
Exemple #10
0
        private void dgwResources_SelectionChanged(object sender, EventArgs e)
        {
            if (dgwResources.SelectedRows.Count == 0)
            {
                txtId.Text             = "";
                txtFrequency.Text      = "";
                txtName.Text           = "";
                txtUnit.Text           = "";
                chbExploatable.Checked = false;
                chbImportant.Checked   = false;
                chbRenewable.Checked   = false;
                txtDescription.Text    = "";
                txtTypeId.Text         = "";
                txtTypeName.Text       = "";
                pbxIcon.Hide();
            }
            else
            {
                Resource res = (Resource)dgwResources.SelectedRows[0].Tag;
                if (res != null)
                {
                    txtId.Text             = res.ID;
                    txtFrequency.Text      = Resource.FrequencyToString(res.Frequency);
                    txtName.Text           = res.Name;
                    txtUnit.Text           = Resource.UnitToString(res.Unit);
                    chbExploatable.Checked = res.Exploatable;
                    chbImportant.Checked   = res.Important;
                    chbRenewable.Checked   = res.Renewable;
                    txtDescription.Text    = res.Description;
                    txtTypeId.Text         = res.Type.ID;
                    txtTypeName.Text       = res.Type.Name;
                    pnlTags.Controls.Clear();
                    if (res.Tags.Count > 0)
                    {
                        int   off = 3;
                        Label lbl;

                        foreach (Tag t in res.Tags.Values)
                        {
                            lbl           = new Label();
                            lbl.Width     = 15 + 5 * t.ID.Length;
                            lbl.Text      = t.ID;
                            lbl.BackColor = t.Color;
                            lbl.Left      = off;
                            pnlTags.Controls.Add(lbl);
                            lbl.Left = off;
                            off     += lbl.Width + 3;
                        }

                        pnlTags.Refresh();
                    }
                    pbxIcon.Show();
                    if (!res.IconFileName.Equals(""))
                    {
                        try
                        {
                            pbxIcon.Image    = Image.FromFile(res.IconFileName);
                            pbxIcon.SizeMode = PictureBoxSizeMode.StretchImage;
                        }
                        catch (FileNotFoundException fnfe)
                        {
                            //pbxIcon.Image = pbxIcon.ErrorImage;
                            try
                            {
                                pbxIcon.Image = Image.FromFile(res.Type.IconFileName);
                                Console.WriteLine(fnfe.StackTrace);
                            }
                            catch (FileNotFoundException fnfe1)
                            {
                                pbxIcon.Image = pbxIcon.ErrorImage;
                                //pbxIcon.Image = Image.FromFile(res.Type.IconFileName);
                                Console.WriteLine(fnfe1.StackTrace);
                            }
                        }
                    }
                    else
                    {
                        pbxIcon.Image = Image.FromFile(res.Type.IconFileName);
                        //pbxIcon.Image = pbxIcon.InitialImage;
                    }
                }
            }
        }