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.
 
 
 
 

350 lines
9.5 KiB

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Stone.WinBiz.BasicData;
using Stone.Common;
namespace Stone.WinModule.BasicData
{
public partial class frmBaseMain : Stone.WinModule.frmBase
{
public F_Base m_Base = null;
public string strWhere = "1=1";
public frmSelectDataGridView frmFilter = null;
public string SelectValue = "";
public DataGridViewRow SelectRow = null;
public virtual void init()
{
try
{
this.Text = m_Base.name;
this.TabText = m_Base.name;
UpdateGridView();
frmFilter = new frmSelectDataGridView(this.dgrdView);
}
catch (Exception ex)
{
MyMessageBox.ShowErrorMessage(ex.Message);
}
}
public DialogResult ShowSelect(string selectValue)
{
this.tlbAdd.Enabled = false;
this.tlbAddCopy.Enabled = false;
this.tlbEdit.Enabled = false;
this.tlbDelete.Enabled = false;
this.tlbInput.Enabled = false;
this.tlbSelect.Enabled = true;
this.txtCode.Text = selectValue;
btnSerach_Click(new object(), new EventArgs());
return this.ShowDialog();
}
public frmBaseMain()
{
InitializeComponent();
}
private void frmBaseMain_Load(object sender, EventArgs e)
{
}
private void tlbAdd_Click(object sender, EventArgs e)
{
try
{
if (F_Factory.ShowMainDetail(m_Base).ShowAdd() == DialogResult.OK)
{
UpdateGridView();
}
}
catch (Exception ex)
{
MyMessageBox.ShowErrorMessage(ex.Message);
}
}
private void tlbAddCopy_Click(object sender, EventArgs e)
{
try
{
if (this.dgrdView.SelectedRows.Count > 0)
{
int ID = Convert.ToInt32(this.dgrdView.SelectedRows[0].Cells["ID"].Value);
if (F_Factory.ShowMainDetail(m_Base).ShowAddCopy(ID) == DialogResult.OK)
{
UpdateGridView();
}
}
else
{
throw new Exception("请选择一条要复制的记录!");
}
}
catch (Exception ex)
{
MyMessageBox.ShowErrorMessage(ex.Message);
}
}
private void tlbEdit_Click(object sender, EventArgs e)
{
try
{
if (this.dgrdView.SelectedRows.Count > 0)
{
int ID = Convert.ToInt32(this.dgrdView.SelectedRows[0].Cells["ID"].Value);
if (F_Factory.ShowMainDetail(m_Base).ShowEdit(ID) == DialogResult.OK)
{
UpdateGridView();
}
}
else
{
throw new Exception("请选择一条要修改的记录!");
}
}
catch (Exception ex)
{
MyMessageBox.ShowErrorMessage(ex.Message);
}
}
private void tlbDelete_Click(object sender, EventArgs e)
{
try
{
Delete();
}
catch (Exception ex)
{
MyMessageBox.ShowErrorMessage(ex.Message);
}
}
private void tlbFilter_Click(object sender, EventArgs e)
{
try
{
frmFilter.ShowDialog();
if (frmFilter.SelectString != "")
{
strWhere = frmFilter.SelectString;
// UpdateGridView();
UpdateGridViewByFilter();
}
else
{
strWhere = "1=1";
}
}
catch (Exception ex)
{
MyMessageBox.ShowErrorMessage(ex.Message);
}
}
private void dgrdView_DoubleClick(object sender, EventArgs e)
{
if (this.tlbSelect.Enabled)
{
tlbSelect_Click(new object(), new EventArgs());
}
}
private void tlbSelect_Click(object sender, EventArgs e)
{
try
{
if (this.dgrdView.SelectedRows.Count > 0)
{
this.SelectValue = GetSelect();
this.DialogResult = DialogResult.OK;
this.Close();
}
else
{
throw new Exception("请选择一条要修改的记录!");
}
}
catch (Exception ex)
{
MyMessageBox.ShowErrorMessage(ex.Message);
}
}
private void tlbRefresh_Click(object sender, EventArgs e)
{
try
{
UpdateGridView();
}
catch (Exception ex)
{
MyMessageBox.ShowErrorMessage(ex.Message);
}
}
private void tlbSet_Click(object sender, EventArgs e)
{
MyGridViewStyle.Show(this.dgrdView, "基础资料" + m_Base.type.ToString());
}
private void tlbInput_Click(object sender, EventArgs e)
{
try
{
if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
{
m_Base.Input(this.openFileDialog1.FileName);
UpdateGridView();
MyMessageBox.ShowInfoMessage("数据导入成功!");
}
}
catch (Exception ex)
{
MyMessageBox.ShowInfoMessage(ex.Message);
}
}
private void tlbOutPut_Click(object sender, EventArgs e)
{
try
{
Stone.Common.MyExport.ShowExport(this.dgrdView);
}
catch (Exception ex)
{
MyMessageBox.ShowInfoMessage(ex.Message);
}
}
private void tlbExit_Click(object sender, EventArgs e)
{
this.Close();
}
public void btnSerach_Click(object sender, EventArgs e)
{
try
{
this.txtCode.Focus();
this.txtCode.SelectAll();
UpdateGridView();
}
catch (Exception ex)
{
MyMessageBox.ShowErrorMessage(ex.Message);
}
}
private void txtCode_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
btnSerach_Click(new object(), new EventArgs());
}
}
private void frmBaseMain_FormClosing(object sender, FormClosingEventArgs e)
{
try
{
MyGridViewStyle.SaveGridViewState(this.dgrdView, "基础资料" + m_Base.type.ToString());
}
catch
{
}
}
#region 可覆写的方法
/// <summary>
/// 更新DataGridView显示
/// </summary>
public virtual void UpdateGridView()
{
string code = this.txtCode.Text.Trim();
Search(code);
m_Base.BindPageData(strWhere);
m_Base.GetView(this.dgrdView);
this.tlbAllCount.Text = "记录数:" + m_Base.dsMain.Tables["Data"].Rows.Count;
}
public virtual void UpdateGridViewByFilter()
{
string code = this.txtCode.Text.Trim();
m_Base.BindPageData(strWhere);
m_Base.GetView(this.dgrdView);
this.tlbAllCount.Text = "记录数:" + m_Base.dsMain.Tables["Data"].Rows.Count;
}
/// <summary>
/// 快速搜索
/// </summary>
/// <param name="code"></param>
public virtual void Search(string code)
{
if (code == "")
{
strWhere = "1=1";
}
else
{
strWhere = " [Code] like '%" + code + "%' ";
}
}
/// <summary>
/// 取得选择的行的值,默认为Code字段,如果是其他字段请覆写该方法
/// </summary>
/// <returns></returns>
public virtual string GetSelect()
{
SelectRow = this.dgrdView.SelectedRows[0];
return this.dgrdView.SelectedRows[0].Cells["Code"].Value.ToString();
}
//删除记录
public virtual void Delete()
{
if (this.dgrdView.SelectedRows.Count > 0)
{
if (MyMessageBox.ShowQuestion("你确实要删除选择的记录吗?"))
{
int ID = Convert.ToInt32(this.dgrdView.SelectedRows[0].Cells["ID"].Value);
m_Base.Delete(ID);
UpdateGridView();
}
}
else
{
throw new Exception("请选择一条要删除的记录!");
}
}
#endregion
}
}