Example #1
0
        private void SelectKit(Kit kit)
        {
            // Replace item's name by empty string if it hasn't units
            kit_name.Text = kit.ResourceID == -1 ? "" : kit.Description;

            foreach (ListItem resource in units_list.Items)
            {
                ResourceItem ri    = resource as ResourceItem;
                int          toAdd = 0;

                // Get kit's units number
                if (kit.ResourceID != -1)
                {
                    foreach (ElectronicUnit unit in kit.Units)
                    {
                        if (ri.Resource.Equals(unit.Model))
                        {
                            toAdd++;
                        }
                    }
                }

                // Find the listbox template fields
                var container = units_list.ItemContainerGenerator.ContainerFromItem(resource) as FrameworkElement;
                ContentPresenter listBoxItemCP = Helpers.FindVisualChild <ContentPresenter>(container);
                if (listBoxItemCP == null)
                {
                    throw new Exception("Invalid item");
                }

                DataTemplate dataTemplate = listBoxItemCP.ContentTemplate;

                DecimalUpDown unitsTextBox = (DecimalUpDown)units_list.ItemTemplate.FindName("equipment_units", listBoxItemCP);
                int           units        = kit.ResourceID == -1 ? 0 : toAdd;
                unitsTextBox.Value = units;
            }
        }
        private void UpdateSingleEquipment(ResourceItem resourceItem, int units, String supplier)
        {
            cn = Helpers.getSGBDConnection();
            if (!Helpers.verifySGBDConnection(cn))
            {
                throw new Exception("Cannot connect to database");
            }

            ElectronicResources resource = resourceItem.Resource;

            SqlCommand cmd = new SqlCommand();

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Connection  = cn;
            cmd.Parameters.Clear();
            cmd.Parameters.AddWithValue("@ProductName", resource.ProductName);
            cmd.Parameters.AddWithValue("@Manufacturer", resource.Manufactor);
            cmd.Parameters.AddWithValue("@Model", resource.Model);
            cmd.Parameters.AddWithValue("@Supplier", supplier);
            cmd.Parameters.AddWithValue("@Units", units);
            cmd.Parameters.AddWithValue("@EmployeeID", User.EmployeeNum);
            cmd.CommandText = "DML.ADD_UNITS";

            try
            {
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                cn.Close();
            }
        }
Example #3
0
        private void SubmitDeliveryResources()
        {
            int delID = -1;

            if (SelectedProject == null)
            {
                return;
            }

            DataTable toDeliver = new DataTable();

            toDeliver.Clear();
            toDeliver.Columns.Add("ResourceID", typeof(int));
            List <Resources> toDelete = new List <Resources>();

            foreach (Resources resource in active_requisitions_list.Items)
            {
                var container = active_requisitions_list.ItemContainerGenerator.ContainerFromItem(resource) as FrameworkElement;
                if (container == null)
                {
                    active_requisitions_list.UpdateLayout();
                    active_requisitions_list.ScrollIntoView(resource);
                    container = active_requisitions_list.ItemContainerGenerator.ContainerFromItem(resource) as FrameworkElement;
                }
                ContentPresenter listBoxItemCP = Helpers.FindVisualChild <ContentPresenter>(container);
                if (listBoxItemCP == null)
                {
                    return;
                }

                DataTemplate dataTemplate = listBoxItemCP.ContentTemplate;

                if (!((CheckBox)active_requisitions_list.ItemTemplate.FindName("active_checkbox", listBoxItemCP)).IsChecked ?? false)
                {
                    continue;
                }

                toDelete.Add(resource);
                DataRow row = toDeliver.NewRow();
                row["ResourceID"] = resource.ResourceID;
                toDeliver.Rows.Add(row);
            }

            if (toDeliver.Rows.Count == 0)
            {
                throw new Exception("You can't deliver 0 resources!");
            }

            delID = SubmitDelivery();
            if (delID == -1)
            {
                throw new Exception("Error creating delivery");
            }

            cn = Helpers.getSGBDConnection();
            if (!Helpers.verifySGBDConnection(cn))
            {
                throw new Exception("Error connecting to database");
            }

            SqlCommand cmd = new SqlCommand();

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Connection  = cn;
            SqlParameter listParam = cmd.Parameters.AddWithValue("@UnitsList", toDeliver);

            listParam.SqlDbType = SqlDbType.Structured;
            cmd.Parameters.AddWithValue("@delID", delID);
            cmd.CommandText = "DML.DELIVER_RESOURCES";

            try
            {
                cmd.ExecuteNonQuery();
                foreach (Resources r in toDelete)
                {
                    ActiveRequisitionsData.Remove(r);

                    if (typeof(ElectronicUnit).IsInstanceOfType(r))
                    {
                        ElectronicUnit unit = r as ElectronicUnit;
                        if (!addResourceItemUnit(unit))
                        {
                            ResourceItem ri = new ResourceItem(unit.Model);
                            ri.addUnit(unit);
                            ResourceItems.Add(ri);
                            ResourcesListData.Add(ri);
                        }
                    }
                    else if (typeof(Kit).IsInstanceOfType(r))
                    {
                        Kit unit = r as Kit;
                        if (!addKitItemUnit(unit))
                        {
                            KitItem ki = new KitItem(unit.Description);
                            ki.addUnit(unit);
                            KitItems.Add(ki);
                            ResourcesListData.Add(ki);
                        }
                    }
                }
                equipment_list.Items.Refresh();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                cn.Close();
            }
        }
