public List <Depertment> RetrivedataFromDatabase()
        {
            string            query       = @"SELECT * FROM DepertmentInfo";
            List <Depertment> depertments = new List <Depertment>();

            //*****Database Operation Starts********
            connection.Open();

            aCommand = new SqlCommand(query, connection);

            aReader = aCommand.ExecuteReader();
            if (aReader.HasRows)
            {
                while (aReader.Read())
                {
                    Depertment aDepertment = new Depertment();
                    aDepertment.DepertmentID   = (int)aReader[0];
                    aDepertment.DepertmentName = aReader[1].ToString();
                    aDepertment.DepertmentCode = aReader[2].ToString();
                    depertments.Add(aDepertment);
                }
            }
            connection.Close();
            //*****Database Operation Ends********

            return(depertments);
        }
Exemplo n.º 2
0
        private void saveButton_Click(object sender, EventArgs e)
        {
            Depertment aDepertment = new Depertment();

            string name    = studentNameTextBox.Text;
            string email   = emailTextBox.Text;
            string address = addressTextBox.Text;
            string depertmentId;

            studentNameTextBox.Text = string.Empty;
            emailTextBox.Text       = string.Empty;
            addressTextBox.Text     = string.Empty;

            Student aStudent = new Student();

            aStudent.StudentName  = name;
            aStudent.Email        = email;
            aStudent.Address      = address;
            aDepertment           = (Depertment)depertmentComboBox.SelectedItem;
            aStudent.DepertmentId = aDepertment.DepertmentID;

            aStudentBll = new StudentBLL();
            string confirmationMessege = aStudentBll.Save(aStudent);

            MessageBox.Show(confirmationMessege);
            ShowInGridView();
        }
Exemplo n.º 3
0
        private void saveButton_Click(object sender, EventArgs e)
        {
            Depertment aDepertment = new Depertment(nameTextBox.Text, codeTextBox.Text);

            aDepertmentBll = new DepertmentBLL();
            string messege = aDepertmentBll.CheckAndSave(aDepertment);

            MessageBox.Show(messege);
            ShowInGridView();
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            Console.Write("Enter department's name: ");
            string departName = Console.ReadLine();

            Console.WriteLine("Enter worker data: ");
            Console.Write("Name: ");
            string name = Console.ReadLine();

            Console.Write("Level (Junior/MidLevel/Senior): ");
            WorkerLvel level = Enum.Parse <WorkerLvel>(Console.ReadLine());

            Console.Write("Base salary: ");
            double baseSalary = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture);

            Depertment depertment = new Depertment(departName);
            Worker     worker     = new Worker(name, level, baseSalary, depertment);

            Console.WriteLine();
            Console.Write("How many contracts to this worker ? ");
            int n = int.Parse(Console.ReadLine());

            Console.WriteLine();

            for (int i = 1; i <= n; i++)
            {
                Console.WriteLine($"Enter #{i} contract data: ");
                Console.Write("Date (DD/MM/YYYY): ");
                DateTime date = DateTime.Parse(Console.ReadLine());
                Console.Write("Valeu per hour: ");
                double valeuPerHour = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture);
                Console.Write("Duration (hours): ");
                int duration = int.Parse(Console.ReadLine());
                Console.WriteLine();
                HourContract contract = new HourContract(date, valeuPerHour, duration);
                worker.AddContract(contract);
            }

            Console.WriteLine();
            Console.Write("Enter month and year to calculate income (MM/YYYY): ");
            string monthAndYear = Console.ReadLine();
            int    month        = int.Parse(monthAndYear.Substring(0, 2));
            int    year         = int.Parse(monthAndYear.Substring(3));

            Console.WriteLine("Name: " + worker.Name);
            Console.WriteLine("Depertment: " + worker.Depertment.Name);
            Console.WriteLine("Income for " + monthAndYear + ": " + worker.Income(year, month).ToString("f2", CultureInfo.InvariantCulture));
        }
        public int SaveInDatabase(Depertment aDepertment)
        {
            string query = string.Format("INSERT INTO DepertmentInfo VALUES ('{0}','{1}')", aDepertment.DepertmentName, aDepertment.DepertmentCode);

            //*****Database Operation Starts********
            connection.Open();

            aCommand = new SqlCommand(query, connection);

            int isAffected = aCommand.ExecuteNonQuery();

            connection.Close();
            //*****Database Operation Ends********

            return(isAffected);
        }
Exemplo n.º 6
0
        public string CheckAndSave(Depertment aDepertment)
        {
            if (aDepertment.DepertmentName != string.Empty || aDepertment.DepertmentCode != string.Empty)
            {
                if (DepertmentNotAlreadyExists(aDepertment))
                {
                    int isAffected = aDepertmentGateway.SaveInDatabase(aDepertment);
                    if (isAffected > 0)
                    {
                        return("Data Saved In DataBase");
                    }
                    else
                    {
                        return("Something Wrong with Insertion");
                    }
                }
                return("Data is already Exist");
            }

            return(@"Fill up all the fields");
        }
        public bool Check(Depertment aDepertment)
        {
            string name  = aDepertment.DepertmentName;
            string query = string.Format("SELECT * FROM DepertmentInfo WHERE DeptName='{0}'", name);


            //*****Database Operation Starts********
            connection.Open();

            aCommand = new SqlCommand(query, connection);

            aReader = aCommand.ExecuteReader();
            if (aReader.HasRows)
            {
                return(false);
            }

            connection.Close();
            //*****Database Operation Ends********
            return(true);
        }
Exemplo n.º 8
0
 private bool DepertmentNotAlreadyExists(Depertment aDepertment)
 {
     return(aDepertmentGateway.Check(aDepertment));
 }
 private void saveButton_Click(object sender, EventArgs e)
 {
     aDepertment = new Depertment(departmentCodeTextBox.Text,DepartmentNameTextBox.Text);
     MessageBox.Show("Department Created");
 }
Exemplo n.º 10
0
 Task <Depertment> IRepository <Depertment> .UpdateRange(Depertment entity)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 11
0
 Task <bool> IRepository <Depertment> .Delete(Depertment entity)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 12
0
 Task <Depertment> IRepository <Depertment> .Add(Depertment entity)
 {
     throw new NotImplementedException();
 }