Business scenario: Cloud customers need to get the data in third-party systems, but the oracle database system is a third party, this is the need to connect oracle database to obtain the data.
Oracle.ManagedDataAccess.dll need to reference this library
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.Metadata.EntityElement;
using System.Text.RegularExpressions;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.Bill.PlugIn.Args;
using Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel;
using Kingdee.BOS.Core.Metadata;
using System.Data;
using Kingdee.BOS.Util;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS;
using Kingdee.BOS.ServiceHelper;
using Kingdee.BOS.JSON;
using Kingdee.BOS.Core.Bill;
using Kingdee.BOS.Core.Metadata.ControlElement;
using Kingdee.BOS.Cache;
//using System.Data.OracleClient;
using Oracle.ManagedDataAccess.Client;
using Kingdee.BOS.WebApi.Client;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Kingdee.BOS.Orm.DataEntity;
namespace GetDataPlugIn
{
public class GetData : AbstractBillPlugIn
{
K3CloudApiClient client = new K3CloudApiClient("http://win-bu6omsa7a39/K3Cloud/");
public override void ButtonClick(ButtonClickEventArgs e)
{
base.ButtonClick(e);
if (e.Key.ToUpperInvariant() == "F_DEV_BUTTON")
{
OracleConnection conn11 = null;
conn11 = OpenConn();
var cmd11 = conn11.CreateCommand();
string Sql;
Sql = "select * from EAS_T_Voucher ";
cmd11.CommandText += Sql;
cmd11.CommandType = CommandType.Text;
using (OracleDataReader rdr11 = cmd11.ExecuteReader())
{
DataTable dt11 = new DataTable();
dt11.Load(rdr11);
int RowCount11;
RowCount11 = dt11.Rows.Count;
for (int i = 0; RowCount11 > i; i++)
{
OracleConnection conn = null;
conn = OpenConn();
var cmd = conn.CreateCommand();
String VoucherId = dt11.Rows[i]["fid"].ToString();
String seleSql = "select * from EAS_T_VoucherEntry where 凭证ID='" + VoucherId + "'";
cmd.CommandText += seleSql;
cmd.CommandType = CommandType.Text;
using (OracleDataReader rdr = cmd.ExecuteReader())
{
DataTable dt = new DataTable();
dt.Load(rdr);
int RowCount;
RowCount = dt.Rows.Count;
int EntryRow = 0;
for (int j = 0; j < RowCount; j++)
{
EntryRow = this.View.Model.GetEntryRowCount("FEntity");
String LoanType = dt.Rows[j]["方向"].ToString();
Decimal FLocalAmount = Decimal.Parse(dt.Rows[j]["FLocalAmount"].ToString());
String DESCR = dt.Rows[j]["FDescription"].ToString();
String AccountItem = dt.Rows[j]["会计科目"].ToString();
String StrAssAct = dt.Rows[j]["Accounting Project "] .ToString ();
String Account = dt.Rows [j] [ " subject code"] .ToString ();
(! String.IsNullOrWhiteSpace (StrAssAct)) IF
{
the DateTime = FBizDate the DateTime.Parse (dt.Rows [J] [ "Business Date"] .ToString ());
Decimal ItemAmount = Decimal.Parse (dt.Rows [J] [ "accounting line amount"] .ToString ());
String EASAssNum = null;
String = CuS dt.Rows [J] [ "customer" ] .ToString ();
String = dt.Rows Sup [J] [ "supplier"] .ToString ();
String POR = dt.Rows [J] [ "other"] .ToString ();
String bank = dt.Rows [j] [ " bank account"] .ToString ();
String ADMIN = dt.Rows [J] [ "administrative organization"] .ToString ();
String CoMP = dt.Rows [J] [ "company"] .ToString ();
String cost = dt.Rows [J] [ "cost center"] .ToString ();
String = dt.Rows the Person [J] [ "staff"] .ToString ();
String StrAssAct1 . dt.Rows = [J] [ "FGeneralAssActType1ID"] the ToString ();
. dt.Rows String StrAssAct2 = [J] [ "FGeneralAssActType2ID"] the ToString ();
String StrAssAct3 dt.Rows = [J] [ "FGeneralAssActType3ID"].ToString();
String StrAssAct4 = dt.Rows[j]["FGeneralAssActType4ID"].ToString();
String StrAssAct5 = dt.Rows[j]["FGeneralAssActType5ID"].ToString();
String StrAssAct6 = dt.Rows[j]["FGeneralAssActType6ID"].ToString();
String StrAssAct7 = dt.Rows[j]["FGeneralAssActType7ID"].ToString();
String StrAssAct8 = dt.Rows[j]["FGeneralAssActType8ID"].ToString();
String StrAssAct9 = dt.Rows[j]["FGeneralAssActType9ID"].ToString();
String StrAssAct10 = dt.Rows[j]["FGeneralAssActType10ID"].ToString();
String entryId = dt.Rows[j]["分录ID"].ToString();
if (StrAssAct8 != null)
{
String haha = StrAssAct8;
}
if (string.IsNullOrWhiteSpace(cus)
&& string.IsNullOrWhiteSpace(por)
&& string.IsNullOrWhiteSpace(bank)
&& string.IsNullOrWhiteSpace(admin)
&& string.IsNullOrWhiteSpace(comp)
&& string.IsNullOrWhiteSpace(cost)
&& string.IsNullOrWhiteSpace(person)
)
{
String AsstActType = "select fnumber from T_BD_GeneralAsstActType ";
if (!string.IsNullOrWhiteSpace(StrAssAct1))
{
AsstActType += "where fid = '" + StrAssAct1 + "'";
}
if (!string.IsNullOrWhiteSpace(StrAssAct2)
)
{
AsstActType += "where fid = '" + StrAssAct2 + "'";
}
if (!string.IsNullOrWhiteSpace(StrAssAct3))
{
AsstActType += "where fid = '" + StrAssAct3 + "'";
}
if (!string.IsNullOrWhiteSpace(StrAssAct4))
{
AsstActType += "where fid = '" + StrAssAct4 + "'";
}
if (!string.IsNullOrWhiteSpace(StrAssAct5))
{
AsstActType += "where fid = '" + StrAssAct5 + "'";
}
if (!string.IsNullOrWhiteSpace(StrAssAct6))
{
AsstActType += "where fid = '" + StrAssAct6 + "'";
}
if (!string.IsNullOrWhiteSpace(StrAssAct7))
{
AsstActType += "where fid = '" + StrAssAct7 + "'";
}
if (!string.IsNullOrWhiteSpace(StrAssAct8))
{
AsstActType += "where fid = '" + StrAssAct8 + "'";
}
if (!string.IsNullOrWhiteSpace(StrAssAct9))
{
AsstActType += "where fid = '" + StrAssAct9 + "'";
}
if (!string.IsNullOrWhiteSpace(StrAssAct10))
{
AsstActType += "where fid = '" + StrAssAct10 + "'";
}
OracleConnection conn2 = null;
conn2 = OpenConn();
var cmd111 = conn2.CreateCommand();
cmd111.CommandText += AsstActType;
cmd111.CommandType = CommandType.Text;
using (OracleDataReader rdr1 = cmd111.ExecuteReader())
{
DataTable zjy = new DataTable();
zjy.Load(rdr1);
int zjyCount;
zjyCount = zjy.Rows.Count;
for (int g = 0; g < zjyCount; g++)
{
EntryRow = this.View.Model.GetEntryRowCount("FEntity");
EASAssNum = zjy.Rows[g]["Fnumber"].ToString();
this.View.Model.SetValue("F_DEV_LoanType", LoanType, EntryRow - 1);
this.View.Model.SetValue("F_DEV_FLocalAmount", FLocalAmount, EntryRow - 1);
this.View.Model.SetValue("F_DEV_ItemAmount", ItemAmount, EntryRow - 1);
this.View.Model.SetValue("F_DEV_AccountItem", AccountItem, EntryRow - 1);
this.View.Model.SetValue("F_DEV_Account", Account, EntryRow - 1);
this.View.Model.SetValue("F_DEV_Voucherid", dt11.Rows[i]["fid"].ToString(), EntryRow - 1);
this.View.Model.SetValue("F_DEV_EASACCNO", dt11.Rows[i]["凭证号"].ToString(), EntryRow - 1);
this.View.Model.SetValue("F_DEV_EASAssNum", EASAssNum, EntryRow - 1);
this.View.Model.SetValue("F_DEV_StrAssAct", StrAssAct, EntryRow - 1);
this.View.Model.SetValue("F_DEV_Date", FBizDate, EntryRow - 1);
this.View.Model.SetValue("F_DEV_FEXPLANATION", DESCR, EntryRow - 1);
this.View.Model.CreateNewEntryRow("FEntity");
}
conn2.Close();
}
}
else
{
EntryRow = this.View.Model.GetEntryRowCount("FEntity");
EASAssNum = cus + Sup + por + bank + admin + comp + cost + person;
this.View.Model.SetValue("F_DEV_StrAssAct", StrAssAct, EntryRow - 1);
this.View.Model.SetValue("F_DEV_EASAssNum", EASAssNum, EntryRow - 1);
this.View.Model.SetValue("F_DEV_LoanType", LoanType, EntryRow - 1);
this.View.Model.SetValue("F_DEV_FLocalAmount", FLocalAmount, EntryRow - 1);
this.View.Model.SetValue("F_DEV_ItemAmount", ItemAmount, EntryRow - 1);
this.View.Model.SetValue("F_DEV_AccountItem", AccountItem, EntryRow - 1);
this.View.Model.SetValue("F_DEV_Account", Account, EntryRow - 1);
this.View.Model.SetValue("F_DEV_Voucherid", dt11.Rows[i]["fid"].ToString(), EntryRow - 1);
this.View.Model.SetValue("F_DEV_EASACCNO", dt11.Rows[i]["凭证号"].ToString(), EntryRow - 1);
this.View.Model.SetValue("F_DEV_Date", FBizDate, EntryRow - 1);
this.View.Model.SetValue("F_DEV_FEXPLANATION", DESCR, EntryRow - 1);
this.View.Model.CreateNewEntryRow("FEntity");
}
}
else
{
EntryRow = this.View.Model.GetEntryRowCount("FEntity");
this.View.Model.SetValue("F_DEV_StrAssAct", StrAssAct, EntryRow - 1);
this.View.Model.SetValue("F_DEV_LoanType", LoanType, EntryRow - 1);
this.View.Model.SetValue("F_DEV_FLocalAmount", FLocalAmount, EntryRow - 1);
this.View.Model.SetValue("F_DEV_AccountItem", AccountItem, EntryRow - 1);
this.View.Model.SetValue("F_DEV_Account", Account, EntryRow - 1);
this.View.Model.SetValue("F_DEV_Voucherid", dt11.Rows[i]["fid"].ToString(), EntryRow - 1);
this.View.Model.SetValue("F_DEV_EASACCNO", dt11.Rows[i]["凭证号"].ToString(), EntryRow - 1);
this.View.Model.SetValue("F_DEV_FEXPLANATION", DESCR, EntryRow - 1);
this.View.Model.CreateNewEntryRow("FEntity");
}
}
}
conn.Close();
}
}
conn11.Close();
}
}
static OracleConnection OpenConn()
{
try
{
OracleConnection conn = new OracleConnection();
conn.ConnectionString = "Data Source= (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.33)(PORT = 1521))" +
"(CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = test)));User Id=hrpdb;Password=password;";
conn.Open();
return conn;
}
catch (Exception)
{
//MessageBox.Show(ex.Message);
}
return null;
}
}
}