예제 #1
0
        private void LoadResources()
        {
            cn = Helpers.getSGBDConnection();
            if (!Helpers.verifySGBDConnection(cn))
            {
                throw new Exception("Cannot connect to database");
            }

            SqlCommand    cmd    = new SqlCommand("SELECT * FROM DML.ALL_ELECTRONIC_UNITS", cn);
            SqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                ElectronicResources resource = new ElectronicResources(
                    reader["ProductName"].ToString(),
                    reader["Manufacturer"].ToString(),
                    reader["Model"].ToString(),
                    reader["ResDescription"].ToString(),
                    null,
                    reader["PathToImage"].ToString()
                    );

                // Check if the resource has units
                if (reader["ResourceID"] != DBNull.Value)
                {
                    ElectronicUnit unit = new ElectronicUnit(
                        int.Parse(reader["ResourceID"].ToString()),
                        resource,
                        reader["Supplier"].ToString()
                        );

                    // Add new resource item (and it's unit) to list, if it isn't there already
                    if (!addResourceItemUnit(unit))
                    {
                        ResourceItem ri = new ResourceItem(resource);
                        ri.addUnit(unit);
                        ResourceItems.Add(ri);
                    }
                }
                else
                {
                    ResourceItem ri = new ResourceItem(resource);
                    ResourceItems.Add(ri);
                }
            }

            cn.Close();

            foreach (ResourceItem ri in ResourceItems)
            {
                EquipmentsListData.Add(ri);
            }
        }
예제 #2
0
        private void LoadResources()
        {
            cn = Helpers.getSGBDConnection();
            if (!Helpers.verifySGBDConnection(cn))
            {
                throw new Exception("Cannot connect to database");
            }

            DataSet    ds  = new DataSet();
            SqlCommand cmd = new SqlCommand();

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Connection  = cn;
            cmd.CommandText = "DML.RESOURCES_TO_REQUEST";
            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))
                {
                    ResourceItem ri = new ResourceItem(resource);
                    ri.addUnit(unit);
                    ResourceItems.Add(ri);
                }
            }

            cn.Close();

            foreach (ResourceItem ri in ResourceItems)
            {
                EquipmentsListData.Add(ri);
            }
        }
예제 #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();
            }
        }