Exemplo n.º 1
0
        public void Should_initialize_instance(decimal value)
        {
            var actual = new NOK(value);

            Assert.IsAssignableFrom <NOK>(actual);
            Assert.AreEqual(value, actual.Value, nameof(actual.Value));
        }
Exemplo n.º 2
0
        public void Should_compare_with_null_instance(decimal value)
        {
            var instance = new NOK(value);

            Assert.IsFalse(instance.Equals(null), "Equals");
            Assert.AreEqual(1, instance.CompareTo(null), "CompareTo");
        }
Exemplo n.º 3
0
        public void Should_throw_exception_on_division_by_zero(decimal value)
        {
            var instance = new NOK(value);

            Assert.Throws <DivideByZeroException>(() => {
                var unused = instance / 0;
            });
        }
Exemplo n.º 4
0
        public void Should_cast_to_decimal(decimal value)
        {
            var instance = new NOK(value);

            var actual = (decimal)instance;

            Assert.AreEqual(value, actual);
        }
Exemplo n.º 5
0
        public void Should_cast_from_decimal(decimal value)
        {
            var expected = new NOK(value);

            var actual = (NOK)value;

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 6
0
        public void Should_compare_with_another_type_of_instance(decimal value)
        {
            var    instance1 = new NOK(value);
            object instance2 = value;

            Assert.IsFalse(instance1.Equals(instance2), "Equals");
            Assert.Throws <ArgumentException>(() => instance1.CompareTo(instance2), "CompareTo");
        }
Exemplo n.º 7
0
        public void Should_convert_to_string(decimal value)
        {
            var expected = $"kr {value:0.00}";

            var instance = new NOK(value);
            var actual   = instance.ToString();

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 8
0
        public void Should_floor_value(double value, double expectedValue)
        {
            var expected = new NOK((decimal)expectedValue);

            var instance = new NOK((decimal)value);
            var actual   = instance.Floor();

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 9
0
        public void Should_roundvalue_withMode(MidpointRounding mode, double value, double expectedValue)
        {
            var expected = new NOK((decimal)expectedValue);

            var instance = new NOK((decimal)value);
            var actual   = instance.Round(mode);

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 10
0
        public void Should_own_a_HashCode(decimal value)
        {
            var expected = value.GetHashCode();

            var instance = new NOK(value);
            var actual   = instance.GetHashCode();

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 11
0
        public void Should_format_string(string format, string mask)
        {
            var expected = string.Format(Consts.CultureEnUS, mask, 1.7578m);

            var instance = new NOK(1.7578m);
            var actual   = instance.ToString(format, Consts.CultureEnUS);

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 12
0
        public void Should_divide_instance_by_decimal(double leftValue, double rightValue, double expectedValue)
        {
            var expected = new NOK((decimal)expectedValue);

            var instance = new NOK((decimal)leftValue);
            var actual   = instance / (decimal)rightValue;

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 13
0
        public void Should_round_value_withDigit(double value, double expectedValue)
        {
            var expected = new NOK((decimal)expectedValue);

            var instance = new NOK((decimal)value);
            var actual   = instance.Round(1);

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 14
0
        public void Should_multiply_decimal_by_instance(double leftValue, double rightValue, double expectedValue)
        {
            var expected = new NOK((decimal)expectedValue);

            var instance = new NOK((decimal)rightValue);

            var actual = (decimal)leftValue * instance;

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 15
0
        public void Should_subtract_two_instances(double leftValue, double rightValue, double expectedValue)
        {
            var expected = new NOK((decimal)expectedValue);

            var leftInstance  = new NOK((decimal)leftValue);
            var rightInstance = new NOK((decimal)rightValue);
            var actual        = leftInstance - rightInstance;

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 16
0
        private void PopulateForm(int patientID)
        {
            BtnSave.Enabled   = false;
            BtnUpdate.Enabled = true;
            TxtPatientID.Text = patientID.ToString();
            TxtForename.Text  = hospitalMS.tblPatientDetails.Single(x => x.PatientId == patientID).PatientForename;
            TxtSurname.Text   = hospitalMS.tblPatientDetails.Single(x => x.PatientId == patientID).PatientSurename;
            TxtDOBDay.Text    = hospitalMS.tblPatientDetails.Single(x => x.PatientId == patientID).PatientDOB.Day.ToString("D2");
            TxtDOBMonth.Text  = hospitalMS.tblPatientDetails.Single(x => x.PatientId == patientID).PatientDOB.Month.ToString("D2");
            TxtDOBYear.Text   = hospitalMS.tblPatientDetails.Single(x => x.PatientId == patientID).PatientDOB.Year.ToString();

            // Only One of these will end up checked
            ////bool gender = hospitalMS.tblPatientDetails.Single(x => x.PatientId == patientID).PatientGender;
            ////(gender) ? RdoMale.Checked = gender : RdoFemale.Checked;

            RdoMale.Checked   = hospitalMS.tblPatientDetails.Single(x => x.PatientId == patientID).PatientGender;
            RdoFemale.Checked = !hospitalMS.tblPatientDetails.Single(x => x.PatientId == patientID).PatientGender;

            TxtPhoneNum.Text = hospitalMS.tblPatientDetails.Single(x => x.PatientId == patientID).PatientPhoneNum.ToString();

            // Address stored as comma seperated values in database, remove the commas and print each line on a new line in the text box
            string address = hospitalMS.tblPatientDetails.Single(x => x.PatientId == patientID).PatientAddress;

            TxtAddress.Text = address.Replace(", ", ",\r\n");

            // NOK Details are stored in JSON format in the Database.
            // They are retrieved here and stored in a string.
            string nokDetailsJSONString = hospitalMS.tblPatientDetails.Single(x => x.PatientId == patientID).PatientNOK;

            // String is read as JSON here and stored in the nokDetailsConverted variable
            var nokDetailsConverted = JsonConvert.DeserializeObject <dynamic>(nokDetailsJSONString);
            // New NOK Class is initialized
            NOK nok = new NOK();

            // JSON values are assigned to NOK Class properties
            nok.NOKName     = nokDetailsConverted.NOKName;
            nok.NOKPhoneNum = nokDetailsConverted.NOKPhoneNum;
            // NOK Class properties are assigned to relevant text boxes.
            TxtNOKName.Text     = nok.NOKName;
            TxtNOKPhoneNum.Text = nok.NOKPhoneNum;

            // Extra code to get all Patient IDs in the Database.
            var allIDs = hospitalMS.tblPatientDetails.Select(x => x.PatientSurename).ToList();

            // Loop through all Patient IDs retrieved
            foreach (var row in allIDs)
            {
                Console.WriteLine(row);
            }
        }
Exemplo n.º 17
0
        private void SavePatientDetails()
        {
            tblPatientDetail patient = new tblPatientDetail();

            patient.PatientForename = TxtForename.Text;
            patient.PatientSurename = TxtSurname.Text;

            // Format the three text fields for DOB as a string and convert to a DateTime Type
            var patientDOB = Convert.ToDateTime(TxtDOBYear.Text + "-" + TxtDOBMonth.Text + "-" + TxtDOBDay.Text);

            patient.PatientDOB = patientDOB;
            Console.WriteLine(patientDOB);

            if (RdoMale.Checked)
            {
                patient.PatientGender = true;
            }
            else if (RdoFemale.Checked)
            {
                patient.PatientGender = false;
            }
            else
            {
                Console.WriteLine("Gender Error");
            }

            patient.PatientAddress  = TxtAddress.Text;
            patient.PatientPhoneNum = TxtPhoneNum.Text;

            NOK nok = new NOK();

            nok.NOKName     = TxtNOKName.Text;
            nok.NOKPhoneNum = TxtNOKPhoneNum.Text;
            string JSONresult = JsonConvert.SerializeObject(nok);

            patient.PatientNOK = JSONresult;

            hospitalMS.tblPatientDetails.InsertOnSubmit(patient);
            ////hospitalMS.tblPatientDetails.UpdateOnSubmit(patient);
            hospitalMS.SubmitChanges();
            ////hospitalMS.tblPatientDetails.SaveChanges();
            Console.WriteLine(JSONresult);
        }
Exemplo n.º 18
0
        private void UpdatePatientDetails()
        {
            int patientID = Int32.Parse(TxtPatientID.Text);

            using (HospitalMSDataContext hospitalMS = new HospitalMSDataContext())
            {
                // "id" is the id in your table (parameter passed)
                //Patient patient = hospitalMS.tblPatientDetails.Find(patientID).First();   // Find may be only for Entity Framework. If you can't use it, use the line below

                var patient = hospitalMS.tblPatientDetails.Where(x => x.PatientId == patientID).First();

                patient.PatientForename = TxtForename.Text;
                patient.PatientSurename = TxtSurname.Text;
                var patientDOB = Convert.ToDateTime(TxtDOBYear.Text + "-" + TxtDOBMonth.Text + "-" + TxtDOBDay.Text);
                patient.PatientDOB = patientDOB;

                if (RdoMale.Checked)
                {
                    patient.PatientGender = true;
                }
                else if (RdoFemale.Checked)
                {
                    patient.PatientGender = false;
                }
                else
                {
                    Console.WriteLine("Gender Error");
                }

                patient.PatientPhoneNum = TxtPhoneNum.Text;
                patient.PatientAddress  = TxtAddress.Text;

                NOK nok = new NOK();
                nok.NOKName     = TxtNOKName.Text;
                nok.NOKPhoneNum = TxtNOKPhoneNum.Text;
                string JSONresult = JsonConvert.SerializeObject(nok);
                patient.PatientNOK = JSONresult;

                hospitalMS.SubmitChanges();
                FormLoad();
            };
        }
Exemplo n.º 19
0
        public void Should_compare_with_smaller_value(double baseValue, double smallerValue)
        {
            var baseInstance    = new NOK((decimal)baseValue);
            var smallerInstance = new NOK((decimal)smallerValue);

            Assert.IsFalse(baseInstance.Equals(smallerInstance), "Equals");
            Assert.IsFalse(baseInstance.Equals((object)smallerInstance), "Equals object");

            Assert.IsFalse(baseInstance == smallerInstance, "==");
            Assert.IsTrue(baseInstance != smallerInstance, "!=");

            Assert.AreEqual(+1, baseInstance.CompareTo(smallerInstance), "CompareTo");
            Assert.AreEqual(+1, baseInstance.CompareTo((object)smallerInstance), "CompareTo object");

            Assert.IsFalse(baseInstance < smallerInstance, "<");
            Assert.IsTrue(baseInstance > smallerInstance, ">");

            Assert.IsFalse(baseInstance <= smallerInstance, "<=");
            Assert.IsTrue(baseInstance >= smallerInstance, ">=");
        }
Exemplo n.º 20
0
        public void Should_compare_with_same_value(decimal value)
        {
            var baseInstance  = new NOK(value);
            var otherInstance = new NOK(value);

            Assert.IsTrue(baseInstance.Equals(otherInstance), "Equals");
            Assert.IsTrue(baseInstance.Equals((object)otherInstance), "Equals object");

            Assert.IsTrue(baseInstance == otherInstance, "==");
            Assert.IsFalse(baseInstance != otherInstance, "!=");

            Assert.AreEqual(0, baseInstance.CompareTo(otherInstance), "CompareTo");
            Assert.AreEqual(0, baseInstance.CompareTo((object)otherInstance), "CompareTo object");

            Assert.IsFalse(baseInstance < otherInstance, "<");
            Assert.IsFalse(baseInstance > otherInstance, ">");

            Assert.IsTrue(baseInstance <= otherInstance, "<=");
            Assert.IsTrue(baseInstance >= otherInstance, ">=");
        }
Exemplo n.º 21
0
        public void Should_compare_with_bigger_value(double baseValue, double biggerValue)
        {
            var baseInstance   = new NOK((decimal)baseValue);
            var biggerInstance = new NOK((decimal)biggerValue);

            Assert.IsFalse(baseInstance.Equals(biggerInstance), "Equals");
            Assert.IsFalse(baseInstance.Equals((object)biggerInstance), "Equals object");

            Assert.IsFalse(baseInstance == biggerInstance, "==");
            Assert.IsTrue(baseInstance != biggerInstance, "!=");

            Assert.AreEqual(-1, baseInstance.CompareTo(biggerInstance), "CompareTo");
            Assert.AreEqual(-1, baseInstance.CompareTo((object)biggerInstance), "CompareTo object");

            Assert.IsTrue(baseInstance < biggerInstance, "<");
            Assert.IsFalse(baseInstance > biggerInstance, ">");

            Assert.IsTrue(baseInstance <= biggerInstance, "<=");
            Assert.IsFalse(baseInstance >= biggerInstance, ">=");
        }
Exemplo n.º 22
0
        public void Should_have_a_symbol(decimal value)
        {
            ICurrency actual = new NOK(value);

            Assert.AreEqual(NOK.Symbol, actual.Symbol);
        }
Exemplo n.º 23
0
        private void button1_Click(object sender, EventArgs e)
        {
            N = (int)dataGridView1.RowCount - 1;
            try
            {
                for (int i = 0; i < N; i++)
                {
                    error = i;
                    a     = Convert.ToInt32(dataGridView1.Rows[i].Cells[0].Value);
                }
            }
            catch
            {
                dataGridView1.Rows[error].Cells[0].Style.BackColor = Color.Red;
                MessageBox.Show("Ошибка");
                Application.Restart();
            }

            a = Math.Abs(Convert.ToInt32(dataGridView1.Rows[0].Cells[0].Value));
            b = Math.Abs(Convert.ToInt32(dataGridView1.Rows[1].Cells[0].Value));
            h = a * b;
            if (a < b)
            {
                a = b;
                b = h / a;
            }
            while (b != 0)
            {
                r = a % b;
                a = b;
                b = r;
            }
            NOD = a;
            NOK = h / a;
            for (int i = 2; i < N; i++)
            {
                a = NOD;
                b = Math.Abs(Convert.ToInt32(dataGridView1.Rows[i].Cells[0].Value));
                h = a * b;
                if (a < b)
                {
                    a = b;
                    b = h / a;
                }
                while (b != 0)
                {
                    r = a % b;
                    a = b;
                    b = r;
                }
                NOD = a;
            }
            for (int i = 2; i < N; i++)
            {
                c = NOK;
                b = Math.Abs(Convert.ToInt32(dataGridView1.Rows[i].Cells[0].Value));
                g = c * b;
                if (c < b)
                {
                    c = b;
                    b = g / c;
                }
                while (b != 0)
                {
                    r = c % b;
                    c = b;
                    b = r;
                }
                NOK = g / c;
            }
            textBox3.Text = NOD.ToString();
            textBox4.Text = NOK.ToString();
        }