入力ソースの行ごとに、さまざまなエンティティ(ベンダー、ワーカーなど)に関する情報を抽出する必要があるアプリがあります。これが の定義だと思っていたのclass
ですが、今苦労しています。
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;
}
}
}
メインプログラムと同じ名前空間にあります。次に、そのクラスをインスタンス化し、ベンダーにフィードしてID
、2 つのプロパティを利用できるようにします(ブラック ボックスのようなものです...)。
だから、私は試しました:
vendor v= vendor(VendorID);
次に、試しました:
vendor v = new vendor(VendorID);
私はそれを静的クラスにして、上記の両方を試しました。私はこれについて間違って考えています、私は確信しています。
誰かが私を正しい方向に向けることができますか?
コード (初期段階...):
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;
}
}
}