- 积分
- 26
- 在线时间
- 740 小时
- 主题
- 10
- 注册时间
- 2013-6-11
- 帖子
- 151
- 最后登录
- 2022-1-10
- 帖子
- 151
- 软币
- 3202
- 在线时间
- 740 小时
- 注册时间
- 2013-6-11
|
本帖最后由 hollow1976 于 2013-7-5 11:08 编辑
最近公司营业税改增值税,软件有个小改造,不复杂正好在学习XPO,拿来试试手.
XPO的资料不多好多东西不懂,自己琢磨的,欢迎大家批评指正
一,已有数据库,从现有库生产实体类
其他表就不说了,生成三个实体类HTTAX_HEADER,HTTAX_LINE,HTTAX_FEEDBACK,HEADER为主表通过UNINO和其他表关联
HEADERB类代码(自动生成)
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using DevExpress.Xpo;
using DevExpress.Data.Filtering;
namespace PtVat.ptdata
{
public partial class HTTAX_HEADER : XPLiteObject
{
int funino;
[Key(true)]
public int unino
{
get { return funino; }
set { SetPropertyValue<int>("unino", ref funino, value); }
}
string ferp_unino;
[Size(50)]
public string erp_unino
{
get { return ferp_unino; }
set { SetPropertyValue<string>("erp_unino", ref ferp_unino, value); }
}
string fvendeename;
public string vendeename
{
get { return fvendeename; }
set { SetPropertyValue<string>("vendeename", ref fvendeename, value); }
}
string fvendeetax;
[Size(20)]
public string vendeetax
{
get { return fvendeetax; }
set { SetPropertyValue<string>("vendeetax", ref fvendeetax, value); }
}
string fvendeeadress;
public string vendeeadress
{
get { return fvendeeadress; }
set { SetPropertyValue<string>("vendeeadress", ref fvendeeadress, value); }
}
string fvendeebnkno;
public string vendeebnkno
{
get { return fvendeebnkno; }
set { SetPropertyValue<string>("vendeebnkno", ref fvendeebnkno, value); }
}
DateTime fbilldate;
public DateTime billdate
{
get { return fbilldate; }
set { SetPropertyValue<DateTime>("billdate", ref fbilldate, value); }
}
int ftaxrate;
public int taxrate
{
get { return ftaxrate; }
set { SetPropertyValue<int>("taxrate", ref ftaxrate, value); }
}
string fremark;
[Size(160)]
public string remark
{
get { return fremark; }
set { SetPropertyValue<string>("remark", ref fremark, value); }
}
int finvoicekind;
public int invoicekind
{
get { return finvoicekind; }
set { SetPropertyValue<int>("invoicekind", ref finvoicekind, value); }
}
string fpayee;
[Size(10)]
public string payee
{
get { return fpayee; }
set { SetPropertyValue<string>("payee", ref fpayee, value); }
}
string fcheckman;
[Size(10)]
public string checkman
{
get { return fcheckman; }
set { SetPropertyValue<string>("checkman", ref fcheckman, value); }
}
string fproposer;
[Size(10)]
public string proposer
{
get { return fproposer; }
set { SetPropertyValue<string>("proposer", ref fproposer, value); }
}
string fsellertax;
[Size(20)]
public string sellertax
{
get { return fsellertax; }
set { SetPropertyValue<string>("sellertax", ref fsellertax, value); }
}
int fmachineno;
public int machineno
{
get { return fmachineno; }
set { SetPropertyValue<int>("machineno", ref fmachineno, value); }
}
string fsellerbnkno;
public string sellerbnkno
{
get { return fsellerbnkno; }
set { SetPropertyValue<string>("sellerbnkno", ref fsellerbnkno, value); }
}
string fnegativesign;
[Size(10)]
public string negativesign
{
get { return fnegativesign; }
set { SetPropertyValue<string>("negativesign", ref fnegativesign, value); }
}
string fofc;
[Size(3)]
public string ofc
{
get { return fofc; }
set { SetPropertyValue<string>("ofc", ref fofc, value); }
}
string fcur;
[Size(3)]
public string cur
{
get { return fcur; }
set { SetPropertyValue<string>("cur", ref fcur, value); }
}
int foldunino;
public int oldunino
{
get { return foldunino; }
set { SetPropertyValue<int>("oldunino", ref foldunino, value); }
}
bool fwpbz;
public bool wpbz
{
get { return fwpbz; }
set { SetPropertyValue<bool>("wpbz", ref fwpbz, value); }
}
string fownerkey;
[Indexed(Name = @"IX_HTTAX_HEADER")]
[Size(16)]
public string ownerkey
{
get { return fownerkey; }
set { SetPropertyValue<string>("ownerkey", ref fownerkey, value); }
}
[Association(@"HTTAX_FEEDBACKReferencesHTTAX_HEADER", typeof(HTTAX_FEEDBACK))]
public XPCollection<HTTAX_FEEDBACK> HTTAX_FEEDBACK { get { return GetCollection<HTTAX_FEEDBACK>("HTTAX_FEEDBACK"); } }
[Association(@"HTTAX_LINEReferencesHTTAX_HEADER", typeof(HTTAX_LINE))]
public XPCollection<HTTAX_LINE> HTTAX_LINE { get { return GetCollection<HTTAX_LINE>("HTTAX_LINE"); } }
}
}
可以在这里定义字段的默认值
using DevExpress.Xpo;
namespace PtVat.ptdata
{
public partial class HTTAX_HEADER
{
public HTTAX_HEADER(Session session) : base(session)
{
ferp_unino = "";
fvendeename = "";
fvendeetax = "";
fvendeeadress = "";
fvendeebnkno = "";
ftaxrate = 6;
fremark = "";
finvoicekind = 0;
fpayee = "";
fcheckman = "";
fproposer = "";
fsellertax = "";
fmachineno = 0;
fsellerbnkno = "";
fnegativesign = "";
fofc = "PTS";
fcur = "";
foldunino = 0;
fwpbz = false;
fownerkey = "";
}
public override void AfterConstruction() { base.AfterConstruction(); }
}
}
二,增,删改,查
查:方法有很多,自己觉得三种比较合适自己
1,XPCollection
XPCollection items = new XPCollection(typeof (HTTAX_HEADER));
items.Criteria = CriteriaOperator.Parse("[unino]=?", Iunino);
比较习惯这种写法,好看懂
foreach (HTTAX_HEADER item in items)
{
string vnme = item.vendeename;
...
...
}
可以直接用XPCollection作为控件的数据源,也可以如下使用
BindingSource bsHeader = new BindingSource();
BindingSource bsLine = new BindingSource();
BindingSource bsFeedback = new BindingSource();
bsHeader.DataSource=items;
bsLine.DataSource=bsHeader;
bsLine.DataMember=HTTAX_LINE;
bsFeedback.DataSource=bsHeader;
bsFeedback.DataMember=HTTAX_FEEDBACK;
绑定到相应的控件上,形成主从关系增删改都很方便.
2.Linq to XPO
XPQuery<HTTAX_HEADER> Headers = new XPQuery<HTTAX_HEADER>(Session.DefaultSession);
XPQuery<HTTAX_LINE> Lines = new XPQuery<HTTAX_LINE>(Session.DefaultSession);
var item=from header in Headers
from line in Lines
where header.unino==line.unino && ...
select new{....}
3.直接用SQL
string sql="select * from httax_header"
SelectedData sd = Session.DefaultSession.ExecuteQuery(sql);
foreach (SelectStatementResultRow re in sd.ResultSet[0].Rows)
{
.....
}
另外一种
Session ses = XpoDefault.Session;
IDbCommand cmd = ses.DataLayer.CreateCommand();
cmd.CommandText = "select hd.erp_unino as 发票号,fb.typecode as 类别代码,hd.vendeename as 客户名称,fb.shpamt+fb.taxation as 含税金额,fb.shpamt as 不含税金额,fb.taxation as 税额, " +
"(CASE when INVOICEKIND=0 THEN '专用发票' when invoicekind=2 then '普通发票' end) as 发票种类, " +
"hd.billdate as 开票日期,rc.retdescript as 发票状态,hd.remark as 备注 " +
"from httax_header hd,httax_feedback fb,httax_retcde rc " +
"where fb.id=(select max(id) from httax_feedback where unino=hd.unino) " +
"and ofc='BGB' and rc.retcde=fb.sta " +
"and hd.billdate>='{0}' and hd.billdate<='{1}' " +
"ORDER BY hd.billdate ";
cmd.CommandText = string.Format(cmd.CommandText, DEfrom.DateTime, DEto.DateTime.AddDays(1));
using (IDataReader InvoiceList = cmd.ExecuteReader())
{
GridCInvList.DataSource = InvoiceList;
if (gridView1.RowCount > 0)
{
BTexport.Enabled = true;
}
else
{
BTexport.Enabled = false;
}
}
增删改
作为数据源绑定到控件上就不说了
单一表
HTTAX_HEADER NewHeader = new HTTAX_HEADER(Session.DefaultSession);
NewHeader.vendeename = "abcd";
...
NewHeader.Save();
主从表
var header = new HTTAX_HEADER(session1);
header.vendeename = "John";
header.HTTAX_LINE.Add(new HTTAX_LINE(session1)
{ ProductName = "Chai", ..... });
header.Save();
还可以通过BindingSource来增删改
HTTAX_HEADER item = (HTTAX_HEADER)hTTAX_HEADERBindingSource.Current;
item.delete();
HTTAX_HEADER item = new (HTTAX_HEADER)hTTAX_HEADERBindingSource();
item.vendeename="abcd";
....
<待续....>
|
评分
-
查看全部评分
|