Beispiel #1
0
        private void AddUpdateUser(int intEmployeeID)
        {
            clsGeneral General = new clsGeneral();
            bool blnUserExists = false;

            //Check to see if User Account Exists
            strSQL = "SELECT ID ";
            strSQL += "FROM tblUsers ";
            strSQL += "WHERE EmployeeID = " + intEmployeeID;

            DataSet ds = General.FillDataset(strSQL);
            DataTable dt = ds.Tables[0];

            if (dt.Rows.Count > 0)
            {
                blnUserExists = true;
            }
            else
            {
                blnUserExists = false;
            }

            ds.Dispose();
            ds = null;
            dt.Dispose();
            dt = null;

            if (blnUserExists == true)
            {
                strSQL = "UPDATE tblUsers ";
                strSQL += "SET ";
                strSQL += "UserName = '******', ";
                strSQL += "Password = '******' ";
                strSQL += "WHERE EmployeeID = " + intEmployeeID;
                General.UpdateRecord(strSQL);
            }
            else
            {
                strSQL = "INSERT INTO tblUsers ";
                strSQL += "(UserName, Password, UserLevel, EmployeeID) ";
                strSQL += "VALUES ( ";
                strSQL += "'" + txtUserName.Text + "', ";
                strSQL += "'" + txtPassword.Text + "', ";
                strSQL += "'User', ";
                strSQL += intEmployeeID + ")";
                General.AddRecord(strSQL);
            }
        }
Beispiel #2
0
 private void AddEmployee()
 {
     clsGeneral General = new clsGeneral();
     SqlConnection conn = default(SqlConnection);
     SqlCommand cmd = default(SqlCommand);
     string strConn = General.strConn;
     int intEmployeeID = 0;
     string strFirst = this.txtFirstName.Text;
     string strLast = this.txtLastName.Text;
     string strName = null;
     int intActive = 0;
     if (this.rbtnActiveEmployeeYes.Checked)
     {
         intActive = 1;
     }
     strName = strLast + ", " + strFirst;
     //
     strSQL = "INSERT INTO tblEmployees ";
     strSQL += "(EmployeeCode, EmployeeFirst, EmployeeLast, EmployeeName, ";
     strSQL += "EmployeeTypeID, Address, City, State, Zip, ";
     strSQL += "HomePhone, CellPhone, Title, EmploymentStartDate, EmploymentEndDate, YearsOfExperience, ";
     strSQL += "Education, Licenses, ProfessionalMemberships, ProfessionalCommittees, HoursPerWeek, ";
     strSQL += "Comments, Active) ";
     strSQL += "VALUES (";
     strSQL += "'" + this.txtEmployeeCode.Text + "', ";
     strSQL += "'" + strFirst + "', ";
     strSQL += "'" + strLast + "', ";
     strSQL += "'" + strName + "', ";
     strSQL += this.cboEmployeeType.SelectedValue + ", ";
     strSQL += "'" + this.txtAddress.Text + "', ";
     strSQL += "'" + this.txtCity.Text + "', ";
     strSQL += "'" + this.txtState.Text + "', ";
     strSQL += "'" + this.txtZip.Text + "', ";
     strSQL += "'" + this.txtHomePhone.Text + "', ";
     strSQL += "'" + this.txtCellPhone.Text + "', ";
     strSQL += "'" + this.txtTitle.Text + "', ";
     //
     if (string.IsNullOrEmpty(this.txtEmployeeStartDate.Text))
     {
         strSQL += "NULL, ";
     }
     else
     {
         strSQL += "'" + this.txtEmployeeStartDate.Text + "', ";
     }
     if (string.IsNullOrEmpty(this.txtEmployeeEndDate.Text))
     {
         strSQL += "NULL, ";
     }
     else
     {
         strSQL += "'" + this.txtEmployeeEndDate.Text + "', ";
     }
     //
     strSQL += "'" + this.txtYearsOfExperience.Text + "', ";
     strSQL += "'" + this.txtEducation.Text + "', ";
     strSQL += "'" + this.txtLicenses.Text + "', ";
     strSQL += "'" + this.txtProfMemberships.Text + "', ";
     strSQL += "'" + this.txtProfCommittees.Text + "', ";
     strSQL += this.txtHoursPerWeek.Text + ", ";
     strSQL += "'" + this.txtComments.Text + "', ";
     strSQL += intActive + ") ";
     strSQL += "SELECT @EmployeeID = @@identity";
     conn = new SqlConnection(strConn);
     cmd = new SqlCommand(strSQL, conn);
     SqlParameter prmEmpID = new SqlParameter("@EmployeeID", SqlDbType.Int);
     prmEmpID.Direction = ParameterDirection.Output;
     cmd.Parameters.Add(prmEmpID);
     //
     conn.Open();
     cmd.ExecuteNonQuery();
     //
     intEmployeeID = prmEmpID.Value.GetValueOrDefault<int>();
     //
     conn.Close();
     conn = null;
     cmd = null;
     //
     if (this.rbtnUserYes.Checked == true)
     {
         // Add User
         strSQL = "INSERT INTO tblUsers ";
         strSQL += "(UserName, Password, UserLevel, EmployeeID) ";
         strSQL += "VALUES (";
         strSQL += "'" + this.txtUserName.Text + "', ";
         strSQL += "'" + this.txtPassword.Text + "', ";
         strSQL += "'User', ";
         strSQL += intEmployeeID + ")";
         General.AddRecord(strSQL);
     }
     //
 }