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);
            }
        }
Beispiel #2
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);
         }
     }
 }
        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);
            }
        }
        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);
            }
        }
Beispiel #5
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);
            }
        }
Beispiel #6
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;
                    }
                }
            }
        }
Beispiel #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);
                }
            }
        }
Beispiel #8
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);
                }
            }
        }
Beispiel #11
0
        public NewResourceForm(Resource res)
        {
            InitializeComponent();
            this.Text  = "Uredi podatke o resursu";
            edit       = true;
            ofd.Filter = "Image Files(*.BMP;*.JPG;*.PNG)|*.BMP;*.JPG;*.PNG";
            this.cmbUnit.DropDownStyle = ComboBoxStyle.DropDownList;

            tags = res.Tags;
            type = res.Type;

            ID = res.ID;

            txtId.Text          = res.SecondID;
            txtName.Text        = res.Name;
            txtDescription.Text = res.Description;
            lblIconName.Text    = res.IconFileName;
            lblTypeID.Text      = type.ID;
            if (res.Renewable)
            {
                chbRenewable.Checked = true;
            }
            if (res.Important)
            {
                chbImportant.Checked = true;
            }
            if (res.Exploatable)
            {
                chbExploatable.Checked = true;
            }
            cmbUnit.Text = Resource.UnitToString(res.Unit);
            switch (res.Frequency)
            {
            case Frequency.FREQUENT:
                rbtFrequent.Checked = true;
                break;

            case Frequency.RARE:
                rbtRare.Checked = true;
                break;

            case Frequency.UNIVERSAL:
                rbtUniversal.Checked = true;
                break;
            }
            txtCost.Text         = res.Cost.ToString();
            dateTimePicker.Value = res.Discovered;
            lblTag.Text          = res.Tags.Count.ToString() + " etiketa";
            fullFileName         = res.IconFileName;
            char[] sep = { '\\' };
            fname = lblIconName.Text = fullFileName.Split(sep).Last();
            if (res.ApproxDiscovered != null)
            {
                rbtApproxDate.Checked = true;
                if (res.ApproxDiscovered.Unknown)
                {
                    rbtUnknown.Checked = true;
                }
                else if (res.ApproxDiscovered.Year >= 0)
                {
                    rbtYear.Checked = true;
                    txtYear.Text    = res.ApproxDiscovered.Year.ToString();
                    chbYear.Checked = !res.ApproxDiscovered.AD;
                }
                else if (res.ApproxDiscovered.Century >= 0)
                {
                    rbtCentury.Checked = true;
                    txtCentury.Text    = res.ApproxDiscovered.Century.ToString();
                    chbCentury.Checked = !res.ApproxDiscovered.AD;
                }
            }
            else
            {
                rbtUnknown.Checked = true;
                rbtDate.Checked    = true;
            }



            rbtDate_CheckedChanged(this, EventArgs.Empty);
            rbtApproxDate_CheckedChanged(this, EventArgs.Empty);

            helpProvider1.SetHelpKeyword(this, "Tutorijal");
        }
        public EditResourceForm(Resource res)
        {
            InitializeComponent();
            ofd.Filter = "Image Files(*.BMP;*.JPG;*.PNG)|*.BMP;*.JPG;*.PNG";
            this.cmbUnit.DropDownStyle = ComboBoxStyle.DropDownList;
            this.cmbType.DropDownStyle = ComboBoxStyle.DropDownList;

            tags = res.Tags;
            type = res.Type;

            txtId.Text          = res.ID;
            txtId.ReadOnly      = true;
            txtName.Text        = res.Name;
            txtDescription.Text = res.Description;
            lblIconName.Text    = res.IconFileName;
            if (res.Renewable)
            {
                chbRenewable.Checked = true;
            }
            if (res.Important)
            {
                chbImportant.Checked = true;
            }
            if (res.Exploatable)
            {
                chbExploatable.Checked = true;
            }
            cmbUnit.Text = Resource.UnitToString(res.Unit);
            switch (res.Frequency)
            {
            case Frequency.FREQUENT:
                rbtFrequent.Checked = true;
                break;

            case Frequency.RARE:
                rbtRare.Checked = true;
                break;

            case Frequency.UNIVERSAL:
                rbtUniversal.Checked = true;
                break;
            }
            txtCost.Text         = res.Cost.ToString();
            dateTimePicker.Value = res.Discovered;
            lblTag.Text          = res.Tags.Count.ToString();
            fullFileName         = res.IconFileName;
            lblIconName.Text     = fullFileName;
            if (res.ApproxDiscovered != null)
            {
                approxDate         = res.ApproxDiscovered;
                lblApproxDate.Text = res.ApproxDiscovered.ToString();
            }


            foreach (Type t in MainForm.types.Values)
            {
                cmbType.Items.Add(t.ID);
            }
            cmbType.SelectedItem = res.Type.ID;

            ToolTip tt = new ToolTip();

            tt.SetToolTip(btnDate, "Izbor okvirnog datuma");

            lblApproxDate.Enabled  = rbtApproxDate.Checked;
            btnDate.Enabled        = rbtApproxDate.Checked;
            dateTimePicker.Enabled = rbtDate.Checked;
        }