Example #1
0
        private void done_in_bt_Click(object sender, EventArgs e)
        {
            empService = new EmployeeService();
            try
            {
                if (empName_in_tb.Text == "" || designation_in_tb.Text == "" || contact_in_tb.Text == "" || salary_in_tb.Text == "")
                {
                    MessageBox.Show("Requirements incomplete!!");
                }
                else
                {
                    emp             = new Employee();
                    emp.EmpName     = empName_in_tb.Text;
                    emp.Designation = designation_in_tb.Text;
                    emp.Contact     = Convert.ToInt32(contact_in_tb.Text);
                    emp.Salary      = Convert.ToInt32(salary_in_tb.Text);
                    int result = empService.InsertEmp(emp);
                    if (result > 0)
                    {
                        Credential u = new Credential();
                        emp.EmpId = result;
                        u.UserId  = emp.EmpId;
                        Random r        = new Random();
                        string password = "******" + r.Next(9999999);
                        u.Password = password;
                        if (designation_in_tb.Text == "Manager")
                        {
                            u.Type = 1;
                        }
                        else
                        {
                            u.Type = 0;
                        }

                        credSer = new CredentialService();
                        int i = credSer.InsertUser(u);
                        if (i > 0)
                        {
                            MessageBox.Show("User created. UserId(" + u.UserId + ")  password(" + password + ")");
                            empName_in_tb.Text = ""; designation_in_tb.Text = ""; contact_in_tb.Text = ""; salary_in_tb.Text = "";
                            UpdateGridView();
                        }
                    }
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.StackTrace); }
        }