예제 #1
0
        private static string CheckIfExists(Laptop laptop, string ID, bool WithID)
        {
            DataAccessLayer dal   = new DataAccessLayer();
            string          error = "";
            string          addID = "";

            if (WithID)
            {
                dal.AddParameter("@ID", ID, System.Data.DbType.String);
                addID = " AND [ID] <> @ID";
            }

            dal.AddParameter("@Serialnumber", laptop.Serialnumber, System.Data.DbType.String);
            dal.AddParameter("@GUID", laptop.GUID, System.Data.DbType.String);
            dal.AddParameter("@Name", laptop.Name, System.Data.DbType.String);
            dal.AddParameter("@Description", laptop.Description, System.Data.DbType.String);
            error = dal.ExecuteScalar(@"
DECLARE @error varchar(50)
SET @error = ''

IF EXISTS (SELECT * FROM [Laptop] WHERE [Deleted] = 0 AND UPPER([Serialnumber]) = UPPER(@Serialnumber)" + addID + @")
SET @error += '1'

IF EXISTS (SELECT * FROM [Laptop] WHERE [Deleted] = 0 AND UPPER([GUID]) = UPPER(@GUID) AND [GUID] <> ''" + addID + @")
SET @error += '5'

IF EXISTS (SELECT * FROM [Laptop] WHERE [Deleted] = 0 AND UPPER([Name]) = UPPER(@Name) AND [Name] <> ''" + addID + @")
SET @error += '6'

IF EXISTS (SELECT * FROM [Laptop] WHERE [Deleted] = 0 AND UPPER([Description]) = UPPER(@Description) AND [Description] <> ''" + addID + @")
SET @error += '7'

SELECT @error
").ToString();
            dal.ClearParameters();

            return(error);
        }
예제 #2
0
 /// <summary>
 /// Checks if a Laptop already exists in the database based on Serialnumber, IMEI,
 /// SIMcard and Phonenr.
 /// Returns an empty string "" if there are no errors or returns a string with the
 /// numbers representing each error:
 /// 1: Serialnumber
 /// 2: IMEI
 /// 3: SIMcard
 /// 4: Phonenr
 /// Fx. it returns "24" meaning that IMEI and Phonenr already exists.
 /// </summary>
 /// <param name="laptop">The Laptop to check</param>
 /// <returns></returns>
 public static string CheckIfExists(Laptop laptop, string ID)
 {
     return(CheckIfExists(laptop, ID, true));
 }
예제 #3
0
 /// <summary>
 /// Checks if a Laptop already exists in the database based on Serialnumber, IMEI,
 /// SIMcard and Phonenr.
 /// Returns an empty string "" if there are no errors or returns a string with the
 /// numbers representing each error:
 /// 1: Serialnumber
 /// 2: IMEI
 /// 3: SIMcard
 /// 4: Phonenr
 /// Fx. it returns "24" meaning that IMEI and Phonenr already exists.
 /// </summary>
 /// <param name="laptop">The Laptop to check</param>
 /// <returns></returns>
 public static string CheckIfExists(Laptop laptop)
 {
     return(CheckIfExists(laptop, "", false));
 }