Esempio n. 1
0
    //Asset
    public static SQL_Request AddAsset(this SQL_Request request, Asset asset, bool close = true)
    {
        if (request.Connection.State == ConnectionState.Closed)
        {
            request.Connection.Open();
        }
        request.Command = new SqlCommand();

        try
        {
            string imgs = "";

            imgs = asset.Images;
            if (request.Connection.State == ConnectionState.Closed)
            {
                request.Connection.Open();
            }
            request.Command             = new SqlCommand();
            request.Command.Connection  = request.Connection;          //Pass the connection object to Command
            request.Command.CommandType = CommandType.StoredProcedure; // We will use stored procedure.
            request.Command.CommandText = "AssetInsert";               //Stored Procedure Name

            //	 @AssetName,@AssetNumber,@CalibratedAsset,@Damaged,@OnHold,@BarcodeImage,
            //@CalibrationCompany,@CalibrationHistory,@CalibrationPeriod,@DateReturned,
            //@DateShipped,@AssetDescription,@LastCalibrated,@OrderNumber,@PersonShipping,
            //@PackingSlip,@ReturnReport,@UPSlabel,@Images,@ImageLinks,@ServiceEngineer,@ShipTo,@AssetWeight
            request.Command.Parameters.Add("@AssetName", SqlDbType.NVarChar).Value          = asset.AssetName;
            request.Command.Parameters.Add("@AssetNumber", SqlDbType.NVarChar).Value        = asset.AssetNumber;
            request.Command.Parameters.Add("@CalibratedAsset", SqlDbType.Bit).Value         = asset.IsCalibrated;
            request.Command.Parameters.Add("@Damaged", SqlDbType.Bit).Value                 = asset.IsDamaged;
            request.Command.Parameters.Add("@OnHold", SqlDbType.Bit).Value                  = asset.OnHold;
            request.Command.Parameters.Add("@IsOut", SqlDbType.Bit).Value                   = asset.IsOut;
            request.Command.Parameters.Add("@BarcodeImage", SqlDbType.NVarChar).Value       = asset.BarcodeImage; //FIX
            request.Command.Parameters.Add("@CalibrationCompany", SqlDbType.NVarChar).Value = asset.CalibrationCompany;
            string calXml = new CalibrationLibrary().SerializeToXmlString(new CalibrationLibrary());
            try
            {
                calXml = asset.CalibrationHistory.SerializeToXmlString(asset.CalibrationHistory);
            }
            catch { }
            request.Command.Parameters.Add("@CalibrationHistory", SqlDbType.NVarChar).Value = calXml;
            request.Command.Parameters.Add("@CalibrationPeriod", SqlDbType.NVarChar).Value  = asset.CalibrationPeriod;
            request.Command.Parameters.Add("@DateReturned", SqlDbType.NVarChar).Value       = asset.DateRecieved.ToString();
            request.Command.Parameters.Add("@DateShipped", SqlDbType.NVarChar).Value        = asset.DateShipped.ToString();
            request.Command.Parameters.Add("@AssetDescription", SqlDbType.NVarChar).Value   = asset.Description;
            request.Command.Parameters.Add("@LastCalibrated", SqlDbType.NVarChar).Value     = asset.LastCalibrated.ToString();
            request.Command.Parameters.Add("@OrderNumber", SqlDbType.NVarChar).Value        = asset.OrderNumber.ToString();
            request.Command.Parameters.Add("@PersonShipping", SqlDbType.NVarChar).Value     = asset.PersonShipping;
            request.Command.Parameters.Add("@Images", SqlDbType.NVarChar).Value             = imgs;
            request.Command.Parameters.Add("@ImageLinks", SqlDbType.NVarChar).Value         = imgs;
            request.Command.Parameters.Add("@ServiceEngineer", SqlDbType.NVarChar).Value    = asset.ServiceEngineer;
            request.Command.Parameters.Add("@ShipTo", SqlDbType.NVarChar).Value             = asset.ShipTo;
            request.Command.Parameters.Add("@AssetWeight", SqlDbType.NVarChar).Value        = asset.weight.ToString();
            try
            {
                foreach (var ii in asset.History.History)
                {
                    ii.IsHistoryItem = true;
                }
            }
            catch { }
            var histxml = asset.History.Serialize();
            request.Command.Parameters.Add("@History", SqlDbType.NVarChar).Value      = histxml;
            request.Command.Parameters.Add("@PackingSlip", SqlDbType.NVarChar).Value  = asset.PackingSlip;
            request.Command.Parameters.Add("@ReturnReport", SqlDbType.NVarChar).Value = asset.ReturnReport;
            request.Command.Parameters.Add("@UPSlabel", SqlDbType.NVarChar).Value     = asset.UpsLabel;

            request.Command.ExecuteNonQuery();
            request.Success = true;
            request.Message = "success:addAsset";
        }
        catch (Exception ex)
        {
            request.Error.Ex = ex;
            request.Success  = false;
            request.Message  = "error:addAsset";
            return(request);
        }
        finally
        {
            if (close)
            {
                request.Connection.Close();
            }
        }
        request.Message = "success:addAsset";
        request.Success = true;
        return(request);
    }
