Esempio n. 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_RESOURCES", cn);
            SqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                ElectronicResources Resource = new ElectronicResources(
                    reader["ProductName"].ToString(),
                    reader["Manufacturer"].ToString(),
                    reader["Model"].ToString(),
                    reader["ResDescription"].ToString(),
                    new Staff(
                        int.Parse(reader["EmployeeNum"].ToString()),
                        reader["FirstName"].ToString(),
                        reader["LastName"].ToString(),
                        reader["Email"].ToString(),
                        reader["StaffImage"].ToString()
                        ),
                    reader["PathToImage"].ToString()
                    );

                EquipmentsListData.Add(Resource);
            }

            cn.Close();
        }
Esempio n. 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);
                }
            }
        }
Esempio n. 3
0
        private void equipment_info_Click(object sender, RoutedEventArgs e)
        {
            // Go to selected equipment's page
            ElectronicResources equipment = (ElectronicResources)(sender as Button).DataContext;
            StaffWindow         window    = (StaffWindow)Window.GetWindow(this);

            window.goToEquipmentPage(equipment);
        }
        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);
            }
        }
Esempio n. 5
0
        public override bool Equals(object obj)
        {
            if (!typeof(ElectronicResources).IsInstanceOfType(obj))
            {
                return(false);
            }
            ElectronicResources o = obj as ElectronicResources;

            return(ProductName == o.ProductName &&
                   Manufactor == o.Manufactor &&
                   Model == o.Model &&
                   Description == o.Description);
        }
Esempio n. 6
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);
            }
        }
Esempio n. 7
0
        public void SubmitEquipment(String imagePath)
        {
            SqlCommand cmd;

            cn = Helpers.getSGBDConnection();
            if (!Helpers.verifySGBDConnection(cn))
            {
                return;
            }

            cmd             = new SqlCommand();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Connection  = cn;
            cmd.Parameters.Clear();
            cmd.Parameters.AddWithValue("@ProductName", equipment_name.Text);
            cmd.Parameters.AddWithValue("@Manufacturer", equipment_manufacturer.Text);
            cmd.Parameters.AddWithValue("@Model", equipment_model.Text);
            cmd.Parameters.AddWithValue("@ResDescription", equipment_description.Text);
            cmd.Parameters.AddWithValue("@EmployeeNum", _staff.EmployeeNum);
            cmd.Parameters.AddWithValue("@PathToImage", imagePath);
            cmd.CommandText = "DML.CREATE_EQUIPMENT";

            try
            {
                cmd.ExecuteNonQuery();
                _equipment = new ElectronicResources(
                    equipment_name.Text,
                    equipment_manufacturer.Text,
                    equipment_model.Text,
                    equipment_description.Text,
                    _staff,
                    imagePath
                    );
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                cn.Close();
            }
        }
Esempio n. 8
0
        public EquipmentPage(ElectronicResources equipment, bool created = false)
        {
            InitializeComponent();
            // Hide go back button if it's a created equipment
            if (created)
            {
                go_back.Visibility = Visibility.Hidden;
            }
            RequisitionsData = new ObservableCollection <Requisition>();
            this._equipment  = equipment;
            // Set equipment infos
            equipment_name.Text         = _equipment.ProductName;
            equipment_model.Text        = _equipment.Model;
            equipment_manufacturer.Text = _equipment.Manufactor;
            equipment_description.Text  = _equipment.Description;
            // Try to load image
            try {
                equipment_image.Source = new BitmapImage(new Uri(_equipment.PathToImage, UriKind.Absolute));
            } catch (Exception ex)
            {
            }

            try
            {
                // Load equipment requisitions
                loadRequisitions();
            }
            catch (SqlException exc)
            {
                Helpers.ShowCustomDialogBox(exc);
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            equipment_last_requisitions_list.ItemsSource = RequisitionsData;
        }
        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();
            }
        }
Esempio n. 10
0
 public ResourceItem(ElectronicResources Resource)
 {
     this.Resource = Resource;
     this.Units    = new List <ElectronicUnit>();
 }
Esempio n. 11
0
 public ElectronicUnit(int ResourceID, ElectronicResources Model, String Supplier)
 {
     this.ResourceID = ResourceID;
     this.Model      = Model;
     this.Supplier   = Supplier;
 }
        public void goToEquipmentPage(ElectronicResources equipment, bool created = false)
        {
            EquipmentPage page = new EquipmentPage(equipment, created);

            frame.Navigate(page);
        }
Esempio n. 13
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);
        }
Esempio n. 14
0
        public void goToEquipmentPage(ElectronicResources equipment)
        {
            EquipmentPage page = new EquipmentPage(equipment);

            frame.Navigate(page);
        }