private void button3_Click(object sender, EventArgs e) // UPDATE { try { if (checkedListBox1.CheckedItems.Count != 0) // copy into 'Choose' the value of the checked item { for (int x = 0; x < checkedListBox1.CheckedItems.Count; x++) { choose = checkedListBox1.CheckedItems[x].ToString(); } } con.Open(); Sha pass = new Sha(textBox3.Text); string cipher = pass.GetPassword().ToString(); SqlCommand cmd = new SqlCommand(@"UPDATE Login SET login_id = '" + textBox1.Text + "',username = '******', password = '******',rank = '" + choose.ToString() + "',pass_mail = '" + textBox5.Text + "',fname = '" + textBox6.Text + "' WHERE (login_id = '" + textBox1.Text + "')", con); cmd.ExecuteNonQuery(); MessageBox.Show("Update Successfully !"); } catch (Exception err) { MessageBox.Show(err.Message); } clear(); Display(); con.Close(); }
private void button1_Click(object sender, EventArgs e) // LOGING BTN { con.Open(); Sha pass = new Sha(textBox2.Text); string crypto = pass.GetPassword().ToString(); string query = "Select * from Login Where username = '******' and password = '******' and pass_mail='" + textBox6.Text.Trim() + "'"; SqlDataAdapter sda = new SqlDataAdapter(query, con); DataTable dtl = new DataTable(); sda.Fill(dtl); if (dtl.Rows.Count == 1) { SqlCommand mySqlCommand = con.CreateCommand(); // put the name of the boss/worker in LOGIN file mySqlCommand.CommandText = "Select * from Login;"; SqlDataReader mySqlDataReader = mySqlCommand.ExecuteReader(); string str = textBox5.Text, str2 = ""; while (mySqlDataReader.Read()) // search the name from the txt file in ALL DB , if find - copy the line { if (mySqlDataReader[1].ToString() == str.Trim()) { str2 += mySqlDataReader[5] + "\n" + mySqlDataReader[3]; // Name + Rank --> Login.text rankWorker = mySqlDataReader[3].ToString(); } } FileStream prd = new FileStream("Login.txt", FileMode.Create); StreamWriter a = new StreamWriter(prd); a.WriteLine(str2.ToString()); a.Close(); prd.Close(); con.Close(); try { string month = DateTime.Today.ToString("MMMM"); FileStream mnth = new FileStream(@"Log_Workers\" + month.ToString() + ".txt", FileMode.Append); StreamWriter ff = new StreamWriter(mnth); SqlCommand mySqlCommand1 = con.CreateCommand(); mySqlCommand1.CommandText = "Select * from Login;"; con.Open(); SqlDataReader mySqlDataReader1 = mySqlCommand1.ExecuteReader(); DateTime value = DateTime.Now; string data = "Login:\n" + value.ToString() + "\n\n"; string str1 = crypto; while (mySqlDataReader1.Read()) { if (mySqlDataReader1[2].ToString() == str1.Trim()) { data += (mySqlDataReader1[5] + "\n" + mySqlDataReader1[4] + "\n"); idForSal = mySqlDataReader1[0].ToString(); } } //data += "- - - - - - - - "; ff.WriteLine(data.ToString()); ff.Close(); mnth.Close(); con.Close(); } catch (Exception err) { MessageBox.Show(err.Message); } FileStream f = new FileStream("Login.txt", FileMode.Open); StreamReader s = new StreamReader(f); string status1 = s.ReadLine(); status1 = s.ReadLine(); f.Close(); s.Close(); FileStream f_sal = new FileStream("Salary.txt", FileMode.Create); // SALARY FILE, RANK + SECONDS NOW StreamWriter s_sal = new StreamWriter(f_sal); string hour = DateTime.Now.ToString("HH"); DateTime m = DateTime.Now; double total_Sal = 0; double sal = 0; total_Sal += (double.Parse(hour.ToString()) * 3600); total_Sal += (double.Parse(m.Minute.ToString()) * 60); s_sal.WriteLine(rankWorker); s_sal.WriteLine(idForSal); // worker_id s_sal.WriteLine(total_Sal.ToString()); // total time in seconds s_sal.Close(); f_sal.Close(); if (int.Parse(status1.ToString().Trim()) == 1) // check BOSS RANK (1) { // button3.Visible = true; //button4.Visible = true; // button6.Visible = true; // button7.Visible = true; button8.Visible = true; textBox5.Visible = false; textBox2.Visible = false; textBox6.Visible = false; try { if (new FileInfo("Message.txt").Length > 0) // if message file is empty { button5.Visible = true; } string NAME = ""; FileStream name = new FileStream("Login.txt", FileMode.Open); StreamReader w = new StreamReader(name); NAME += w.ReadLine().ToString().Trim(); MessageBox.Show("Hello Mr. " + NAME.ToString() + "\n\n" + "You got a Message"); } catch { } } else { this.Hide(); Phone ann = new Phone(); ann.Show(); } } else { MessageBox.Show("Incorrect Username / Password / Email"); } textBox5.Clear(); textBox2.Clear(); textBox6.Clear(); //this.ActiveControl = textBox5; //textBox5.Focus(); con.Close(); }
private void button2_Click(object sender, EventArgs e) // INSERT { int c = 0; bool flag = true; string shtudel = textBox5.Text; Sha cryp = new Sha(textBox3.Text); string cipher = cryp.GetPassword().ToString(); // cyper get SHA Password if (checkedListBox1.CheckedItems.Count != 0) // for CheckedlistBox { for (int x = 0; x < checkedListBox1.CheckedItems.Count; x++) { choose += checkedListBox1.CheckedItems[x].ToString(); c++; } } if (textBox1.Text == "" || textBox3.Text == "" || textBox6.Text == "") { flag = false; MessageBox.Show("Empty fields"); } else if (!shtudel.Contains("@")) { MessageBox.Show("Email should contains '@'"); flag = false; } else if (c != 0 && flag) { try { con.Open(); SqlCommand cmd = new SqlCommand(@"INSERT INTO Login (login_id,username,password,rank,pass_mail,fname) VALUES ('" + textBox1.Text + "','" + textBox2.Text + "','" + cipher + "','" + choose.ToString() + "','" + textBox5.Text + "','" + textBox6.Text + "') ", con); cmd.ExecuteNonQuery(); MessageBox.Show("Successfully Saved !"); clear(); } catch (Exception err) { MessageBox.Show(err.Message); } } else { MessageBox.Show("No Rank data checked"); } Display(); con.Close(); }