public ManagerForma(OracleConnection conn, ManagerC manager) { InitializeComponent(); LoadingSemaphore = new Semaphore(0, 100); Manager = manager; Conn = conn; pictureBoxLogo.Image = Resources.FASAP_LOGO; Init(); }
public ManagerForma() //probno { InitializeComponent(); string oradb = "Data Source=(DESCRIPTION=" + "(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1620))" + "(CONNECT_DATA=(SERVICE_NAME=ORCL)));" + "User Id=DBA_20132014L_GRP_020;Password=7734924;"; Conn = new OracleConnection(); Conn.ConnectionString = oradb; Conn.Open(); Manager = new ManagerC(8, 1, "Гордана", "Иванова-Крстевска", "*****@*****.**", "1804978455221"); Init(); }
private void logiranje() { { username = tbUserName.Text; password = tbPassword.Text; if (username == "") { MessageBoxForm mbf = new MessageBoxForm("Внесeте корисничко име!", false); mbf.ShowDialog(); tbUserName.Select(); } else if (password == "") { MessageBoxForm mbf = new MessageBoxForm("Внесeте лозинка!", false); mbf.ShowDialog(); tbPassword.Select(); } else { string sql = @"SELECT LOZINKA FROM KORISNIK WHERE KORISNICHKO_IME = :KOR_IME"; // C# OracleCommand cmd = new OracleCommand(sql, Conn); try { OracleParameter prm = new OracleParameter("KOR_IME", OracleDbType.Varchar2); prm.Value = username; cmd.Parameters.Add(prm); cmd.CommandType = CommandType.Text; OracleDataReader dr = cmd.ExecuteReader(); String realPass = ""; // tocniot password od bazata if (dr.Read()) // ako uspee da procita znaci postoi toa korisnicko ime { realPass = dr.GetString(0); tocenUser = true; } else // ne postoi toa korisnicko ime { tocenUser = false; MessageBoxForm mbf = new MessageBoxForm("Не постои тоа корисничко име. Обидете се повторно.", false); mbf.ShowDialog(); tbPassword.Clear(); tbUserName.Clear(); tbUserName.Select(); } // ako postoi korisnickoto ime proveri dali vneseniot password (password) se sovpagja so vistinskiot (realPass) if (tocenUser) { if (password == realPass) { //MessageBox.Show("tocen pasvord"); tocenPass = true; } else { MessageBoxForm mbf = new MessageBoxForm("Внесовте погрешна лозинка. Обидете се повторно.", false); mbf.ShowDialog(); tocenPass = false; tbPassword.Clear(); } } } catch (Exception ex) { MessageBoxForm mbf = new MessageBoxForm("Настана грешка при поврзувањето со базата!", false); if (mbf.ShowDialog() == DialogResult.Yes) { this.Close(); } else { this.Close(); } } //ako e vnesen tocniot password if (tocenPass) { //prvo vcitaj vrabotenID i restoranID sql = @"Select VRABOTEN_ID,RESTORAN_ID from KORISNIK where KORISNICHKO_IME= : KOR_IME"; cmd = new OracleCommand(sql, Conn); try { OracleParameter prm = new OracleParameter("KOR_IME", OracleDbType.Varchar2); prm.Value = username; cmd.Parameters.Add(prm); cmd.CommandType = CommandType.Text; OracleDataReader dr = cmd.ExecuteReader(); if (dr.Read()) { VrabotenId = (int)dr.GetValue(0); RestoranId = (int)dr.GetValue(1); } } catch (Exception ex) { MessageBoxForm mbf = new MessageBoxForm("Настана грешка при поврзувањето со базата!", false); if (mbf.ShowDialog() == DialogResult.Yes) { this.Close(); } else { this.Close(); } } /////////////////////////////////////////// //ako vraboteniot e admin if (VrabotenId == 0) { ManagerC manager = new ManagerC(VrabotenId, RestoranId, "ADMIN", "", username, password); ManagerForma managerForma = new ManagerForma(Conn, manager); managerForma.Show(); tbPassword.Clear(); } else // ako vraboteniot ne e admin (vrabID!=0) vcitaj gi i dr informacii za nego { sql = @"Select v.ime_vraboten, v.prezime_vraboten, i.Pozicija, i.status From Korisnik k join Vraboten v on k.Vraboten_ID=v.Vraboten_ID Join Izvrshuva i on i.Vraboten_ID=v.Vraboten_ID Join Restoran r on r.Restoran_ID=i.Restoran_ID where korisnichko_ime = :KOR_IME"; cmd = new OracleCommand(sql, Conn); try { OracleParameter prm = new OracleParameter("KOR_IME", OracleDbType.Varchar2); prm.Value = username; cmd.Parameters.Add(prm); cmd.CommandType = CommandType.Text; OracleDataReader dr = cmd.ExecuteReader(); if (dr.Read()) { // VrabotenId = (int)dr.GetValue(0); ime = dr.GetString(0); prezime = dr.GetString(1); pozicija = dr.GetString(2); int st; if (int.TryParse(dr.GetString(3), out st)) { status = st; } // RestoranId = (int)dr.GetValue(5); } } catch (Exception ex) { MessageBoxForm mbf = new MessageBoxForm("Настана грешка при поврзувањето со базата!", false); if (mbf.ShowDialog() == DialogResult.Yes) { this.Close(); } else { this.Close(); } } // otkako se procitani podatocite proveri koja funkcija ja izvrsuva // i soodvetno otvori mu forma if (status == 0) //ako vraboteniot e neaktiven, nema privilegii za pristap { MessageBoxForm mbf = new MessageBoxForm("Немате привилегии за пристап!", false); if (mbf.ShowDialog() == DialogResult.Yes) { this.Close(); } else { this.Close(); } } else { if (pozicija.ToLower() == "доставувач") { vraboten = new Dostavuvac(VrabotenId, RestoranId, ime, prezime, username, password); } else if (pozicija.ToLower() == "келнер") { vraboten = new Kelner(VrabotenId, RestoranId, ime, prezime, username, password); } if (pozicija.ToLower() == "менаџер") //ako e manager { ManagerC manager = new ManagerC(VrabotenId, RestoranId, ime, prezime, username, password); ManagerForma managerForma = new ManagerForma(Conn, manager); managerForma.Show(); tbPassword.Clear(); } else //ako e obicen vraboten { VrabotenForma vf = new VrabotenForma(Conn, vraboten); vf.Show(); tbPassword.Clear(); } } } } } } }