コード例 #1
0
 ///<summary>Returns true if Update(SmsPhone,SmsPhone) would make changes to the database.
 ///Does not make any changes to the database and can be called before remoting role is checked.</summary>
 public static bool UpdateComparison(SmsPhone smsPhone, SmsPhone oldSmsPhone)
 {
     if (smsPhone.ClinicNum != oldSmsPhone.ClinicNum)
     {
         return(true);
     }
     if (smsPhone.PhoneNumber != oldSmsPhone.PhoneNumber)
     {
         return(true);
     }
     if (smsPhone.DateTimeActive != oldSmsPhone.DateTimeActive)
     {
         return(true);
     }
     if (smsPhone.DateTimeInactive != oldSmsPhone.DateTimeInactive)
     {
         return(true);
     }
     if (smsPhone.InactiveCode != oldSmsPhone.InactiveCode)
     {
         return(true);
     }
     if (smsPhone.CountryCode != oldSmsPhone.CountryCode)
     {
         return(true);
     }
     return(false);
 }
コード例 #2
0
ファイル: SmsPhoneCrud.cs プロジェクト: kjb7749/testImport
 ///<summary>Inserts one SmsPhone into the database.  Returns the new priKey.</summary>
 public static long Insert(SmsPhone smsPhone)
 {
     if (DataConnection.DBtype == DatabaseType.Oracle)
     {
         smsPhone.SmsPhoneNum = DbHelper.GetNextOracleKey("smsphone", "SmsPhoneNum");
         int loopcount = 0;
         while (loopcount < 100)
         {
             try {
                 return(Insert(smsPhone, true));
             }
             catch (Oracle.ManagedDataAccess.Client.OracleException ex) {
                 if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated"))
                 {
                     smsPhone.SmsPhoneNum++;
                     loopcount++;
                 }
                 else
                 {
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else
     {
         return(Insert(smsPhone, false));
     }
 }
コード例 #3
0
        ///<summary>Inserts one SmsPhone into the database.  Provides option to use the existing priKey.  Doesn't use the cache.</summary>
        public static long InsertNoCache(SmsPhone smsPhone, bool useExistingPK)
        {
            bool   isRandomKeys = Prefs.GetBoolNoCache(PrefName.RandomPrimaryKeys);
            string command      = "INSERT INTO smsphone (";

            if (!useExistingPK && isRandomKeys)
            {
                smsPhone.SmsPhoneNum = ReplicationServers.GetKeyNoCache("smsphone", "SmsPhoneNum");
            }
            if (isRandomKeys || useExistingPK)
            {
                command += "SmsPhoneNum,";
            }
            command += "ClinicNum,PhoneNumber,DateTimeActive,DateTimeInactive,InactiveCode,CountryCode) VALUES(";
            if (isRandomKeys || useExistingPK)
            {
                command += POut.Long(smsPhone.SmsPhoneNum) + ",";
            }
            command +=
                POut.Long(smsPhone.ClinicNum) + ","
                + "'" + POut.String(smsPhone.PhoneNumber) + "',"
                + POut.DateT(smsPhone.DateTimeActive) + ","
                + POut.DateT(smsPhone.DateTimeInactive) + ","
                + "'" + POut.String(smsPhone.InactiveCode) + "',"
                + "'" + POut.String(smsPhone.CountryCode) + "')";
            if (useExistingPK || isRandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                smsPhone.SmsPhoneNum = Db.NonQ(command, true, "SmsPhoneNum", "smsPhone");
            }
            return(smsPhone.SmsPhoneNum);
        }
コード例 #4
0
        public SendManySms()
        {
            InitializeComponent();

            smsPhone1 = new SmsPhone(FormFactor.Bar, "BP20200406");
            smsPhone1.AddSimCard(new SimCard(), output);
            smsPhone2 = new SmsPhone(FormFactor.Bar, "BP20200409");
            smsPhone2.AddSimCard(new SimCard(), output);
            smsPhone3 = new SmsPhone(FormFactor.Bar, "BP20200406");
            smsPhone3.AddSimCard(new SimCard(), output);
            smsPhone4 = new SmsPhone(FormFactor.Bar, "BP20200409");
            smsPhone4.AddSimCard(new SimCard(), output);

            output = new TextBoxOutput(this.receivedSms);

            var contact1 = smsPhone1.GetMyContact("Alex");
            var contact2 = smsPhone2.GetMyContact("Vova");
            var contact3 = smsPhone3.GetMyContact("Stas");
            var contact4 = smsPhone4.GetMyContact("Oleg");

            smsPhone1.AddContact(contact2, contact3, contact4);
            smsPhone2.AddContact(contact1);
            smsPhone3.AddContact(contact1);
            smsPhone4.AddContact(contact1);

            phones = new IPhone[] { smsPhone1, smsPhone2, smsPhone3, smsPhone4 };

            smsFormatting.DataSource = Enum.GetNames(typeof(TextBoxOutput.FormatingStyle));
            cmbWords.DataSource      = new List <string>()
            {
                FILTER_ALL_VALUES
            }.Concat(words).ToArray();
            cmbLogic.DataSource  = Enum.GetNames(typeof(LogicOperand));
            dtpFrom.CustomFormat = "dd/MM/yyyy hh:mm:ss";
            dtpTo.CustomFormat   = "dd/MM/yyyy hh:mm:ss";

            resetFilters();

            sendSms = delegate
            {
                int arrLength = words.Length - 1;
                smsPhone1.SendSms($"smsVSO|{words[random.Next(arrLength)]}|{smsCount++}", output, 0, "Vova", "Stas", "Oleg");
                smsPhone2.SendSms($"smsVA|{words[random.Next(arrLength)]}|{smsCount++}", output, 0, "Alex");
                smsPhone3.SendSms($"smsSA|{words[random.Next(arrLength)]}|{smsCount++}", output, 0, "Alex");
                smsPhone4.SendSms($"smsOA|{words[random.Next(arrLength)]}|{smsCount++}", output, 0, "Alex");

                cbxSubscribers.DataSource = getAllSenders(phones);
            };

            powerbank             = new PowerBank("PB20200430");
            powerbank.PluginToUse = Plugins.Usb;
        }
コード例 #5
0
        ///<summary>Updates one SmsPhone in the database.</summary>
        public static void Update(SmsPhone smsPhone)
        {
            string command = "UPDATE smsphone SET "
                             + "ClinicNum       =  " + POut.Long(smsPhone.ClinicNum) + ", "
                             + "PhoneNumber     = '" + POut.String(smsPhone.PhoneNumber) + "', "
                             + "DateTimeActive  =  " + POut.DateT(smsPhone.DateTimeActive) + ", "
                             + "DateTimeInactive=  " + POut.DateT(smsPhone.DateTimeInactive) + ", "
                             + "InactiveCode    = '" + POut.String(smsPhone.InactiveCode) + "', "
                             + "CountryCode     = '" + POut.String(smsPhone.CountryCode) + "' "
                             + "WHERE SmsPhoneNum = " + POut.Long(smsPhone.SmsPhoneNum);

            Db.NonQ(command);
        }
コード例 #6
0
        public void MessageWasReceived()
        {
            IPhone            smsPhone1  = new SmsPhone(FormFactor.Bar, "BP20200406");
            IPhone            smsPhone2  = new SmsPhone(FormFactor.Bar, "BP20200409");
            string            tesString  = "TEST STRING";
            MockTextBoxOutput mockoutput = new MockTextBoxOutput(richTextBox);

            Action <SmsMessage> subscribe = smsPhone2.UseComponent <Communicator>().SmsSubscribe(mockoutput);

            smsPhone1.UseComponent <Communicator>().SetRecipient(subscribe).SendSms(tesString);

            Assert.IsTrue(methodCalled == 1, $"Method {nameof(mockoutput.WriteLine)} must be called once");
        }
コード例 #7
0
        public async Task PowerIsConsumed()
        {
            IPhone phone = new SmsPhone(FormFactor.Bar, "SP20200502");

            int originalCapacity = phone.UseComponent <Battery>().Capacity;

            await phone.PluginDevice(phone).ExecuteDevice <SmsPhone>(executeTimes: 2);

            int dischargedCapacity = phone.UseComponent <Battery>().Capacity;

            Assert.IsTrue(originalCapacity > 0);
            Assert.IsTrue(originalCapacity > dischargedCapacity);
        }
コード例 #8
0
ファイル: SmsPhoneCrud.cs プロジェクト: kjb7749/testImport
 ///<summary>Inserts one SmsPhone into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(SmsPhone smsPhone)
 {
     if (DataConnection.DBtype == DatabaseType.MySql)
     {
         return(InsertNoCache(smsPhone, false));
     }
     else
     {
         if (DataConnection.DBtype == DatabaseType.Oracle)
         {
             smsPhone.SmsPhoneNum = DbHelper.GetNextOracleKey("smsphone", "SmsPhoneNum");                  //Cacheless method
         }
         return(InsertNoCache(smsPhone, true));
     }
 }
コード例 #9
0
        public async Task MinimumCapacityIs0()
        {
            IPhone phone = new SmsPhone(FormFactor.Bar, "SP20200502");

            phone.UseComponent <Battery>().Capacity = 0;

            int minimumCapacity = phone.UseComponent <Battery>().Capacity;

            await phone.PluginDevice(phone).ExecuteDevice <SmsPhone>(executeTimes: 2);

            int dischargedCapacity = phone.UseComponent <Battery>().Capacity;

            Assert.IsTrue(minimumCapacity == 0);
            Assert.IsTrue(minimumCapacity == dischargedCapacity);
        }
コード例 #10
0
        public async Task PowerIsSupplied()
        {
            IPhone phone = new SmsPhone(FormFactor.Bar, "SP20200502");

            IInterconnection powerBank = new PowerBank("PB20200502");

            powerBank.PluginToUse = Plugins.Usb;

            int originalCapacity = phone.UseComponent <Battery>().Capacity;

            await phone.PluginDevice(powerBank).ExecuteDevice <PowerBank>(executeTimes: 2);

            int chargedCapacity = phone.UseComponent <Battery>().Capacity;

            Assert.IsTrue(originalCapacity < 100);
            Assert.IsTrue(originalCapacity < chargedCapacity);
        }
コード例 #11
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <SmsPhone> TableToList(DataTable table)
        {
            List <SmsPhone> retVal = new List <SmsPhone>();
            SmsPhone        smsPhone;

            foreach (DataRow row in table.Rows)
            {
                smsPhone                  = new SmsPhone();
                smsPhone.SmsPhoneNum      = PIn.Long(row["SmsPhoneNum"].ToString());
                smsPhone.ClinicNum        = PIn.Long(row["ClinicNum"].ToString());
                smsPhone.PhoneNumber      = PIn.String(row["PhoneNumber"].ToString());
                smsPhone.DateTimeActive   = PIn.DateT(row["DateTimeActive"].ToString());
                smsPhone.DateTimeInactive = PIn.DateT(row["DateTimeInactive"].ToString());
                smsPhone.InactiveCode     = PIn.String(row["InactiveCode"].ToString());
                smsPhone.CountryCode      = PIn.String(row["CountryCode"].ToString());
                retVal.Add(smsPhone);
            }
            return(retVal);
        }
コード例 #12
0
        public async Task MaximumCapacityIs100()
        {
            IPhone phone = new SmsPhone(FormFactor.Bar, "SP20200502");

            IInterconnection powerBank = new PowerBank("PB20200502");

            powerBank.PluginToUse = Plugins.Usb;

            phone.UseComponent <Battery>().Capacity = 100;

            int maximumCapacity = phone.UseComponent <Battery>().Capacity;

            await phone.PluginDevice(powerBank).ExecuteDevice <PowerBank>(executeTimes: 2);

            int chargedCapacity = phone.UseComponent <Battery>().Capacity;

            Assert.IsTrue(maximumCapacity == 100);
            Assert.IsTrue(maximumCapacity == chargedCapacity);
        }
コード例 #13
0
        public void FilteringSms(string subString, string receivedFrom, LogicOperand logic, string fromTo, int expectedResults)
        {
            DateTime from, to;

            SetDates(fromTo, out from, out to);

            GeneralPhone smsPhone1 = new SmsPhone(FormFactor.Bar, "BP20200406");

            smsPhone1.AddSimCard(new SimCard());
            GeneralPhone smsPhone2 = new SmsPhone(FormFactor.Bar, "BP20200409");

            smsPhone2.AddSimCard(new SimCard());

            var contact2 = smsPhone2.GetMyContact("Vova");

            smsPhone1.AddContact(contact2);

            int i = 0;

            foreach (string word in words)
            {
                smsPhone1.SendSms(smsText: $"Test Message {i++} {word}", names: "Vova");
            }

            FilterParams filterParams = new FilterParams()
            {
                SubString    = subString,
                ReceivedFrom = receivedFrom,
                Logic        = logic,
                From         = from,
                To           = to
            };
            Func <IEnumerable <GeneralPhone>, FilterParams, ListViewItem[]> filterChanged = UpdateFiltering;

            ListViewItem[] lvItems = filterChanged(new List <GeneralPhone>()
            {
                smsPhone1, smsPhone2
            }, filterParams);

            Assert.AreEqual(words.Length, smsPhone1.UseComponent <Memory>().Get <SmsMessage>().Count());
            Assert.AreEqual(words.Length, smsPhone2.UseComponent <Memory>().Get <SmsMessage>().Count());
            Assert.AreEqual(expectedResults, lvItems.Count());
        }
コード例 #14
0
        public SendManySms()
        {
            InitializeComponent();

            smsPhone1 = new SmsPhone(FormFactor.Bar, "BP20200406");
            smsPhone1.AddSimCard(new SimCard(), output);
            smsPhone2 = new SmsPhone(FormFactor.Bar, "BP20200409");
            smsPhone2.AddSimCard(new SimCard(), output);
            smsPhone3 = new SmsPhone(FormFactor.Bar, "BP20200406");
            smsPhone3.AddSimCard(new SimCard(), output);
            smsPhone4 = new SmsPhone(FormFactor.Bar, "BP20200409");
            smsPhone4.AddSimCard(new SimCard(), output);

            output = new TextBoxOutput(this.receivedSms);

            var contact1 = smsPhone1.GetMyContact("Alex");
            var contact2 = smsPhone2.GetMyContact("Vova");
            var contact3 = smsPhone3.GetMyContact("Stas");
            var contact4 = smsPhone4.GetMyContact("Oleg");

            smsPhone1.AddContact(contact2, contact3, contact4);
            smsPhone2.AddContact(contact1);
            smsPhone3.AddContact(contact1);
            smsPhone4.AddContact(contact1);

            phones = new GeneralPhone[] { smsPhone1, smsPhone2, smsPhone3, smsPhone4 };

            smsFormatting.DataSource = Enum.GetNames(typeof(TextBoxOutput.FormatingStyle));
            cmbWords.DataSource      = new List <string>()
            {
                FILTER_ALL_VALUES
            }.Concat(words).ToArray();
            cmbLogic.DataSource  = Enum.GetNames(typeof(LogicOperand));
            dtpFrom.CustomFormat = "MM/dd/yyyy hh:mm:ss";
            dtpTo.CustomFormat   = "MM/dd/yyyy hh:mm:ss";

            resetFilters();
        }
コード例 #15
0
        ///<summary>Updates one SmsPhone in the database.  Uses an old object to compare to, and only alters changed fields.  This prevents collisions and concurrency problems in heavily used tables.  Returns true if an update occurred.</summary>
        public static bool Update(SmsPhone smsPhone, SmsPhone oldSmsPhone)
        {
            string command = "";

            if (smsPhone.ClinicNum != oldSmsPhone.ClinicNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ClinicNum = " + POut.Long(smsPhone.ClinicNum) + "";
            }
            if (smsPhone.PhoneNumber != oldSmsPhone.PhoneNumber)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "PhoneNumber = '" + POut.String(smsPhone.PhoneNumber) + "'";
            }
            if (smsPhone.DateTimeActive != oldSmsPhone.DateTimeActive)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "DateTimeActive = " + POut.DateT(smsPhone.DateTimeActive) + "";
            }
            if (smsPhone.DateTimeInactive != oldSmsPhone.DateTimeInactive)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "DateTimeInactive = " + POut.DateT(smsPhone.DateTimeInactive) + "";
            }
            if (smsPhone.InactiveCode != oldSmsPhone.InactiveCode)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "InactiveCode = '" + POut.String(smsPhone.InactiveCode) + "'";
            }
            if (smsPhone.CountryCode != oldSmsPhone.CountryCode)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "CountryCode = '" + POut.String(smsPhone.CountryCode) + "'";
            }
            if (command == "")
            {
                return(false);
            }
            command = "UPDATE smsphone SET " + command
                      + " WHERE SmsPhoneNum = " + POut.Long(smsPhone.SmsPhoneNum);
            Db.NonQ(command);
            return(true);
        }
コード例 #16
0
 ///<summary>Inserts one SmsPhone into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(SmsPhone smsPhone)
 {
     return(InsertNoCache(smsPhone, false));
 }