public void RefreshCat() { SQL sql = new SQL(); FbDataReader reader = sql.StartQuery("SELECT * FROM CAT"); Info_cat_txt.Items.Clear(); try { while (reader.Read()) { Info_cat_txt.Items.Add(reader.GetString(1)); Info_cat_txt.Text = Info_cat_txt.Items[0].ToString(); } } finally { sql.EndQuery(); Info_cat_txt.Text = catName; } }
private void Enter_Click(object sender, EventArgs e) { SQL sql = new SQL(); try { FbDataReader reader = sql.StartQuery("SELECT * FROM PERSONAL"); Program.user = new Personal(); if(sql.error==0) while (true) { if (reader.Read()) { } else { break; } int a; if (reader.GetString(1) == Auth_name.Text && (!reader.IsDBNull(2) & reader.GetString(2) == Auth_pass.Text)) { log = true; if(!reader.IsDBNull(3) & reader.GetString(3)=="1"){ Program.Perm_Ad = true; Program.user.add = true; } if (!reader.IsDBNull(4) & reader.GetString(4) == "1") { Program.Perm_CreatePDF = true; Program.user.create_pdf = true; } if (!reader.IsDBNull(5) & reader.GetString(5) == "1") { Program.Perm_Change = true; Program.user.change = true; } if (!reader.IsDBNull(6) & reader.GetString(6) == "1") { Program.Perm_Download = true; Program.user.download = true; } if (!reader.IsDBNull(7) & reader.GetString(7) == "1") { Program.Perm_Admin = true; Program.user.admin = true; } if (!reader.IsDBNull(8) ) { Program.user.Name = reader.GetString(8); } if (!reader.IsDBNull(9) ) { Program.user.scndName = reader.GetString(9); } if (!reader.IsDBNull(10)) { Program.user.title = reader.GetString(10); } break; } } } finally { sql.EndQuery(); } if (log) { Program.mainform = new Form1(); Program.mainform.Show(); Program.Auth_form.Close(); } else { MessageBox.Show("Неверный логин или пароль"); } }
private int GetCatID(String cat) { SQL sql = new SQL(); FbDataReader reader = sql.StartQuery("SELECT * FROM CAT"); try { while (reader.Read()) { if (reader.GetString(1).ToString() == cat) { return reader.GetInt32(0); } } } finally { sql.EndQuery(); } return -1; }
private void Info_change_Click(object sender, EventArgs e) { if (isLoginOk()) { if (name != Info_name_txt.Text || number != Info_number_txt.Text || catName != Info_cat_txt.Text || jpg != Info_jpg.Image || tag != Info_tags.Text || (picbox.coin.date.Day+"."+picbox.coin.date.Month+"."+picbox.coin.date.Year)!=Info_date_txt.Text) { int catid = GetCatID(Info_cat_txt.Text); int catid_f = GetCatID(catName); SQL sql = new SQL(); if (Info_number_txt.Text == "") { Info_number_txt.Text = "0"; } String new_jpg_path = JPGName; String new_cdr_path = CDRName; if (bm != null) { bm = ResizeBitmap(bm); } WebClient wc = new WebClient(); int sec = picbox.coin.sec; /* if (picbox.coin.image != Info_jpg.Image) { wc.UploadFile(Program.JPGserver + JPGName + sec, "STOR", JPGPath); JPGName += "" + sec; } else { JPGName = picbox.coin.JPGPath; }*/ if (JPGPath != null) { bm.Save(Application.StartupPath + "\\" + new_jpg_path); wc.UploadFile(Program.JPGserver + new_jpg_path + sec, "STOR", Application.StartupPath + "\\" + new_jpg_path); System.IO.File.Delete(Application.StartupPath + "\\" + new_jpg_path); new_jpg_path += "" + sec; picbox.coin.JPGPath = new_jpg_path; picbox.coin.image = (Bitmap)bm; picbox.Image = picbox.coin.image; } else { new_jpg_path = picbox.coin.JPGPath; } if (CDRPath != null) { wc.UploadFile(Program.CDRserver + new_cdr_path + sec, "STOR", CDRPath); new_cdr_path += "" + sec; picbox.coin.CDRPath = new_cdr_path; } else { new_cdr_path = picbox.coin.CDRPath; } String day = ""; String month = ""; String year = ""; String date=""; if ((picbox.coin.date.Day + "." + picbox.coin.date.Month + "." + picbox.coin.date.Year) != Info_date_txt.Text) { try { String tmp; day = Info_date_txt.Text.Substring(0, Info_date_txt.Text.IndexOf(".")); tmp = Info_date_txt.Text.Substring(Info_date_txt.Text.IndexOf(".") + 1, Info_date_txt.Text.Length - Info_date_txt.Text.IndexOf(".") - 1); month = tmp.Substring(0, tmp.IndexOf(".")); tmp = tmp.Substring(tmp.IndexOf(".") + 1, tmp.Length - tmp.IndexOf(".") - 1); year = tmp; date = int.Parse(month) + "/" + int.Parse(day) + "/" + int.Parse(year); } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { date = picbox.coin.date.Month + "/" + picbox.coin.date.Day + "/" + picbox.coin.date.Year; } String test11 = ""; test11 = "UPDATE COINS SET NAME = '" + Info_name_txt.Text + "'" + ", \"DATE\" = '" + date + ", TAG = '" + Info_tags.Text + "', NUMBER = " + int.Parse(Info_number_txt.Text) + ", CAT = " + catid + ", IMAGE_JPG = '" + new_jpg_path + "'" + ", IMAGE_CDR = '" + new_cdr_path + "'" + " WHERE " + "NAME = '" + name + "'AND NUMBER = " + int.Parse(number) + "AND CAT = " + catid_f; sql.ExecuteNonQuery("UPDATE COINS SET NAME = '" + Info_name_txt.Text + "'"+", \"DATE\" = '" + date +"', TAG = '" + Info_tags.Text + "', NUMBER = " + int.Parse(Info_number_txt.Text) + ", CAT = " + catid + ", IMAGE_JPG = '" + new_jpg_path + "'" + ", IMAGE_CDR = '" + new_cdr_path + "'" + " WHERE " + "NAME = '" + name + "'AND NUMBER = " + int.Parse(number) + "AND CAT = " + catid_f); picbox.coin.name = Info_name_txt.Text; picbox.coin.number = int.Parse(Info_number_txt.Text); picbox.coin.tag = Info_tags.Text; if ((picbox.coin.date.Day + "." + picbox.coin.date.Month + "." + picbox.coin.date.Year) != Info_date_txt.Text) { picbox.coin.date.AddDays(int.Parse(day)); picbox.coin.date.AddMonths(int.Parse(month)); picbox.coin.date.AddYears(int.Parse(year)); } Program.mainform.refreshCoinIdtoName(); Program.mainform.sort(); } } }
private void Manager_addpersonal_Click(object sender, EventArgs e) { Personal p = new Personal(); if (isadd) { if (isLoginOk()) { isadd = false; Manager_addpersonal.Text = "Добавить"; SQL sql = new SQL(); int add_int; int change_int; int dl_int; int create_int; int admin_int; if (Manger_chk_add.Checked) { add_int = 1; } else { add_int = 0; } if (Manger_chk_change.Checked) { change_int = 1; } else { change_int = 0; } if (Manger_chk_download.Checked) { dl_int = 1; } else { dl_int = 0; } if (Manger_chk_createPDF.Checked) { create_int = 1; } else { create_int = 0; } if (Manger_chk_admin.Checked) { admin_int = 1; } else { admin_int = 0; } sql.ExecuteNonQuery("INSERT INTO PERSONAL (USER_LOGIN,PASS,ADD_COIN,CREATE_PDF,CHANGE,DOWNLOAD,ADMIN_RULE,NAME,LAST_NAME,TITLE) VALUES('" + Manager_login_txt.Text + "','" + Manager_pass_txt.Text + "'," + add_int + "," + create_int + "," + change_int + "," + dl_int + "," + admin_int + ",'" + Manager_name_txt.Text + "','" + Manage_lastname_txt.Text + "','" + Manager_title_txt.Text + "')"); p = pers[pers.Count - 1]; p.login = Manager_login_txt.Text; p.pass = Manager_pass_txt.Text; p.add = Manger_chk_add.Checked; p.change = Manger_chk_change.Checked; p.download = Manger_chk_download.Checked; p.create_pdf = Manger_chk_createPDF.Checked; p.admin = Manger_chk_admin.Checked; p.Name = Manager_name_txt.Text; p.scndName = Manage_lastname_txt.Text; p.title = Manager_title_txt.Text; refreshPers(); Manager_personal_list.SetSelected(Manager_personal_list.Items.Count - 1, true); select(); } else { MessageBox.Show("Два пользователя с одним логином"); } }else{ isadd=true; Manager_personal_list.Items.Add("Пользователь"); Manager_personal_list.SetSelected(Manager_personal_list.Items.Count-1,true); p.login = "******"; // p.scndName = "Пользователь "; pers.Add(p); select(); Manager_addpersonal.Text = "Cохранить"; } }
private void Manager_Load(object sender, EventArgs e) { SQL sql = new SQL(); FbDataReader reader = sql.StartQuery("SELECT * FROM PERSONAL"); try { while (reader.Read()) { Personal p = new Personal(); p.login = reader.GetString(1); p.pass = reader.GetString(2); if (reader.GetInt32(3) == 1) { p.add = true; } else { p.add = false; } if (reader.GetInt32(4) == 1) { p.create_pdf = true; } else { p.create_pdf = false; } if (reader.GetInt32(5) == 1) { p.change = true; } else { p.change = false; } if (reader.GetInt32(6) == 1) { p.download = true; } else { p.download = false; } if (reader.GetInt32(7) == 1) { p.admin = true; } else { p.admin = false; } if (!reader.IsDBNull(8)) { p.Name = reader.GetString(8); } if (!reader.IsDBNull(9)) { p.scndName = reader.GetString(9); } if (!reader.IsDBNull(10)) { p.title = reader.GetString(10); } pers.Add(p); } } finally { sql.EndQuery(); refreshPers(); Manager_personal_list.SetSelected(0, true); select(); } sql = new SQL(); reader = sql.StartQuery("SELECT * FROM CAT"); try { while (reader.Read()) { Cat c = new Cat(); c.cat = reader.GetString(1); c.id = reader.GetInt32(0); cat.Add(c); } } finally { sql.EndQuery(); refreshCat(); } }
private void Manager_del_Click(object sender, EventArgs e) { del = true; SQL sql = new SQL(); if(!isLastAdmin()){ sql.ExecuteNonQuery("DELETE FROM PERSONAL WHERE " + "USER_LOGIN = '******'"); for (int i = 0; i < pers.Count; i++) { if (pers[i].login==personal.login) { pers.RemoveAt(i); Manager_personal_list.Items.RemoveAt(i); refreshPers(); Manager_personal_list.SetSelected(0, true); select(); } } } del = false; }
private void Manager_change_Click(object sender, EventArgs e) { if (isLoginOk()) { if (personal.login != Manager_login_txt.Text || personal.pass != Manager_pass_txt.Text || personal.add != Manger_chk_add.Checked || personal.change != Manger_chk_change.Checked || personal.download != Manger_chk_download.Checked || personal.create_pdf != Manger_chk_createPDF.Checked || personal.admin != Manger_chk_admin.Checked || personal.Name != Manager_name_txt.Text || personal.scndName != Manage_lastname_txt.Text || personal.title != Manager_title_txt.Text ) { int add_int; int change_int; int dl_int; int create_int; int admin_int; if (Manger_chk_add.Checked) { add_int = 1; } else { add_int = 0; } if (Manger_chk_change.Checked) { change_int = 1; } else { change_int = 0; } if (Manger_chk_download.Checked) { dl_int = 1; } else { dl_int = 0; } if (Manger_chk_createPDF.Checked) { create_int = 1; } else { create_int = 0; } if (Manger_chk_admin.Checked) { admin_int = 1; } else { admin_int = 0; } SQL sql = new SQL(); sql.ExecuteNonQuery("UPDATE PERSONAL SET USER_LOGIN = '******', PASS = '******', ADD_COIN = " + add_int + ", CREATE_PDF = " + create_int + ", CHANGE = " + change_int + ", DOWNLOAD = " + dl_int + ", ADMIN_RULE = " + admin_int + ", NAME = '" + Manager_name_txt.Text + "'" + ", LAST_NAME = '" + Manage_lastname_txt.Text + "'" + ", TITLE = '" + Manager_title_txt.Text + "'" + " WHERE " + "USER_LOGIN = '******'"); personal.login = Manager_login_txt.Text; personal.pass = Manager_pass_txt.Text; personal.add = Manger_chk_add.Checked; personal.change = Manger_chk_change.Checked; personal.download = Manger_chk_download.Checked; personal.create_pdf = Manger_chk_createPDF.Checked; personal.admin = Manger_chk_admin.Checked; personal.Name = Manager_name_txt.Text; personal.scndName = Manage_lastname_txt.Text; personal.title = Manager_title_txt.Text; } } else { MessageBox.Show("Два пользователя с одним логином"); } }
private void Manager_cat_del_Click(object sender, EventArgs e) { del = true; SQL sql = new SQL(); if (Selected_cat!=null) { sql.ExecuteNonQuery("DELETE FROM CAT WHERE " + "ID = " + Selected_cat.id); sql.ExecuteNonQuery("DELETE FROM COINS WHERE " + "CAT = " + Selected_cat.id); for (int i = 0; i < cat.Count; i++) { if (cat[i].id == Selected_cat.id) { cat.RemoveAt(i); refreshCat(); // select(); } } } Program.mainform.refreshCatList(); del = false; }