Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9125649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:51:10+00:00 2026-06-17T06:51:10+00:00

I have an app that needs to extract some information about various entities (vendor,

  • 0

I have an app that needs to extract some information about various entities (vendor, worker, etc.) for each row of an input source. I thought this was the definition of a class, but I’m struggling now.

class Vendor
{
    public int ID { get; set; }
    public string Name { get; set; }

    public Vendor(int vendorID)
    {
        using (CPASEntities ctx = new CPASEntities())
        {

            tblVendor v = (from vndr in ctx.tblVendors
                           where vndr.ID == vendorID
                           select vndr).FirstOrDefault();
            if (v == null)
            {
                ID = 0;
                Name = null;
            }
            else
            {
                ID = v.ID;
                Name = v.Vendor_Name;
            }
        }
    }

It’s in the same namespace of the main program. Now I want to instantiate that class and feed it a vendor ID so it will make the two properties available to me (black box, sort of…)

So, I tried:

vendor v= vendor(VendorID);

Then, I tried:

vendor v = new vendor(VendorID);

I even made it a static class and tried both of the above. I’m thinking about this incorrectly, I’m sure.

Can someone point me in the right direction?


Code (early stages…):

using CPAS_EM;
using Excel = Microsoft.Office.Interop.Excel;
using SpreadsheetGear;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;

namespace ProcTimesheets
{    
    public static class Vendor

{
    public int ID { get; set; }
    public string Name { get; set; }

    public Vendor(int vendorID)
    {
        using (CPASEntities ctx = new CPASEntities())
        {

            tblVendor v = (from vndr in ctx.tblVendors
                           where vndr.ID == vendorID
                           select vndr).FirstOrDefault();
            if (v == null)
            {
                ID = 0;
                Name = null;
            }
            else
            {
                ID = v.ID;
                Name = v.Vendor_Name;
            }
        }
    }
}
public static class Worker
{....}
static class LaborRate
{....}
class Program
{
    static void Main(string[] args)
    {
        XmlNodeList timesheets = TSList();
        foreach (XmlNode doc in timesheets)
        {
            string link = @"http://moss.mava.xxx.com/" + doc.Attributes["ows_FileRef"].InnerText.Split('#')[1];             // Leaves out the "//" at the beginning
            Timesheet tsheet = new Timesheet(link);
            tsheet.TimesheetID = Convert.ToInt32(doc.Attributes["ows_ID"].InnerText);
            tsheet.WeekStartDate = Convert.ToDateTime(doc.Attributes["ows_WeekStart"].InnerText);
            tsheet.CurrentStatus = doc.Attributes["ows_TimesheetStatus"].InnerText;
            tsheet.ApproverName = doc.Attributes["ows_Approver"].InnerText;
            tsheet.VendorFullName = doc.Attributes["ows_Vendor"].InnerText.Split('#')[1];               // strips some crap at the beginnining
            tsheet.Creator = doc.Attributes["ows_Author"].InnerText.Split('(')[1].Split(')')[0];         // Strips out only the NT user name
            tsheet.CreateDate = doc.Attributes["ows_Created"].InnerText;                                 // Leaves it in string format...never used as a date
            tsheet.Modifier = doc.Attributes["ows_Editor"].InnerText.Split('(')[1].Split(')')[0];       // Strips out only the NT user name
            tsheet.ModDate = doc.Attributes["ows_Modified"].InnerText.Split('(')[1].Split(')')[0];      // Leaves it in string format...never used as a date
            tsheet.OverrideStatus = doc.Attributes["ows_OverrideStatus"].InnerText;
        }
    }
    static XmlNodeList TSList()
    {
        //  This function returns an XML list of all Documents in the library with a status that needs to be audited.
        //  It uses the URL and Library Name found in the project property settings             
       ....
    }
}
public class Timesheet
{
    private enum NotifyType
    {
        General,
        Approver,
        OverrideApprover,
        BadWO
    }

    private Excel.Worksheet xlSH;                               // Local variables
    private Excel.Range xlRange;                                //
    private Excel.Application xlApp;                            //  
    private Excel.Workbooks xlWBS;                              //
    private Excel.Workbook xlWB;                                //

    public int RowCount { get; set; }                           // Row count in the "Used Range" (including the header row)
    public int ColCount { get; set; }                           // Column count in the "UsedRange"
    public int TimesheetID { get; set; }                        // Set from the SP Document Property
    public int VendorID                                         // "Read-only" property derived from the VendorFullName Document Property
    {
        get
        {
            return Convert.ToInt32(VendorFullName.Split('(')[1].Split(')')[0]); // Retrieves the parenthesized Vendor ID
        }
    }

    public DateTime WeekStartDate { get; set; }                 // Set from the SP Document Property
    public DateTime WeekEndDate                                 // "Read-only" property 
    {
        get
        {
            return WeekStartDate.AddDays(6);                    //(always returns WeekStartDate+6)
        }
    }

    public string CurrentStatus { get; set; }                   // Set from the SP Property unchanged
    public string ApproverName { get; set; }                    // Set from the SP Property unchanged
    public string ApproverEmailAddress
    {
        get
        {
            return ApproverName + "@xxx.com";
        }
    }
    public string VendorFullName { get; set; }                  // Set from the SP Property unchanged
    public string link { get; set; }                            // Derived from the SP Property
    public string Creator { get; set; }                         // NT user name of the SP Document creator
    public string CreatorEmailAddress
    {
        get
        {
            return Creator + "@xxx.com";
        }

    }
    public string CreateDate { get; set; }                      // straight from ows_Created -- left as a string
    public string Modifier { get; set; }                        // NT user name of the SP Document ows_Modifier
    public string ModDate { get; set; }                         // straight from ows_Modified -- left as a string
    public string OverrideStatus { get; set; }
    public string VendorShortName
    {
        get
        {
            return VendorFullName.Split('(')[0].Trim();        // Strips off trailing (), and trims it up
        }
    }

    List<string> WorkbookErrors = new List<string>();        

    public bool IsValid
    {
        get                                   // This property is set by "validating" the worksheet
        {
            vendor v = new Vendor(VendorID);
            bool returnvalue = true;
             // Don't forget spreadsheetgear is zero based.....
            for (int row = 0; row < RowCount; row++)
            {

            }
            return returnvalue;
        }
    }                                // "Read-only" property
    private void NotifyWorkbookError(List<string> MsgLst)
    {  ....  }
    private void Notify(NotifyType nType, List<string> MsgLst)
    {....}
    private string GetHTML(int MessageID)
    {....}
    public Timesheet(string wbPath)
    {
        link = wbPath;
        bool validDocument = OpenWorkbook();
        // Vendor curVndr = new Vendor(VendorID);
        //  Test the headings to make sure the workbook is valid
        if (validDocument)
        {

        }
        else
        {

        }

        xlWB.Close();
        xlWBS.Close();
        xlApp.Quit();


        System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRange);
        System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSH);
        System.Runtime.InteropServices.Marshal.ReleaseComObject(xlWB);
        System.Runtime.InteropServices.Marshal.ReleaseComObject(xlWBS);
        System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp);
        GC.Collect();
        GC.WaitForPendingFinalizers();

    }
    bool OpenWorkbook()
    {
        xlApp = new Excel.Application();
        xlApp.Visible = false;
        xlWBS = xlApp.Workbooks;
        xlWB = xlWBS.Open(link);

        if ((xlWB.ReadOnly == true) || (ValidHeadings(xlRange) == false))
        {
            WorkbookErrors.Add("This workbook is read-only. Someone has it open for writing. No processing can be completed");
            return false;                                           // Read-only Workbooks or WBs with bad heading row are not auditable
        }
        xlSH = xlWB.Worksheets[Properties.Settings.Default.Timesheet_WorkSheetName];
        xlRange = xlSH.UsedRange;
        RowCount = xlRange.Rows.Count;
        ColCount = xlRange.Columns.Count;
        return true;
    }
    bool ValidHeadings(Excel.Range range, int headingrow = 1)
    {....}
    static bool ValidRow(Excel.Range row, int vendorID)
    {
        bool returnvalue = false;


        return returnvalue;
    }
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:51:11+00:00Added an answer on June 17, 2026 at 6:51 am

    I suspect that either your class is not really in the same namespace, or it is in another project, and your main project doesn’t have a reference to that project.

    If the Vendor class is really in the same namespace as your main entry point for your program, all you have to do there is just:

    Vendor v = new Vendor(VendorID);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySQL/Rails app that needs search. Here's some info about the data:
I have a class Session.cs in the App_Code directory that needs to extract some
I have an app that needs to read a PDF file from the file
We have an app that needs to access network resources. It's written in VB.Net.
I have an app that needs to be able use either an sqlite3 datebase
I have an app that needs backgrounds for both parts of the split view.
I have a Rails app that needs to expose values from a database as
I have a wpf app that needs to communicate(exchange data) with a custom designed
I have an app that has a bunch of Core Data that it needs
I have an app included into INSTALLED_APPS that needs to be monkey-patched. The problem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.