Exemple #1
0
        public static Transfer getTransfer(SqlCommand cmd, int InvID)
        {
            SqlDataReader dbReader;

            string sql = "SELECT Transfers.TransID, Transfers.Name, Transfers.Date, Transfers.Whereto, Transfers.Notes " +
                "FROM Transfers, TransferInventory WHERE Transfers.TransID = TransferInventory.TransID AND "
            + "TransferInventory.InvID = @InvID";

            cmd.CommandText = sql;

            cmd.Parameters.AddWithValue("InvID", InvID);

            dbReader = cmd.ExecuteReader();
            Transfer trans = new Transfer();

            while (dbReader.Read())
            {
                trans.ID = Convert.ToInt32(dbReader["TransID"]);
                trans.Date = Convert.ToString(dbReader["Date"]);
                trans.Where = Convert.ToString(dbReader["Whereto"]);
                trans.Notes = Convert.ToString(dbReader["Notes"]);
            }
            dbReader.Close();
            cmd.Parameters.Clear();

            return trans;
        }
Exemple #2
0
 public Computer()
 {
     monitors = new List<Monitor>();
     po = new PurchaseOrder();
     groups = new List<Group>();
     logistics = new List<Logistics>();
     currentLocation = new Logistics();
     licenses = new List<License>();
     warranties = new List<Warranty>();
     transfer = new Transfer();
 }
Exemple #3
0
 public static string saveTransfer(Transfer transfer)
 {
     return TransferDA.saveTransfer(transfer);
 }
Exemple #4
0
        protected void btnCreateTransfer_Click(object sender, EventArgs e)
        {
            Transfer transfer = new Transfer();
            transfer.Date = txtBoxDate.Text;
            transfer.Notes = txtBoxNotes.Text;
            transfer.Where = txtBoxWhere.Text;

            for (int i = 0; i < lstBoxSerialNos.Items.Count; i++)
            {
                transfer.Inventory.Add(lstBoxSerialNos.Items[i].Text);
            }

            lblTransferMessage.Text = Transfer.saveTransfer(transfer);
            lblTransferMessage.Visible = true;
            btnClearMessage.Visible = true;
        }
Exemple #5
0
        public static string saveTransfer(Transfer transfer)
        {
            SqlConnection dbConn;
            string sConnection;
            SqlCommand dbCmd;
            SqlTransaction transaction;
            StringBuilder message = new StringBuilder();

            sConnection = GlobalVars.ConnectionString;
            dbConn = new SqlConnection(sConnection);
            dbConn.Open();
            dbCmd = dbConn.CreateCommand();
            transaction = dbConn.BeginTransaction("Transaction");
            dbCmd.Transaction = transaction;
            int invCount = 0;
            try
            {
                string sqlCommand = "INSERT INTO Transfers (Date, Whereto, Notes) " +
                    "VALUES (@Date, @Whereto, @Notes)";

                dbCmd.CommandText = sqlCommand;

                dbCmd.Parameters.AddWithValue("Date", transfer.Date);
                dbCmd.Parameters.AddWithValue("Whereto", transfer.Where);
                dbCmd.Parameters.AddWithValue("Notes", transfer.Notes);

                dbCmd.ExecuteNonQuery();
                dbCmd.Parameters.Clear();

                int transferID = TransferDA.getTransferID(dbCmd, transfer.Name);

                for (int i = 0; i < transfer.Inventory.Count; i++)
                {
                    string serialNo = transfer.Inventory[i].ToString();
                    if (ComputerDA.computerExist(dbCmd, serialNo) == true || EquipmentDA.equipmentExist(dbCmd, serialNo) == true)
                    {
                        if (ComputerDA.computerTransferred(dbCmd, serialNo) == false)
                        {
                            int invId = 0;
                            invId = ComputerDA.getInvID(dbCmd, serialNo);
                            if (invId < 1)
                            {
                                invId = EquipmentDA.getInvID(dbCmd, serialNo);
                            }
                            GroupDA.removeLinks(dbCmd, invId);
                            ComputerDA.transferComputer(dbCmd, invId);

                            MonitorDA.deleteMonitors(dbCmd, invId);
                            LicenseDA.removeLicenses(dbCmd, invId);

                            sqlCommand = "INSERT INTO TransferInventory (TransID, InvID) " +
                            "VALUES (@TransID, @InvID)";

                            dbCmd.CommandText = sqlCommand;

                            dbCmd.Parameters.AddWithValue("TransID", transferID);
                            dbCmd.Parameters.AddWithValue("InvID", invId);

                            dbCmd.ExecuteNonQuery();
                            dbCmd.Parameters.Clear();
                            invCount++;
                        }
                        else
                        {
                            message.Append("Inventory item with Serial Number " + serialNo + " is already transferred and has not been added to this transfer.<bR>");
                        }
                    }
                    else
                    {
                        message.Append("Inventory with Serial Number " + serialNo + " does not exist and has not been added to this transfer.<bR>");
                    }

                }
                if (invCount == 0)
                {
                    message.Append("There were no current inventory items on this transfer, therefore the transfer has not been created.");
                    transaction.Rollback();
                }
                else
                {
                    transaction.Commit();
                    message.Append("Operation Successful!");
                }
                dbConn.Close();

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                message.Append(ex.ToString() + "<bR>");
                transaction.Rollback();
            }
            return message.ToString();
        }