public Project()
 {
     this.intID         = 0;
     this.intNumber     = 0;
     this.intCategory   = 0;
     this.strName       = "";
     this.strTip        = "";
     this.spSubprojects = new Subproject();
 }
Exemple #2
0
        public static DataSet GetSubprojects(Connection cnConnection, Subproject spSearch)
        {
            // A table mapping names the DataTable.
            DataSet dsSubprojects = new DataSet();

            String strCommand = @"SELECT * FROM tabSubprojects";

            if ((spSearch.intCategory != 0) || (spSearch.intProjectNumber != 0) ||
                (spSearch.strName.Length != 0) || (spSearch.dtStart.Year != 1) || (spSearch.intDuration != 0) ||
                (spSearch.intProgress != 0) || (spSearch.strTip.Length != 0))
            {
                strCommand += @" WHERE ";
            }

            if (spSearch.intCategory != 0)
            {
                strCommand += @"intcCategory = '" + spSearch.intCategory + "' ";
            }

            if (spSearch.intProjectNumber != 0)
            {
                if (spSearch.intCategory != 0)
                {
                    strCommand += @"AND intProjectNumber = '" + spSearch.intProjectNumber.ToString() + "' ";
                }
                else
                {
                    strCommand += @"intProjectNumber = '" + spSearch.intProjectNumber.ToString() + "' ";
                }
            }

            if (spSearch.strName.Length != 0)
            {
                if (spSearch.intCategory != 0 || spSearch.intProjectNumber != 0)
                {
                    strCommand += @"AND nvcName  LIKE N'%" + spSearch.strName + "%' ";
                }
                else
                {
                    strCommand += @"nvcName  LIKE N'%" + spSearch.strName + "%' ";
                }
            }

            if (spSearch.dtStart.Year != 1)
            {
                if (spSearch.intCategory != 0 || spSearch.intProjectNumber != 0 || spSearch.strName.Length != 0)
                {
                    strCommand += @" AND datStart = '" + spSearch.dtStart.Year.ToString() + "-" + spSearch.dtStart.Month.ToString() + "-" + spSearch.dtStart.Day.ToString() + "' ";
                }
                else
                {
                    strCommand += @"datStart = '" + spSearch.dtStart.Year.ToString() + "-" + spSearch.dtStart.Month.ToString() + "-" + spSearch.dtStart.Day.ToString() + "' ";
                }
            }

            if (spSearch.intDuration != 0)
            {
                if (spSearch.intCategory != 0 || spSearch.intProjectNumber != 0 || spSearch.strName.Length != 0 || spSearch.dtStart.Year != 1)
                {
                    strCommand += @" AND intDuration = '" + spSearch.intDuration.ToString() + "' ";
                }
                else
                {
                    strCommand += @"intDuration = '" + spSearch.intDuration.ToString() + "' ";
                }
            }

            if (spSearch.intProgress != 0)
            {
                if (spSearch.intCategory != 0 || spSearch.intProjectNumber != 0 || spSearch.strName.Length != 0 ||
                    spSearch.dtStart.Year != 1)
                {
                    strCommand += @" AND intProgress = '" + spSearch.intProgress + "' ";
                }
                else
                {
                    strCommand += @"intProgress = '" + spSearch.intProgress + "' ";
                }
            }

            if (spSearch.strTip.Length != 0)
            {
                if (spSearch.intCategory != 0 || spSearch.intProjectNumber != 0 || spSearch.strName.Length != 0 ||
                    spSearch.dtStart.Year != 1 || spSearch.intProgress != 0)
                {
                    strCommand += @" AND nvcTip = '" + spSearch.strTip + "' ";
                }
                else
                {
                    strCommand += @"nvcTip = '" + spSearch.strTip + "' ";
                }
            }

            strCommand += " ORDER BY datStart";

            //Create a SqlDataAdapter for the Suppliers table.
            SqlDataAdapter daSubprojects = new SqlDataAdapter();

            SqlConnection cnSqlConnection = new SqlConnection(cnConnection.strConnectionStringPty);

            cnSqlConnection.Open();
            daSubprojects.SelectCommand = new SqlCommand(strCommand, cnSqlConnection);
            daSubprojects.Fill(dsSubprojects, "tabSubprojects");
            cnSqlConnection.Close();

            return(dsSubprojects);
        }