using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Shopping.Extra
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            LoadData();
        }

        private void LoadData()
        {
            SqlConnection conn = new SqlConnection();

            try
            {
                conn.ConnectionString = Shopping.Properties.Settings.Default["NikAmoozShop"].ToString();
                string query = " SELECT * FROM [HR].[EmployeeGroup] ";
                query += "SELECT * FROM [Person].[PersonGroup]";
                SqlCommand cmd = new SqlCommand(query, conn);

                conn.Open();

                DataSet dsGroups = new DataSet();
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(dsGroups);

                cmbEmployeeGroups.DataSource = dsGroups.Tables[0];
                cmbEmployeeGroups.ValueMember = "EmployeeGroupID";
                cmbEmployeeGroups.DisplayMember = "EmployeeGroupTitle";

                cmbPersonGroup.DataSource = dsGroups.Tables[1];
                cmbPersonGroup.ValueMember = "PersonGroupID";
                cmbPersonGroup.DisplayMember = "PersonGroupTitle";

               
            }
            catch (SqlException ex)
            {
                MessageBox.Show("وقوع مشکل در هنگام کار با دیتایس" + "\n" + ex.Message, "خطای بانک اطلاعاتی", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            catch (Exception ex)
            {
                MessageBox.Show("وقوع مشکل در سیستم" + "\n" + ex.Message, "خطای سیستمی", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            finally
            {
                conn.Close();
            }
        }
    }
}