Esempio n. 2
0
    public static SQL_Request UpdateAsset(this SQL_Request request, Asset asset, bool close = true)
    {
        request.Command = new SqlCommand();
        try
        {
            if (request.Connection.State == ConnectionState.Closed)
            {
                request.Connection.Open();
            }
            // Create a object of SqlCommand class
            request.Command.Connection  = request.Connection;          //Pass the connection object to Command
            request.Command.CommandType = CommandType.StoredProcedure; // We will use stored procedure.
            request.Command.CommandText = "AssetUpdate";
            string imgs = asset.Images;
            // request.Command.CommandText = "spUpdateTimeData"; //Stored Procedure Name
            request.Command.Parameters.Add("@AssetName", SqlDbType.NVarChar).Value          = asset.AssetName;
            request.Command.Parameters.Add("@AssetNumber", SqlDbType.NVarChar).Value        = asset.AssetNumber;
            request.Command.Parameters.Add("@CalibratedAsset", SqlDbType.Bit).Value         = asset.IsCalibrated;
            request.Command.Parameters.Add("@Damaged", SqlDbType.Bit).Value                 = asset.IsDamaged;
            request.Command.Parameters.Add("@OnHold", SqlDbType.Bit).Value                  = asset.OnHold;
            request.Command.Parameters.Add("@IsOut", SqlDbType.Bit).Value                   = asset.IsOut;
            request.Command.Parameters.Add("@BarcodeImage", SqlDbType.NVarChar).Value       = asset.BarcodeImage;
            request.Command.Parameters.Add("@CalibrationCompany", SqlDbType.NVarChar).Value = asset.CalibrationCompany;
            request.Command.Parameters.Add("@CalibrationPeriod", SqlDbType.NVarChar).Value  = asset.CalibrationPeriod;
            request.Command.Parameters.Add("@DateReturned", SqlDbType.NVarChar).Value       = asset.DateRecieved.ToString();
            request.Command.Parameters.Add("@DateShipped", SqlDbType.NVarChar).Value        = asset.DateShipped.ToString();
            request.Command.Parameters.Add("@AssetDescription", SqlDbType.NVarChar).Value   = asset.Description;
            request.Command.Parameters.Add("@LastCalibrated", SqlDbType.NVarChar).Value     = asset.LastCalibrated.ToString();
            request.Command.Parameters.Add("@OrderNumber", SqlDbType.NVarChar).Value        = asset.OrderNumber.ToString();
            request.Command.Parameters.Add("@PersonShipping", SqlDbType.NVarChar).Value     = asset.PersonShipping;
            request.Command.Parameters.Add("@Images", SqlDbType.NVarChar).Value             = imgs;
            request.Command.Parameters.Add("@ImageLinks", SqlDbType.NVarChar).Value         = imgs;
            request.Command.Parameters.Add("@ServiceEngineer", SqlDbType.NVarChar).Value    = asset.ServiceEngineer;
            request.Command.Parameters.Add("@ShipTo", SqlDbType.NVarChar).Value             = asset.ShipTo;
            request.Command.Parameters.Add("@AssetWeight", SqlDbType.NVarChar).Value        = asset.weight.ToString();
            if (asset.PackingSlip == null)
            {
                asset.PackingSlip = "";
            }
            request.Command.Parameters.Add("@PackingSlip", SqlDbType.NVarChar).Value  = asset.PackingSlip;
            request.Command.Parameters.Add("@ReturnReport", SqlDbType.NVarChar).Value = asset.ReturnReport;
            request.Command.Parameters.Add("@UPSlabel", SqlDbType.NVarChar).Value     = asset.UpsLabel;

            string calXml = new CalibrationLibrary().SerializeToXmlString(new CalibrationLibrary());
            try
            {
                calXml = asset.CalibrationHistory.SerializeToXmlString(asset.CalibrationHistory);
            }
            catch { }
            request.Command.Parameters.Add("@CalibrationHistory", SqlDbType.NVarChar).Value = calXml;
            try
            {
                foreach (var ii in asset.History.History)
                {
                    ii.IsHistoryItem = true;
                }
            }
            catch { }
            try
            {
                foreach (var aa in asset.History.History)
                {
                    aa.History = new AssetHistory();
                }
                var histxml = asset.History.Serialize();
                request.Command.Parameters.Add("@History", SqlDbType.NVarChar).Value = histxml;
            }
            catch { }

            request.Command.ExecuteNonQuery();
            request.Message = "success:assetUpdate";
        }
        catch (Exception ex)
        {
            request.Error.Ex = ex;
            request.Success  = false;
            request.Message  = "error:assetUpdate";

            System.Windows.Forms.MessageBox.Show(ex.ToString());
            return(request);
        }
        finally
        {
            if (close)
            {
                request.Connection.Close();
            }
        }
        return(request);
    }