You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
251 lines
6.8 KiB
251 lines
6.8 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Data;
|
|
using Stone.Common;
|
|
using System.Windows.Forms;
|
|
using Stone.Entity;
|
|
using Gm_WMS.DataAccess.DataService;
|
|
|
|
|
|
namespace Stone.WinBiz.BasicData
|
|
{
|
|
public class F_Base
|
|
{
|
|
/// <summary>
|
|
/// 基础资料类型
|
|
/// </summary>
|
|
public string type = "";
|
|
/// <summary>
|
|
/// 基础资料的名称
|
|
/// </summary>
|
|
public string name = string.Empty;
|
|
/// <summary>
|
|
/// 基础资料储存数据的DataSet
|
|
/// </summary>
|
|
public DataSet dsMain = null;
|
|
|
|
|
|
public EntityBase entity = null;
|
|
public EntityBase entityView = null;
|
|
|
|
public string strOrder = "[ID] asc";
|
|
public F_Base()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 绑定数据到DataSet中去(分页)
|
|
/// </summary>
|
|
/// <param name="strWhere"></param>
|
|
//public virtual void BindPageData(string strWhere, int rows1, int rows2)
|
|
//{
|
|
// string strOrder = "id asc";
|
|
|
|
// if (entityView == null) entityView = entity;
|
|
|
|
// dsMain = entityView.GetDataLimit(rows1, rows2, "", strWhere, strOrder);
|
|
// dsMain.Tables[0].TableName = "Data";
|
|
// dsMain.Tables.Add(entityView.GetData("count(*) as AllCount", strWhere, "AllCount asc").Tables[0].Copy());
|
|
// dsMain.Tables[1].TableName = "Page";
|
|
// dsMain.Tables.Add(entity.Table.Copy());
|
|
// dsMain.Tables[2].TableName = "Table";
|
|
//}
|
|
|
|
public virtual void BindPageData(string strWhere)
|
|
{
|
|
//string strOrder = "id asc";
|
|
|
|
if (entityView == null) entityView = entity;
|
|
|
|
dsMain = entityView.GetData("", strWhere, strOrder);
|
|
dsMain.Tables[0].TableName = "Data";
|
|
dsMain.Tables.Add(entity.Table.Copy());
|
|
dsMain.Tables[1].TableName = "Table";
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取DataGridView的显示结果
|
|
/// </summary>
|
|
/// <param name="dgv"></param>
|
|
public virtual void GetView(DataGridView dgv)
|
|
{
|
|
dgv.DataSource = dsMain.Tables["Data"];
|
|
dgv.Columns["ID"].Visible = false; //隐藏ID列
|
|
// MyGridViewStyle.GetGridViewState(dgv, "基础资料" + type);
|
|
MyGridViewStyle.SetDataGridMenuCommon(dgv);
|
|
|
|
MyGridViewStyle.SetDataGridRowNumber(dgv);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 最得指定ID的记录
|
|
/// </summary>
|
|
/// <param name="ID"></param>
|
|
/// <returns></returns>
|
|
public virtual DataRow GetData(int ID)
|
|
{
|
|
DataSet dsData = entity.GetData("", ID);
|
|
if (dsData.Tables[0].Rows.Count > 0)
|
|
{
|
|
return dsData.Tables[0].Rows[0];
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询指定条件的记录
|
|
/// </summary>
|
|
/// <param name="strWhere"></param>
|
|
/// <returns></returns>
|
|
public virtual DataRow GetData(string strWhere)
|
|
{
|
|
DataSet dsData = entity.GetData(strWhere);
|
|
if (dsData.Tables[0].Rows.Count > 0)
|
|
{
|
|
return dsData.Tables[0].Rows[0];
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 验证数据是否正确
|
|
/// </summary>
|
|
/// <param name="drData"></param>
|
|
public virtual void Checking(DataRow drData, bool isNew)
|
|
{
|
|
if (drData["Code"].ToString().Trim() == "")
|
|
throw new Exception("代码不能为空!");
|
|
|
|
if (isNew)
|
|
{
|
|
if (entity.GetData("", "Code='" + drData["Code"].ToString() + "'", "id asc").Tables[0].Rows.Count > 0)
|
|
throw new Exception("代码 " + drData["Code"].ToString() + " 已经存在!");
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 添加一行数据
|
|
/// </summary>
|
|
/// <param name="drData"></param>
|
|
public virtual void Add(DataRow drData)
|
|
{
|
|
Checking(drData, true);
|
|
|
|
entity.Add(drData);
|
|
|
|
Stone.WinBiz.BasicData.F_Log.WriteLog("新增数据[" + this.name + "]");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修改一行记录
|
|
/// </summary>
|
|
/// <param name="drData"></param>
|
|
public virtual void Edit(DataRow drData)
|
|
{
|
|
Checking(drData, false);
|
|
|
|
entity.Edit(drData);
|
|
|
|
Stone.WinBiz.BasicData.F_Log.WriteLog("修改数据[" + this.name + "]");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除指定ID的记录
|
|
/// </summary>
|
|
/// <param name="ID"></param>
|
|
public virtual void Delete(int ID)
|
|
{
|
|
entity.Del(ID);
|
|
|
|
//删除DataSet中的记录
|
|
DataRow[] drDatas = dsMain.Tables[0].Select("ID=" + ID);
|
|
if (drDatas.Length > 0)
|
|
{
|
|
drDatas[0].Delete();
|
|
}
|
|
|
|
|
|
Stone.WinBiz.BasicData.F_Log.WriteLog("删除数据[" + this.name + "]");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据Code获取Name
|
|
/// </summary>
|
|
/// <param name="Code"></param>
|
|
/// <returns></returns>
|
|
public virtual string GetNameByCode(string Code)
|
|
{
|
|
DataSet dsData = entity.GetData("Name", "Code='" + Code + "'", "id asc");
|
|
|
|
string result = "";
|
|
if (dsData.Tables[0].Rows.Count > 0)
|
|
{
|
|
result = dsData.Tables[0].Rows[0]["Name"].ToString();
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 导入数据
|
|
/// </summary>
|
|
/// <param name="filename"></param>
|
|
public virtual void Input(string filename)
|
|
{
|
|
DataSet dsInput = null;
|
|
|
|
Stone.Common.MyExcelDatabase.OpenDatabase(filename, true);
|
|
dsInput = Stone.Common.MyExcelDatabase.ExecuteDataSet("select * from [Sheet1$]");
|
|
Stone.Common.MyExcelDatabase.CloseDatabase();
|
|
|
|
|
|
|
|
LocalDBService db = null;
|
|
try
|
|
{
|
|
|
|
db = new LocalDBService();
|
|
db.BeginTrans();
|
|
|
|
InputData(dsInput, db);
|
|
|
|
db.Commit();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (db != null) db.Rollback();
|
|
throw new Exception("导入数据失败!\r\n" + "原因为:\r\n" + ex.Message);
|
|
}
|
|
finally
|
|
{
|
|
if (db != null) db.EndTrans();
|
|
}
|
|
|
|
|
|
Stone.WinBiz.BasicData.F_Log.WriteLog("导出Excel[" + this.name + "]");
|
|
|
|
}
|
|
|
|
public virtual void InputData(DataSet dsData, LocalDBService db)
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
|