Example #4
0
        private void SubmitRequisitionResources()
        {
            int reqID = -1;

            if (SelectedProject == null)
            {
                throw new Exception("You have to select a project first!");
            }

            // List's to manage equipments for requisition
            List <Resources> toBeRequested = new List <Resources>();
            List <ListItem>  toBeRemoved   = new List <ListItem>();

            DataTable toRequest = new DataTable();

            toRequest.Clear();
            toRequest.Columns.Add("ResourceID", typeof(int));

            foreach (ListItem resource in equipment_list.Items)
            {
                var container = equipment_list.ItemContainerGenerator.ContainerFromItem(resource) as FrameworkElement;
                if (container == null)
                {
                    equipment_list.UpdateLayout();
                    equipment_list.ScrollIntoView(resource);
                    container = equipment_list.ItemContainerGenerator.ContainerFromItem(resource) as FrameworkElement;
                }
                ContentPresenter listBoxItemCP = Helpers.FindVisualChild <ContentPresenter>(container);
                if (listBoxItemCP == null)
                {
                    return;
                }

                DataTemplate dataTemplate = listBoxItemCP.ContentTemplate;

                DecimalUpDown unitsTextBox = equipment_list.ItemTemplate.FindName("equipment_units", listBoxItemCP) as DecimalUpDown;
                int           units        = int.Parse(unitsTextBox.Text);
                if (units == 0)
                {
                    continue;
                }

                unitsTextBox.Value = 0;

                // Add chosen unit's number
                while (units > 0)
                {
                    Resources unit = null;
                    if (resource is ResourceItem)
                    {
                        ResourceItem r = resource as ResourceItem;
                        if (units > r.Units.Count)
                        {
                            throw new Exception("You cannot request more units than available!");
                        }
                        unit = r.requestUnit();
                        if (r.Units.Count == 0)
                        {
                            toBeRemoved.Add(r);
                        }
                    }
                    else if (resource is KitItem)
                    {
                        KitItem k = resource as KitItem;
                        if (units > k.Units.Count)
                        {
                            throw new Exception("You cannot request more units than available!");
                        }
                        unit = k.requestUnit();
                        if (k.Units.Count == 0)
                        {
                            toBeRemoved.Add(k);
                        }
                    }
                    toBeRequested.Add(unit);
                    DataRow row = toRequest.NewRow();
                    row["ResourceID"] = unit.ResourceID;
                    toRequest.Rows.Add(row);
                    units--;
                }
            }

            if (toRequest.Rows.Count == 0)
            {
                throw new Exception("You can't request 0 resources!");
            }

            reqID = SubmitRequisition();
            if (reqID == -1)
            {
                throw new Exception("Error creating requisition");
            }

            cn = Helpers.getSGBDConnection();
            if (!Helpers.verifySGBDConnection(cn))
            {
                throw new Exception("Error connecting to database");
            }

            SqlCommand cmd = new SqlCommand();

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Connection  = cn;
            SqlParameter listParam = cmd.Parameters.AddWithValue("@UnitsList", toRequest);

            listParam.SqlDbType = SqlDbType.Structured;
            cmd.Parameters.AddWithValue("@reqID", reqID);
            cmd.CommandText = "DML.REQUEST_RESOURCES";

            try
            {
                cmd.ExecuteNonQuery();
                foreach (Resources resource in toBeRequested)
                {
                    ActiveRequisitionsData.Add(resource);
                }
                foreach (ListItem li in toBeRemoved)
                {
                    ResourcesListData.Remove(li);
                    if (typeof(ResourceItem).IsInstanceOfType(li))
                    {
                        ResourceItem ri = li as ResourceItem;
                        ResourceItems.Remove(ri);
                    }
                    else if (typeof(KitItem).IsInstanceOfType(li))
                    {
                        KitItem ki = li as KitItem;
                        KitItems.Remove(ki);
                    }
                }
                equipment_list.Items.Refresh();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                cn.Close();
            }
        }
Example #5
0
        private void LoadAvailableResources()
        {
            cn = Helpers.getSGBDConnection();
            if (!Helpers.verifySGBDConnection(cn))
            {
                throw new Exception("Cannot connect to database");
            }

            DataSet    ds  = new DataSet();
            SqlCommand cmd = new SqlCommand("DML.RESOURCES_TO_REQUEST", cn);

            cmd.CommandType = CommandType.StoredProcedure;
            SqlDataAdapter da = new SqlDataAdapter(cmd);

            da.Fill(ds);
            cn.Close();

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                ElectronicResources resource = new ElectronicResources(
                    row["ProductName"].ToString(),
                    row["Manufacturer"].ToString(),
                    row["Model"].ToString(),
                    row["ResDescription"].ToString(),
                    null,
                    row["PathToImage"].ToString()
                    );

                ElectronicUnit unit = new ElectronicUnit(
                    int.Parse(row["ResourceID"].ToString()),
                    resource,
                    row["Supplier"].ToString()
                    );

                if (!addResourceItemUnit(unit))
                {
                    Console.WriteLine(resource);
                    ResourceItem ri = new ResourceItem(resource);
                    ri.addUnit(unit);
                    ResourceItems.Add(ri);
                }
            }

            foreach (DataRow row in ds.Tables[1].Rows)
            {
                Kit unit = new Kit(
                    int.Parse(row["ResourceID"].ToString()),
                    row["KitDescription"].ToString()
                    );

                if (!addKitItemUnit(unit))
                {
                    KitItem ki = new KitItem(unit.Description);
                    ki.addUnit(unit);
                    KitItems.Add(ki);
                }
            }

            foreach (ResourceItem ri in ResourceItems)
            {
                ResourcesListData.Add(ri);
            }

            foreach (KitItem ki in KitItems)
            {
                ResourcesListData.Add(ki);
            }
        }
 public UnitsHelper(ResourceItem Resource, int Units, String Supplier)
 {
     this.Resource = Resource;
     this.Units    = Units;
     this.Supplier = Supplier;
 }