예제 #1
0
        public frm_Main()
        {
            InitializeComponent();
            dgv_ContentTermin.RowTemplate.Height = 50;
            DataAccessLayer DAL = new DataAccessLayer();

            if (frm == null)
            {
                frm = this;
            }
            //Properties.Settings.Default.Reset();



            try
            {
                string selectQuery = "select * from tbl_users where userName = '******' and userPass = '******'";
                DataTable Dt = new DataTable();
                Dt = DAL.fetchData(selectQuery);
                if (Dt.Rows.Count == 0)
                {
                    Properties.Settings.Default.Reset();
                    btn_AddKalender.Enabled = false;
                }
                else
                {
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }



            // Connect to Database
            MySqlConnection mySqlConnection = DAL.myConnection();

            try
            {
                mySqlConnection.Open();
                lbl_OnOff.BackColor = Color.Green;
            }
            catch (Exception ex)
            {
                //To write log file when some problem hapend with the connection to database
                using (StreamWriter w = File.AppendText(Environment.CurrentDirectory + "\\log.txt"))
                {
                    w.WriteLine(DateTime.Now + "-->" + ex.Message);
                }

                lbl_OnOff.BackColor = Color.Red;
            }

            //to get Days of current month
            int DaysOfMonth = DateTime.DaysInMonth(int.Parse(DateTime.Now.ToString("yyyy")), int.Parse(DateTime.Now.ToString("MM")));

            DAL.disconnect(mySqlConnection);

            if (string.IsNullOrEmpty(Properties.Settings.Default.userName) && string.IsNullOrEmpty(Properties.Settings.Default.Password))
            {
                ts_btn_Termin.Enabled = false;
                frm_Login frm_Login = new frm_Login();
                frm_Login.ShowDialog();
            }
            else
            {
                ts_btn_Login.Text = "Abmelden";
                ts_btn_Login.Name = "ts_btn_Abmelden";
                //ts_btn_Login.Image = Image.FromFile(Environment.CurrentDirectory + "\\icon\\Logout.png");
            }

            lbl_UserName.Text = "Benutzer: " + Properties.Settings.Default.userName;

            //fuctions.cmbGenrator(red, green, blue, cbName, cbTitel);
            //TODO: All in one function
            try
            {
                fLP_Kalender.Controls.Clear();
                string    query = "select * from tbl_kalender where userId = " + Properties.Settings.Default.userId;
                DataTable Dt    = DAL.fetchData(query);


                for (int i = 0; i < Dt.Rows.Count; i++)
                {
                    string   kalenderColor = Dt.Rows[i]["color"].ToString();
                    string[] colorArray    = kalenderColor.Split(' ');
                    red   = int.Parse(colorArray[0]);
                    green = int.Parse(colorArray[1]);
                    blue  = int.Parse(colorArray[2]);

                    CheckBox cb = new CheckBox();
                    cb.Name             = "cb_" + Dt.Rows[i]["kalenderName"].ToString();
                    cb.Text             = Dt.Rows[i]["kalenderName"].ToString();
                    cb.BackColor        = Color.FromArgb(red, green, blue);
                    cb.CheckedChanged  += Cb_Selected;
                    cb.MouseHover      += Item_MouseHover;
                    cb.ContextMenuStrip = frm_Main.getMainForm.contextMS_Kalender;
                    frm_Main.getMainForm.fLP_Kalender.Controls.Add(cb);
                }
                Dt.Clear();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            try
            {
                fLP_SharedCalender.Controls.Clear();
                string query = "select k.kalenderName, k.color,u.userName from tbl_kalender as k " +
                               "inner join tbl_shared as s on k.kalender_Id = s.kalenderId " +
                               "inner join tbl_users as u on k.userId = u.user_Id " +
                               "where s.userId = " + Properties.Settings.Default.userId;
                DataTable Dt = DAL.fetchData(query);


                for (int i = 0; i < Dt.Rows.Count; i++)
                {
                    //TO call the value from Color Columns
                    string   kalenderColor = Dt.Rows[i]["color"].ToString();
                    string[] colorArray    = kalenderColor.Split(' ');
                    red   = int.Parse(colorArray[0]);
                    green = int.Parse(colorArray[1]);
                    blue  = int.Parse(colorArray[2]);

                    CheckBox cb = new CheckBox();
                    cb.Name            = "cb_" + Dt.Rows[i]["kalenderName"].ToString();
                    cb.Text            = Dt.Rows[i]["kalenderName"].ToString() + "-(" + Dt.Rows[i]["userName"].ToString() + ")";
                    cb.BackColor       = Color.FromArgb(red, green, blue);
                    cb.CheckedChanged += Cb_Shared_CheckedChanged;
                    cb.MouseHover     += Item_MouseHover;
                    //cb.ContextMenuStrip = frm_Main.getMainForm.contextMS_Kalender;
                    fLP_SharedCalender.Controls.Add(cb);
                }
                Dt.Clear();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #2
0
 private static void Frm_FormClosed(object sender, FormClosedEventArgs e)
 {
     frm = null;
 }