コード例 #1
0
 public void addUnit(ElectronicUnit newUnit)
 {
     if (!Units.Contains(newUnit))
     {
         Units.Add(newUnit);
     }
 }
コード例 #2
0
        private void LoadUnits()
        {
            foreach (Kit kit in KitsListData)
            {
                DataSet    ds  = new DataSet();
                SqlCommand cmd = new SqlCommand();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Connection  = cn;
                cmd.Parameters.Clear();
                cmd.Parameters.AddWithValue("@KitID", kit.ResourceID);
                cmd.CommandText = "DML.KIT_UNITS";
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(ds);

                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()
                        );

                    kit.addUnit(unit);
                }
            }
        }
コード例 #3
0
        public ElectronicUnit requestUnit()
        {
            ElectronicUnit toReturn = null;

            if (Units.Count > 0)
            {
                toReturn = Units.First();
                Units.Remove(toReturn);
            }
            return(toReturn);
        }
コード例 #4
0
 private bool addResourceItemUnit(ElectronicUnit unit)
 {
     foreach (ResourceItem item in ResourceItems)
     {
         if (item.Resource.Equals(unit.Model))
         {
             item.addUnit(unit);
             return(true);
         }
     }
     return(false);
 }
コード例 #5
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);
            }
        }
コード例 #6
0
 private bool addResourceItemUnit(ElectronicUnit unit)
 {
     // Get unit's equipment and add it another
     foreach (ResourceItem item in ResourceItems)
     {
         if (item.Resource.Equals(unit.Model))
         {
             item.addUnit(unit);
             return(true);
         }
     }
     return(false);
 }
コード例 #7
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);
            }
        }
コード例 #8
0
        private DataTable verifyUnits()
        {
            DataTable toRequest = new DataTable();

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

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

                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;

                int units = int.Parse(((DecimalUpDown)units_list.ItemTemplate.FindName("equipment_units", listBoxItemCP)).Text);
                if (units > ri.Units.Count)
                {
                    throw new Exception("You cannot request more units than the available!");
                }

                // Save each unit on DB
                while (units > 0)
                {
                    ElectronicUnit unit = ri.requestUnit();
                    DataRow        row  = toRequest.NewRow();
                    row["ResourceID"] = unit.ResourceID;
                    toRequest.Rows.Add(row);
                    units--;
                }
            }

            if (toRequest.Rows.Count == 0)
            {
                throw new Exception("You need to select at least one unit!");
            }

            return(toRequest);
        }
コード例 #9
0
 public void addUnit(ElectronicUnit unit)
 {
     _units.Add(unit);
 }
コード例 #10
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();
            }
        }
コード例 #11
0
        private Kit submitKitCreation(DataTable toRequest)
        {
            Kit newKit = null;

            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.Parameters.Clear();
            SqlParameter listParam = cmd.Parameters.AddWithValue("@UnitsList", toRequest);

            listParam.SqlDbType = SqlDbType.Structured;
            cmd.Parameters.Add("@KitID", SqlDbType.Int).Direction = ParameterDirection.Output;
            cmd.Parameters.AddWithValue("@StaffID", StaffID);
            cmd.Parameters.AddWithValue("@KitDescription", kit_name.Text);
            cmd.CommandText = "DML.CREATE_KIT";
            int kitID = -1;

            try
            {
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(ds);
                kitID  = Convert.ToInt32(cmd.Parameters["@KitID"].Value);
                newKit = new Kit(kitID, kit_name.Text);

                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()
                        );

                    newKit.addUnit(unit);
                }
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                cn.Close();
            }

            return(newKit);
        }