Пример #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (this.BackColor == Color.White)
            {
                LightMood();
            }

            else if (this.BackColor == Color.Black)
            {
                DarkMood();
            }

            Name       = textBox1.Text;
            Address    = textBox2.Text; Email = textBox3.Text;
            Phone      = textBox4.Text; NID = textBox5.Text;
            Montly_Sal = numericUpDown1.Text;
            Position   = comboBox1.Text; Workking_Status = groupBox5.Text;
            Birthday   = dateTimePicker1.Text;
            bool isValid = IsEMailAddrValid(Email);

            if (radioButton1.Checked)
            {
                Married_Status = "Married";
            }
            else if (radioButton2.Checked)
            {
                Married_Status = "Unmarried";
            }
            else
            {
                Married_Status = "";
            }

            if (radioButton4.Checked)
            {
                Gander = "Male";
            }
            else if (radioButton3.Checked)
            {
                Gander = "Female";
            }
            else
            {
                Gander = "";
            }

            if (radioButton6.Checked)
            {
                Working_Time = "Fulltime"; Shift = "Full";
            }
            else if (radioButton5.Checked)
            {
                Working_Time = "Halftime";
            }
            else
            {
                Working_Time = "";
            }

            if (radioButton8.Checked)
            {
                Shift = "Day";
            }
            else if (radioButton7.Checked)
            {
                Shift = "Night";
            }
            else
            {
                Shift = "";
            }

            if (radioButton10.Checked)
            {
                Workking_Status = "Not Available";
            }
            else if (radioButton9.Checked)
            {
                Workking_Status = "Available";
            }
            else
            {
                Workking_Status = "";
            }



            //label1.ForeColor = Color.Black;
            //label2.ForeColor = Color.Black;
            //label3.ForeColor = Color.Black;
            //label4.ForeColor = Color.Black;
            //label5.ForeColor = Color.Black;
            //label6.ForeColor = Color.Black;
            //label7.ForeColor = Color.Black;
            //label8.ForeColor = Color.Black;
            //label10.ForeColor = Color.Black;


            void emptyTextBox()
            {
                MessageBox.Show("All TaxBox is not Fillup or Any thing Wrong!", "Warnning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            try
            {
                FileStream   stream = new FileStream(imgLocation, FileMode.Open, FileAccess.Read);
                BinaryReader brs    = new BinaryReader(stream);
                Photo = brs.ReadBytes((int)stream.Length);
            }
            catch
            {
                Photo = null;
            }


            if (Name.Equals(""))
            {
                label1.ForeColor = Color.Red; emptyTextBox();
            }
            else if (Address.Equals(""))
            {
                label2.ForeColor = Color.Red; emptyTextBox();
            }


            else if (Email.Equals("") || isValid == false)
            {
                label3.ForeColor = Color.Red; emptyTextBox(); label17.Show();
            }

            else if (Phone.Equals(""))
            {
                label4.ForeColor = Color.Red; emptyTextBox();
            }
            else if (NID.Equals("") || NID.Length != 12)
            {
                label5.ForeColor = Color.Red; emptyTextBox();  if (NID.Length != 12)
                {
                    label15.Show();
                }
                else
                {
                    label15.Hide();
                }
            }

            else if (Married_Status.Equals(""))
            {
                label6.ForeColor = Color.Red; emptyTextBox();
            }
            else if (Gander.Equals(""))
            {
                label7.ForeColor = Color.Red; emptyTextBox();
            }
            else if (Working_Time.Equals(""))
            {
                label8.ForeColor = Color.Red; emptyTextBox();
            }
            else if (Montly_Sal.Equals(""))
            {
                label10.ForeColor = Color.Red; emptyTextBox();
            }

            //else if (Email.Equals("")) { label3.ForeColor = Color.Red; emptyTextBox(); }
            //else if (Email.Equals("")) { label3.ForeColor = Color.Red; emptyTextBox(); }
            //else if (Email.Equals("")) { label3.ForeColor = Color.Red; emptyTextBox(); }
            //else if (Email.Equals("")) { label3.ForeColor = Color.Red; emptyTextBox(); }


            else if (Photo == null)
            {
                emptyTextBox();
            }


            else
            {
                DialogResult dialog = MessageBox.Show("Do you want to Add This New User?", "Warnning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

                if (dialog == DialogResult.Yes)
                {
                    //  Random rnd = new Random();
                    //  Password = rnd.Next(1000, 5000);  ////////////////////////////////////////////////////////////////////////

                    Password = RandomPass();


                    //Photo = null;



                    SqlCommand insert = new SqlCommand("insert into AllUser(Password,Name,NID,Address,Email,Phone,Married_Status,Gander,Working_Time,Montly_Sal,Position,Workking_Status,Shift,Photo,Birthday)" +
                                                       "" +
                                                       " values(@Password,@Name,@NID,@Address,@Email,@Phone,@Married_Status,@Gander,@Working_Time,@Montly_Sal,@Position,@Workking_Status,@Shift,@Photo,@Birthday)");

                    insert.Parameters.AddWithValue("@Password", @Password);
                    insert.Parameters.AddWithValue("@Name", Name);
                    insert.Parameters.AddWithValue("@NID", NID);

                    insert.Parameters.AddWithValue("@Address", Address);
                    insert.Parameters.AddWithValue("@Email", Email);
                    insert.Parameters.AddWithValue("@Phone", Phone);
                    insert.Parameters.AddWithValue("@Married_Status", Married_Status);
                    insert.Parameters.AddWithValue("@Gander", Gander);

                    insert.Parameters.AddWithValue("@Working_Time", Working_Time);
                    insert.Parameters.AddWithValue("@Montly_Sal", Montly_Sal);
                    insert.Parameters.AddWithValue("@Position", Position);
                    insert.Parameters.AddWithValue("@Workking_Status", Workking_Status);
                    insert.Parameters.AddWithValue("@Shift", Shift);
                    insert.Parameters.AddWithValue("@Photo", @Photo);
                    insert.Parameters.AddWithValue("@Birthday", Birthday);


                    int row = db.executeQuery(insert);

                    if (row == 1)
                    {
                        PrintUserInfo_Form PUF = new PrintUserInfo_Form();
                        PUF.Show();
                    }
                    string Year = DateTime.Now.ToString("yyyy");

                    DataTable TampTable = new DataTable();
                    string    qurey     = "Select * from AllUser Where NID ='" + NID + "'AND Name ='" + Name + "'";

                    db.readDatathroughAdapter(qurey, TampTable);
                    string ID;

                    ID = TampTable.Rows[0]["ID"].ToString();



                    SqlCommand insert2 = new SqlCommand("insert into SalaryList(ID,Name,Year) values(@ID,@Name,@Year)");   //insert in salary

                    insert2.Parameters.AddWithValue("@ID", ID);
                    insert2.Parameters.AddWithValue("@Name", Name);
                    insert2.Parameters.AddWithValue("@Year", Year);
                    row = db.executeQuery(insert2);

                    if (row == 1)
                    {
                        MessageBox.Show("Done");
                    }
                }
            }
        }
Пример #2
0
        private void button2_Click(object sender, EventArgs e)             //Update Button
        {
            if (this.BackColor == Color.White)
            {
                LightMood();

                //DarkMood();
            }

            else if (this.BackColor == Color.Black)
            {
                DarkMood();
            }

            Name       = textBox1.Text;
            Address    = textBox2.Text; Email = textBox3.Text;
            Phone      = textBox4.Text; NID = textBox5.Text;
            Montly_Sal = numericUpDown1.Text;
            Position   = comboBox1.Text; Workking_Status = groupBox5.Text;
            Password   = textBox7.Text;


            if (radioButton1.Checked)
            {
                Married_Status = "Married";
            }
            else if (radioButton2.Checked)
            {
                Married_Status = "Unmarried";
            }
            else
            {
                Married_Status = "";
            }

            if (radioButton4.Checked)
            {
                Gander = "Male";
            }
            else if (radioButton3.Checked)
            {
                Gander = "Female";
            }
            else
            {
                Gander = "";
            }

            if (radioButton6.Checked)
            {
                Working_Time = "FullTime"; Shift = "Full";
            }
            else if (radioButton5.Checked)
            {
                Working_Time = "HalfTime";
            }
            else
            {
                Working_Time = "";
            }

            if (radioButton8.Checked)
            {
                Shift = "Day";
            }
            else if (radioButton7.Checked)
            {
                Shift = "Night";
            }
            else
            {
                Shift = "";
            }

            if (radioButton10.Checked)
            {
                Workking_Status = "Not";
            }
            else if (radioButton9.Checked)
            {
                Workking_Status = "Avable";
            }
            else
            {
                Workking_Status = "";
            }



            void emptyTextBox()
            {
                MessageBox.Show("All TaxBox is not Fillup or Any thing Wrong!", "Warnning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            if (Name.Equals(""))
            {
                label1.ForeColor = Color.Red; emptyTextBox();
            }
            else if (Address.Equals(""))
            {
                label2.ForeColor = Color.Red; emptyTextBox();
            }
            else if (Email.Equals(""))
            {
                label3.ForeColor = Color.Red; emptyTextBox();
            }
            else if (Phone.Equals(""))
            {
                label4.ForeColor = Color.Red; emptyTextBox();
            }
            else if (NID.Equals("") || NID.Length != 12)
            {
                label5.ForeColor = Color.Red; emptyTextBox(); if (NID.Length != 12)
                {
                    label15.Show();
                }
                else
                {
                    label15.Hide();
                }
            }

            else if (Married_Status.Equals(""))
            {
                label6.ForeColor = Color.Red; emptyTextBox();
            }
            else if (Gander.Equals(""))
            {
                label7.ForeColor = Color.Red; emptyTextBox();
            }
            else if (Working_Time.Equals(""))
            {
                label8.ForeColor = Color.Red; emptyTextBox();
            }
            else if (Montly_Sal.Equals(""))
            {
                label10.ForeColor = Color.Red; emptyTextBox();
            }

            //else if (Email.Equals("")) { label3.ForeColor = Color.Red; emptyTextBox(); }
            //else if (Email.Equals("")) { label3.ForeColor = Color.Red; emptyTextBox(); }
            //else if (Email.Equals("")) { label3.ForeColor = Color.Red; emptyTextBox(); }
            //else if (Email.Equals("")) { label3.ForeColor = Color.Red; emptyTextBox(); }

            else
            {
                DialogResult dialog = MessageBox.Show("Do you want to Add This New User?", "Warnning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

                if (dialog == DialogResult.Yes)
                {
                    try
                    {
                        FileStream   stream = new FileStream(imgLocation, FileMode.Open, FileAccess.Read);
                        BinaryReader brs    = new BinaryReader(stream);
                        Photo = brs.ReadBytes((int)stream.Length);
                    }
                    catch { }



                    string query = "Update AllUser SET Password ='******',Name ='" + Name + "',NID ='" + NID + "',Address ='" + Address + "',Email ='" + Email + "', Phone ='" + Phone + "',Married_Status ='" + Married_Status + "',Gander ='" + Gander + "',Working_Time ='" + Working_Time + "',Montly_Sal ='" + Montly_Sal + "',Position ='" + Position + "',Workking_Status ='" + Workking_Status + "',Shift ='" + Shift + "', Photo = @Photo where ID = ' " + textBox6.Text + " ' ";

                    SqlCommand updateData = new SqlCommand(query);



                    updateData.Parameters.AddWithValue("@Password", Password);
                    updateData.Parameters.AddWithValue("@Name", Name);
                    updateData.Parameters.AddWithValue("@NID", NID);

                    updateData.Parameters.AddWithValue("@Address", Address);
                    updateData.Parameters.AddWithValue("@Email", Email);
                    updateData.Parameters.AddWithValue("@Phone", Phone);
                    updateData.Parameters.AddWithValue("@Married_Status", Married_Status);
                    updateData.Parameters.AddWithValue("@Gander", Gander);

                    updateData.Parameters.AddWithValue("@Working_Time", Working_Time);
                    updateData.Parameters.AddWithValue("@Montly_Sal", Montly_Sal);
                    updateData.Parameters.AddWithValue("@Position", Position);
                    updateData.Parameters.AddWithValue("@Workking_Status", Workking_Status);
                    updateData.Parameters.AddWithValue("@Shift", Shift);
                    updateData.Parameters.AddWithValue("@Photo", Photo);


                    int row = db.executeQuery(updateData);

                    if (row == 1)
                    {
                        MessageBox.Show("Information Updated", "Warnning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
        }