public static SubDepartment[] GetSubDepartments(Connection cnConnection, int intDepartmentsArg)
        {
            SubDepartment[] depSubDepartments;
            int             intRowsCount = 0;

            SqlConnection scConnection     = new SqlConnection(cnConnection.strConnectionStringPty);
            SqlCommand    cmSubDepartments = new SqlCommand("", scConnection);

            cmSubDepartments.Connection  = scConnection;
            cmSubDepartments.CommandText =
                string.Format("SELECT * FROM tabSubDepartments WHERE bitIsActual=1 AND intDepartment={0} ORDER BY nvcName", intDepartmentsArg);

            scConnection.Open();
            SqlDataReader drSubDepartments = cmSubDepartments.ExecuteReader();

            while (drSubDepartments.Read())
            {
                ++intRowsCount;
            }
            drSubDepartments.Close();

            depSubDepartments = new SubDepartment[intRowsCount];
            drSubDepartments  = cmSubDepartments.ExecuteReader();
            intRowsCount      = 0;
            while (drSubDepartments.Read())
            {
                depSubDepartments[intRowsCount] = new SubDepartment();
                depSubDepartments[intRowsCount].intDepartmnt = (int)drSubDepartments["intDepartment"];
                depSubDepartments[intRowsCount].strName      = drSubDepartments["nvcName"].ToString();
                depSubDepartments[intRowsCount].intNumber    = (int)drSubDepartments["intNumber"];
                ++intRowsCount;
            }

            return(depSubDepartments);
        }
        public static bool Insert(Connection cnConnection, SubDepartment sdInsertArg)
        {
            bool          bolResultLoc     = false;
            SqlConnection scConnection     = new SqlConnection(cnConnection.strConnectionStringPty);
            SqlCommand    cmSubDepartments = new SqlCommand();

            cmSubDepartments.Connection  = scConnection;
            cmSubDepartments.CommandText = String.Format("INSERT INTO tabDepartments (intDepartment,nvcName, intNumber) VALUES ({0},N'{1}',{2})",
                                                         sdInsertArg.intDepartmnt, sdInsertArg.strName, NextNumber(cnConnection));

            scConnection.Open();
            if (cmSubDepartments.ExecuteNonQuery() >= 1)
            {
                bolResultLoc = true;
            }
            scConnection.Close();

            return(bolResultLoc);
        }
        public static bool Update(Connection cnConnection, SubDepartment sdUpadateArg)
        {
            bool bolResultLoc = false;

            SqlConnection scConnection     = new SqlConnection(cnConnection.strConnectionStringPty);
            SqlCommand    cmSubDepartments = new SqlCommand();

            cmSubDepartments.Connection  = scConnection;
            cmSubDepartments.CommandText = String.Format("UPDATE tabSubDepartments SET intDepartment={0}, nvcName=N'{1}', intNumber={2}  WHERE intID={3}",
                                                         sdUpadateArg.intDepartmnt, sdUpadateArg.strName, sdUpadateArg.intNumber, sdUpadateArg.intID);

            scConnection.Open();
            if (cmSubDepartments.ExecuteNonQuery() >= 1)
            {
                bolResultLoc = true;
            }
            scConnection.Close();

            return(bolResultLoc);
        }
Ejemplo n.º 4
0
        public static string GetNameByDepartmentAndNumber(Connection cnConnection, SubDepartment sdSearchArg)
        {
            String strNameLoc = "";

            SqlConnection scConnection     = new SqlConnection(cnConnection.strConnectionStringPty);
            SqlCommand    cmSubDepartments = new SqlCommand();

            cmSubDepartments.Connection  = scConnection;
            cmSubDepartments.CommandText = String.Format("SELECT nvcName FROM tabShifts WHERE intDepartment={0}, intNumber={1}",
                                                         sdSearchArg.intDepartmnt, sdSearchArg.intNumber);

            scConnection.Open();
            SqlDataReader drSubDepartment = cmSubDepartments.ExecuteReader();

            if (drSubDepartment.Read())
            {
                strNameLoc = drSubDepartment["nvcName"].ToString();
            }

            drSubDepartment.Close();
            scConnection.Close();

            return(strNameLoc);
        }