用友U8是国内最受欢迎的ERP系统之一,广泛应用于中小企业。U8提供了丰富的二次开发接口,支持企业根据自身需求进行定制化开发。
using System;
using UFSoft.U8.Framework.Login;
using UFSoft.U8.Pub.Data;
namespace U8Sample
{
class Program
{
static void Main(string[] args)
{
// 登录U8
Login login = new Login();
login.UserName = "admin";
login.Password = "123456";
login.SubCAccId = "001";
login.Year = "2024";
login.Period = "1";
if (login.LoginSuccess())
{
// 调用业务操作
Console.WriteLine("登录成功");
// 示例:获取客户信息
string sql = "SELECT cCusCode, cCusName FROM Customer";
DataTable dt = DBHelper.ExecuteDataSet(login.AccId, sql).Tables[0];
foreach (DataRow row in dt.Rows)
{
Console.WriteLine($"客户代码:{row["cCusCode"]}, 客户名称:{row["cCusName"]}");
}
}
else
{
Console.WriteLine("登录失败:" + login.GetLastError());
}
}
}
}
using System;
using System.ServiceModel;
namespace U8WebServiceSample
{
class Program
{
static void Main(string[] args)
{
// 创建服务客户端
var client = new U8WebService.ServiceClient();
// 调用登录方法
var loginResult = client.Login("admin", "123456", "001", "2024", "1");
if (loginResult.Success)
{
// 调用业务方法
var result = client.GetCustomerList(loginResult.Token);
foreach (var customer in result)
{
Console.WriteLine($"客户:{customer.cCusName} ({customer.cCusCode})");
}
}
else
{
Console.WriteLine("登录失败:" + loginResult.Message);
}
}
}
}
using System;
using UFSoft.U8.UAP.UIMeta;
using UFSoft.U8.UAP.UI;
namespace U8FormPlugin
{
public class CustomerEditPlugin : U8FormPlugin
{
public override void AfterCreateNew(UFSoft.U8.UAP.UI.EventArgs e)
{
// 初始化表单数据
base.AfterCreateNew(e);
this.View.Model.SetValue("cCusName", "新客户");
}
public override void BeforeSave(UFSoft.U8.UAP.UI.EventArgs e)
{
// 保存前验证
base.BeforeSave(e);
string name = this.View.Model.GetValue("cCusName") as string;
if (string.IsNullOrEmpty(name))
{
this.View.ShowMessage("客户名称不能为空");
e.Cancel = true;
}
}
}
}
使用U8的UAP报表设计器,可以可视化地设计报表。
using System;
using System.Data;
using UFSoft.U8.Pub.Data;
namespace U8DataAccess
{
class Program
{
static void Main(string[] args)
{
// 数据库连接
string connStr = "Server=localhost;Database=UFDATA_001_2024;Uid=sa;Pwd=123456";
// 执行SQL查询
string sql = "SELECT * FROM Customer WHERE cCusCode = '001'";
DataTable dt = DBHelper.ExecuteDataSet(connStr, sql).Tables[0];
// 处理结果
if (dt.Rows.Count > 0)
{
DataRow row = dt.Rows[0];
Console.WriteLine($"客户名称:{row["cCusName"]}");
Console.WriteLine($"联系电话:{row["cPhone"]}");
}
}
}
}
用友U8提供了ORM框架,可以方便地进行数据操作。
用友U8提供了丰富的二次开发接口和工具,开发者可以通过API集成、插件开发等方式扩展系统功能。掌握U8的二次开发技术,对于企业的数字化转型和系统定制具有重要意义。