QuickBooks QBFC (8.0 SDK)를 사용하여 고객, 작업 및 직원 목록을 얻는 방법
-
19-09-2019 - |
문제
C# 응용 프로그램을 작성하는 고통스러운 작업을 받았습니다. 저는 QB 프로그래밍에 익숙하지 않기 때문에 고객 목록을 얻은 다음 각 고객의 작업 및 직원과 같은 기본 작업을 수행하려고합니다. 나는 SDK 문서를 읽었지만, 내가 찾은 예제가 현재 나에게 약간 발전했기 때문에 여전히 세부 사항에 대해 약간 퍼지가 있습니다 : -p.
일을 간단하게 유지하기 위해, 저는 스타터를위한 고객 목록을 제공하는 코드 스 니펫을 요청하고 싶습니다. 내가 가진 코드는 다음과 같습니다.
QBSessionManager SessionManager = new QBSessionManager();
IMsgSetRequest customerSet = SessionManager.CreateMsgSetRequest("US", 8, 0);
//
// Code to get list of customers here.
//
SessionManager.OpenConnection2("", "New App", ENConnectionType.ctLocalQBD);
SessionManager.BeginSession(string.Empty, ENOpenMode.omDontCare);
IMsgSetResponse Resp = SessionManager.DoRequests(customerSet);
MessageBox.Show(Resp.ToXMLString());
SessionManager.EndSession();
SessionManager.CloseConnection();
누구든지 "고객 목록을 얻기 위해 코드"를 작성할 수 있습니까? 미리 감사드립니다!
승리자
해결책 2
좋아, 내가 누락 된 조각을 찾은 것 같다 :
ICustomerQuery customers = customerSet.AppendCustomerQueryRq();
이렇게하면 각 고객과 관련된 모든 데이터가 생성되며, 이는 한 걸음 앞으로 나아갑니다. 고객을위한 XML을 구문 분석하는 것은 매우 간단해야하지만 각 작업에 대한 하위 노드가 없기 때문에 각 고객에 대한 개별 작업/작업을 구문 분석하는 것은 힘들 것입니다. 기본적으로 모든 기본 고객 정보 (주소, 청구서 청구서는 XML 덩어리를 반복합니다. 주소, 배송 주소 등),이 하나의 속성은 "FullName"이라는 속성을 고객 이름에 추가 한 다음 작업 제목 (자체 자체가 하위 타스 제목 등이있는 다른 콜론 등)이 뒤 따릅니다. 더 나은 XML 응답을 얻기 위해 요청 쿼리를 사용하여 할 수있는 일이 있는지 궁금합니다 (예 : 반환하려는 속성을 지정하고 주어진 고객에 대한 각 작업에 대한 하위 노드 생성을 시행 할 수 있습니다) ... 의견에 감사드립니다.
다른 팁
customers.IncludeRetElementList.Add("IsActive");
customers.IncludeRetElementList.Add("ListID");
customers.IncludeRetElementList.Add("EditSequence");
customers.IncludeRetElementList.Add("Name");
customers.IncludeRetElementList.Add("ParentRef");
위 목록에 지정된 필드 만 QuickBooks에서 반환됩니다. 올바른 경우에 올바른 문자열을 사용하는 것이 매우 중요합니다. 잘못된 경우 오류 메시지가 발생하지 않습니다. 하위 필드를 지정할 수 없습니다 (예 : 주소 블록 내의 도시, 전체 주소 블록을 가져와야합니다). 사용자 정의 필드의 경우 jolderID를 지정해야합니다 (응용 프로그램에 개인이 아닌 사용자 지정 필드에는 0 사용).
customers.IncludeRetElementList.Add("DataExtRet"); //will return non-private and/or private data extension fields depending on the OwnerIDList, below
customers.OwnerIDList.Add("0"); // required for non-private data extn fields
customers.OwnerIDList.Add("Your Appln GUID"); // Use this to get private data extns for the Appln identified by the GUID
Victors, Chili 및 Hassan의 대답에 추가. 나 자신이 QBFC 사례로 어려움을 겪고 있었기 때문에이 질문을 우연히 발견하게되어 기쁩니다. 다음은 누군가가 길을 따라가는 데 도움이 될 수있는 전체 코드 세트입니다. 그동안 누군가가 유용한 문서의 방향으로 나를 지적 할 수 있다면 ... 그것은 좋을 것입니다.
직원 데이터를 XML 문자열로 가져옵니다
public static string EmployeeListXML()
{
QBSessionManager SessionManager = new QBSessionManager();
IMsgSetRequest msgSetReq = SessionManager.CreateMsgSetRequest("US", 8, 0);
IEmployeeQuery employee = msgSetReq.AppendEmployeeQueryRq();
employee.IncludeRetElementList.Add("IsActive");
employee.IncludeRetElementList.Add("ListID");
employee.IncludeRetElementList.Add("EditSequence");
employee.IncludeRetElementList.Add("FirstName");
employee.IncludeRetElementList.Add("LastName");
employee.IncludeRetElementList.Add("SSN");
//employee.IncludeRetElementList.Add("ParentRef");
//employee.IncludeRetElementList.Add("DataExtRet"); //will return non-private and/or private data extension fields depending on the OwnerIDList, below
employee.OwnerIDList.Add("0"); // required for non-private data extn fields
//customers.OwnerIDList.Add("Your Appln GUID"); // Use this to get private data extns for the Appln identified by the GUID
SessionManager.OpenConnection2("", Application.ProductName, ENConnectionType.ctLocalQBD);
//SessionManager.BeginSession(string.Empty, ENOpenMode.omDontCare);
SessionManager.BeginSession(frmMain.QBFileName, ENOpenMode.omDontCare); // I have the filename on frmMain
IMsgSetResponse Resp = SessionManager.DoRequests(msgSetReq);
SessionManager.EndSession();
SessionManager.CloseConnection();
//MessageBox.Show(Resp.ToXMLString());
return Resp.ToXMLString();
}
XML 문자열을 emplpoyee 객체 목록에 넣습니다.
public static List<Employee> EmployeeXMLtoList()
{
string sXML = EmployeeListXML();
List<Employee> lstEmp = new List<Employee>();
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(sXML);
XmlNodeList parentNode = xmlDoc.GetElementsByTagName("EmployeeRet");
foreach (XmlNode childNode in parentNode)
{
Employee oEmp = new Employee();
oEmp.ListID = childNode.SelectSingleNode("ListID").InnerText;
oEmp.EditSequence = childNode.SelectSingleNode("EditSequence").InnerText;
oEmp.Active = childNode.SelectSingleNode("IsActive").InnerText;
oEmp.FirstName = childNode.SelectSingleNode("FirstName").InnerText;
oEmp.LastName = childNode.SelectSingleNode("LastName").InnerText;
oEmp.SSN = childNode.SelectSingleNode("SSN").InnerText;
lstEmp.Add(oEmp);
}
return lstEmp;
}
LINQ를 사용하여 직원 객체를 반환하는 함수
public static Employee GetEmployeeObject(string sSSN)
{
Employee oReturn = null;
List<Employee> lstEmployee = EmployeeXMLtoList();
IEnumerable<Employee> lstEmps = from oEmp in lstEmployee
where oEmp.SSN == sSSN
select oEmp;
foreach (var oEmp in lstEmps)
{
oReturn = oEmp;
}
return oReturn;
}
코드의 예
Employee oEmployee = QB.GetEmployeeObject("112-35-8560");
직원 수업
public class Employee
{
private string sEmployeeID;
private string sSSN;
private string sLastName;
private string sFirstName;
private string sAddress1;
private string sAddress2;
private string sCity;
private string sState;
private string sZipCode;
private string sGender;
private string sEthnicity;
private DateTime dDOB;
private string sMaritalStatus;
private int iDependants;
private string sUScitizen;
private decimal iPayRate;
private string sPhone;
private DateTime dHireDate;
private string sEmail;
public Employee() { }
public string EmployeeID
{
get { return sEmployeeID; }
set { sEmployeeID = value; }
}
public string ListID
{
get; set;
}
public string EditSequence
{
get; set;
}
public string Active
{
get; set;
}
public string SSN
{
get { return sSSN; }
set { sSSN = value; }
}
public string LastName
{
get { return sLastName; }
set { sLastName = value; }
}
public string FirstName
{
get { return sFirstName; }
set { sFirstName = value; }
}
public string FullName
{
get { return FirstName + " " + LastName; }
set { }
}
public string Address1
{
get { return sAddress1; }
set { sAddress1 = value; }
}
public string Address2
{
get { return sAddress2; }
set { sAddress2 = value; }
}
public string State
{
get { return sState; }
set { sState = value; }
}
public string City
{
get { return sCity; }
set { sCity = value; }
}
public string ZipCode
{
get { return sZipCode; }
set { sZipCode = value; }
}
public string Gender
{
get { return sGender; }
set { sGender = value; }
}
public string Ethnicity
{
get { return sEthnicity; }
set { sEthnicity = value; }
}
public DateTime DOB
{
get { return dDOB; }
set { dDOB = value; }
}
public string MaritalStatus
{
get { return sMaritalStatus; }
set { sMaritalStatus = value; }
}
public int Dependants
{
get { return iDependants; }
set { iDependants = value; }
}
public string UScitizen
{
get { return sUScitizen; }
set { sUScitizen = value; }
}
public decimal PayRate
{
get { return iPayRate; }
set { iPayRate = value; }
}
public DateTime HireDate
{
get { return dHireDate; }
set { dHireDate = value; }
}
public string Phone
{
get { return sPhone; }
set { sPhone = value; }
}
public string Email
{
get { return sEmail; }
set { sEmail = value; }
}
}