调用KINGDEE的凭证导入接口

引入webservices在visualstudio2010中非常简单,只需要“添加web引用”就可以了,然后把相应的网址输入进去。

之后就是万年不变的编程和调用了。

看源码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WindowsFormsApplication1.EASLogin;
using WindowsFormsApplication1.WSGL;
using WindowsFormsApplication1.Properties;
using System.Xml;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{

public EASLoginProxyService Proxy = new EASLoginProxyService();
public WSContext WSC = new WSContext();

public Form1()
{
InitializeComponent();

}
public class LoginInfo
{
public String DBCenter;
public int DBType;
public String UserID;
public String PassWord;

//public LoginInfo();

public void setDBCenter(String DBCenter)
{
this.DBCenter = DBCenter;
}
public String getDBCenter()
{
return this.DBCenter;
}
public void setDBType(int DBType)
{
this.DBType = DBType;
}
public int getDBType()
{
return this.DBType;
}
public void setUserID(String UserID)
{
this.UserID = UserID;
}
public String getUserID()
{
return this.UserID;
}
public void setPassWord(String PassWord)
{
this.PassWord = PassWord;
}
public String getPassWord()
{
return this.PassWord;
}

}

private void Form1_Load(object sender, EventArgs e)
{


}

private void button1_Click(object sender, EventArgs e)
{

LoginInfo LoginInfo = new LoginInfo();
LoginInfo.setDBCenter(textBox1.Text);
if (comboBox1.Text == "ORACLE")
{
LoginInfo.setDBType(1);
}
else if (comboBox1.Text == "SQLSERVER")
{
LoginInfo.setDBType(0);
}
else if (comboBox1.Text == "DB2")
{
LoginInfo.setDBType(2);
}
else
{
MessageBox.Show("“数据库类型”选择错误,请重新选择。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
LoginInfo.setUserID(textBox3.Text);
LoginInfo.setPassWord(textBox4.Text);





try
{
WSC = Proxy.login(LoginInfo.getUserID(), LoginInfo.getPassWord(), "eas", LoginInfo.getDBCenter(), "L2", LoginInfo.getDBType(), "BaseDB");
//WSContext WSC = Proxy.login("user", "kduser", "eas", "123", "L2", 0,"BaseDB");

if (WSC.sessionId == null)
{
MessageBox.Show("登录失败,请核对登录信息.", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{

Form2 fm2 = new Form2(this);
fm2.Show();
this.Hide();
}
}
catch (Exception ex)
{
MessageBox.Show("不能登录EAS服务器,请确认服务器已启动并保持网络畅通.", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

}

private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using Microsoft.Office.Interop.Excel;

namespace WindowsFormsApplication1
{
public partial class Form2 : Form
{
public Form1 form1;
public Form2(Form1 fm1)
{
InitializeComponent();
form1 = fm1;
}

private void Form2_Load(object sender, EventArgs e)
{

}

/*private void 保存ToolStripMenuItem_Click(object sender, EventArgs e)
{

System.Data.DataTable dt = new System.Data.DataTable();
dt.Clear();

foreach (DataGridViewColumn headerCell in dataGridView1.Columns)
{
dt.Columns.Add(headerCell.HeaderText);
}
foreach (DataGridViewRow item in dataGridView1.Rows)
{
DataRow dr = dt.NewRow();
for (int i = 0; i < dt.Columns.Count; i++)
{
dr[i] = item.Cells[i].Value.ToString();
}
dt.Rows.Add(dr);
}

saveFileDialog1.ShowDialog();
String SaveFilePath = saveFileDialog1.FileName.ToString();

SaveDataTableToExcel(dt,SaveFilePath);
}*/

public static DataSet LoadDataFromExcel(string filePath)
{
///读取选定路径的excel类型文件
try
{
string strConn;
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath + ";Extended Properties='Excel 8.0;HDR=False;IMEX=1'";
OleDbConnection OleConn = new OleDbConnection(strConn);
OleConn.Open();
String sql = "SELECT * FROM [Sheet 1$]";//可是更改Sheet名称,比如sheet2,等等
OleDbDataAdapter OleDaExcel = new OleDbDataAdapter(sql, OleConn);
DataSet OleDsExcle = new DataSet();
OleDaExcel.Fill(OleDsExcle);
OleConn.Close();
return OleDsExcle;
}
catch (Exception err)
{
//MessageBox.Show("数据绑定Excel失败!失败原因:" + err.Message, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
return null;
}
}

/*public static bool SaveDataTableToExcel(System.Data.DataTable excelTable, string filePath)
{

///保存修改后的数据到文件。

try
{
Microsoft.Office.Interop.Excel.Application app =
new Microsoft.Office.Interop.Excel.ApplicationClass();

app.Visible = false;
Workbook wBook = app.Workbooks.Add(true);
Worksheet wSheet = wBook.Worksheets[1] as Worksheet;
if (excelTable.Rows.Count > 0)
{
int row = 0;
row = excelTable.Rows.Count;
int col = excelTable.Columns.Count;
for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
{
string str = excelTable.Rows[i][j].ToString();
wSheet.Cells[i + 2, j + 1] = str;
}
}
}
int size = excelTable.Columns.Count;
for (int i = 0; i < size; i++)
{
wSheet.Cells[1, 1 + i] = excelTable.Columns[i].ColumnName;
}
//设置禁止弹出保存和覆盖的询问提示框
app.DisplayAlerts = false;
app.AlertBeforeOverwriting = false;
//保存工作簿 < type="text/JavaScript"> alimama_pid="mm_10249644_1605763_5027492"; alimama_type="f"; alimama_sizecode ="tl_1x5_8"; alimama_fontsize=12; alimama_bordercolor="FFFFFF"; alimama_bgcolor="FFFFFF"; alimama_titlecolor="0000FF"; alimama_underline=0; alimama_height=22; alimama_width=0; < src="http://a.alimama.cn/inf.js" type=text/javascript>
wBook.Save();
//保存excel文件
app.Save(filePath);
app.SaveWorkspace(filePath);
app.Quit();
app = null;
return true;
}
catch (Exception err)
{
MessageBox.Show("导出Excel出错!错误原因:" + err.Message , "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
return false;
}
finally
{
}
}*/

private void 文件ToolStripMenuItem_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
String OpenFilePath = openFileDialog1.FileName.ToString();
if (OpenFilePath != null)
{
try
{
dataGridView1.DataSource = LoadDataFromExcel(OpenFilePath).Tables[0].DefaultView;
dataGridView1.AllowUserToAddRows = false;
dataGridView1.AllowUserToDeleteRows = false;
dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.Silver;
}
catch (Exception ex0)
{
MessageBox.Show("文件未打开。/n/n以下是解决方法:/n1.请正确选择文件路径。/n2.如果文件正在使用中,请关闭。/n3.请确定打开的文件类型为MICROSOFT EXCEL表格。/n4.确认要导入文件的表单名称为Sheet 1(‘Sheet’和‘1’之间有一个空格),若不是,请手动修改。/n/n如果以上方法都不能解决此问题,请联系计算机管理员。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
else
{
MessageBox.Show("未选择数据", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}

private void 退出系统ToolStripMenuItem_Click(object sender, EventArgs e)
{
System.Windows.Forms.Application.Exit();
}

private void 编辑ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (dataGridView1.Rows.Count <= 0)
{
MessageBox.Show("没有选择数据,请点击'文件'-'打开'来选择数据。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
Form3 fm3 = new Form3(this,form1);
fm3.Show();
this.Hide();
}
}

}
}

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;

namespace WindowsFormsApplication1
{
public partial class Form3 : Form
{

public Form2 form2;
public Form1 form1;

public Form3(Form2 fm2,Form1 fm1)
{
InitializeComponent();
form2 = fm2;
form1 = fm1;

}

private void Form3_Load(object sender, EventArgs e)
{
dateTimePicker1.Text = form2.dataGridView1.Rows[1].Cells["日期"].Value.ToString();
dateTimePicker2.Text = form2.dataGridView1.Rows[1].Cells["日期"].Value.ToString();
textBox5.Text = (form2.dataGridView1.Rows[1].Cells["日期"].Value.ToString()).Substring(0, 4);
textBox2.Text = (form2.dataGridView1.Rows[1].Cells["日期"].Value.ToString()).Substring(5, 2);


DataTable dt = new DataTable();
dt.Columns.Add("分录行号");
dt.Columns.Add("摘要");
dt.Columns.Add("科目");
dt.Columns.Add("借方");
dt.Columns.Add("贷方");
dt.Columns.Add("报告币借方");
dt.Columns.Add("报告币贷方");

for (int i = 1; i <= 80; i++)
{
DataRow dr = dt.NewRow();
dr[0] = i;
for (int j = 1; j <= 6; j++)
{
dr[j] = "";

}
dt.Rows.Add(dr);
}

dataGridView1.DataSource = dt;


}

private void 导出到EAS系统ToolStripMenuItem_Click(object sender, EventArgs e)
{


ImportVoucher(e);
}

private void ImportVoucher(EventArgs e)
{
WSGL.WSGLWebServiceFacadeSrvProxyService ImportProxyService = new WSGL.WSGLWebServiceFacadeSrvProxyService();

WSGL.WSWSVoucher[] vouchers = getvocher();
vouchers = getvocher();

try
{
ImportProxyService.importVoucher(vouchers, 0, 00, 0);
MessageBox.Show("导入成功", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
}


//try
//{

//ls = ImportProxyService.getVoucher("01.0014","2010","4",1,3);
//ImportProxyService.Url = "http://127.0.0.1:6888/ormrpc/services/"+"WSWSVoucher";



// MessageBox.Show(vouchers.ToString());

// ls = ImportProxyService.getVoucher(

//}
//catch (Exception ex)
//{
// MessageBox.Show("未能导入数据,以下是详细信息:/n/n" + ex.ToString(), "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
//}
}

public WSGL.WSWSVoucher[] getvocher()
{
WSGL.WSWSVoucher[] data = new WSGL.WSWSVoucher[1];
data[0] = new WSGL.WSWSVoucher();
data[0].companyNumber = "01.0014";
data[0].bookedDate = "2010-04-29";
data[0].bizDate = "2010-04-29";
data[0].periodYear = 2010;
data[0].periodNumber = 04;
data[0].voucherType = "记";
data[0].voucherNumber = "1";
data[0].entrySeq = 1;
data[0].accountNumber = "1001";
data[0].currencyNumber = "BB01";
data[0].entryDC = 1;
data[0].originalAmount = 10000.21;
data[0].debitAmount = 10000.21;
data[0].creator = "任元元";
data[0].itemFlag = 0;


//data[0].accountNumber = "1001";
////data[0].assistBizDate = 111;
////data[0].assistEndDate = "";
//data[0].asstSeq = 1;
//data[0].attaches = 0;
//data[0].auditor = "任元元";
//data[0].bizDate = "2010-04-30";
//data[0].bizNumber = "1";
//data[0].bookedDate = "2010-04-30";
//data[0].cashflowAmountLocal = 1001;
//data[0].cashflowAmountOriginal = 1001;
//data[0].cashflowAmountRpt = 1001;
//data[0].companyNumber = "01.008";

//data[0].cashflowAmountLocal = 1001.01;
//data[0].cashflowAmountOriginal = 1001.01;
//data[0].cashflowAmountRpt = 1001.01;

MessageBox.Show(data[0].ToString());

return data;
}

private void 退出系统ToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}


}
}

你可能感兴趣的:(接口)