📄 ucdictkjqjwh.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Sybase.DataWindow;
using Qeb.Control;
using Qeb.Support;
using Qeb.Support.Common;
using Qeb.DBProxy;
namespace Qeb.YK
{
public partial class UCDictKjQjWh : Qeb.GY.UCDictBase
{
private DateTime m_Totay;
public UCDictKjQjWh()
{
InitializeComponent();
}
private void UCDictKjQjWh_Load(object sender, EventArgs e)
{
dwKjQj.LibraryList = PBL.YkPbl;
dwKjQj.DataWindowObject = YkDataObjects.D_Yk_KjQjWh;
dwKjQj.InitUI();
this.SetEdit(false);
try
{
m_Totay = DateHelper.GetServerTime();
this.txtYear.Text = m_Totay.ToString("yyyy");
}
catch(Exception ex)
{
MessageBox.Show("取服务器时间出错:"+ex.Message,MsgTitle.Error);
this.btnModify.Enabled = false;
}
this.RetrieveData();
}
#region 设置界面编辑状态
/// <summary>
/// 设置界面编辑状态
/// </summary>
/// <param name="edit"></param>
private void SetEdit(bool edit)
{
if (edit)
{
//设为可以编辑
try
{
dwKjQj.SetProperty("DataWindow.ReadOnly", "No");
}
catch (Exception ex)
{
MessageBox.Show("设置数据窗口只读属性发生异常:" + ex.Message);
}
}
else
{
//清除修改提示状态
m_IsModified = false;
btnSave.Enabled = false;
try
{
dwKjQj.SetProperty("DataWindow.ReadOnly", "Yes");
}
catch (Exception ex)
{
MessageBox.Show("设置数据窗口只读属性发生异常:" + ex.Message);
}
}
}
#endregion
#region 检索数据
private void RetrieveData()
{
if (this.txtYear.Text==null || this.txtYear.Text.Trim()=="")
{
MessageBox.Show("年份没有输入,请输入再查询!",MsgTitle.Prompt);
this.txtYear.Focus();
return;
}
try
{
DbProxyClient proxy = App.DbProxy;
proxy.Clear();
proxy.AddRetrieveParam(":p_yyid", App.yyId);
proxy.AddRetrieveParam(":p_year", this.txtYear.Text);
proxy.Retrieve(dwKjQj);
}
catch(Exception ex)
{
MessageBox.Show("检索会计期间发生异常:"+ex.Message,MsgTitle.Error);
return;
}
this.SetEdit(false);
//如果是当年或第二年
if (dwKjQj.RowCount == 0)
{
try
{
DateTime today = m_Totay;
string year = this.txtYear.Text;
if (today.ToString("yyyy") == year || today.AddYears(1).ToString("yyyy") == year)
{
int row = 0;
for (int i = 1; i < 13; i++)
{
row = dwKjQj.InsertRow(0);
dwKjQj.SetItemString(row, "kjqj", year + i.ToString("00"));
dwKjQj.SetItemDateTime(row, "ksrq", Convert.ToDateTime(today.ToString("yyyy") + "-" + i.ToString("00") + "-01"));
dwKjQj.SetItemDateTime(row, "jsrq", DateHelper.LastDayofMon(today.Year, i));
dwKjQj.SetItemDecimal(row, "dqbz", 0); //0 未使用
dwKjQj.SetItemString(row, "yyid", App.yyId);
this.btnSave.Enabled = true;
}
}
}
catch(Exception ex)
{
dwKjQj.Reset();
MessageBox.Show("自动生成会计期间发生异常:" + ex.Message, MsgTitle.Error);
}
}
}
#endregion
#region
private void dwKjQj_EditChanged(object sender, Sybase.DataWindow.EditChangedEventArgs e)
{
if (!m_IsModified)
{
this.m_IsModified = true;
this.btnSave.Enabled = true;
}
}
#endregion
private void btnRefresh_Click(object sender, EventArgs e)
{
if (this.m_IsModified)
{
DialogResult result = MessageBox.Show(this, "数据已修改,是否需要保存?", MsgTitle.Prompt, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
return;
}
}
this.RetrieveData();
}
private void txtYear_TextChanged(object sender, EventArgs e)
{
btnRefresh_Click(sender, e);
}
private void txtYear_Enter(object sender, EventArgs e)
{
txtYear.SelectAll();
}
private void btnModify_Click(object sender, EventArgs e)
{
this.SetEdit(true);
}
#region 保存
private void btnSave_Click(object sender, EventArgs e)
{
if (!dwKjQj.AcceptText())
return;
try
{
DbProxyClient proxy = App.DbProxy;
proxy.Clear();
proxy.AddDataWindow(dwKjQj);
proxy.Update();
SetEdit(false);
}
catch (System.Exception ex)
{
MessageBox.Show("保存会计期间发生异常:" + ex.Message, MsgTitle.Error);
}
}
#endregion
private void dwKjQj_ItemChanged(object sender, Sybase.DataWindow.ItemChangedEventArgs e)
{
if (e.ColumnName == "ksrq")
{
if (string.IsNullOrEmpty(e.Data))
{
MessageBox.Show("请输入正确的开始日期!",MsgTitle.Warning);
e.Action = ItemChangedAction.Accept;
return;
}
else
{
if (e.RowNumber > 1)
{
try
{
DateTime rq = Convert.ToDateTime(e.Data.Substring(0,10)).AddDays(-1);
dwKjQj.SetItemDateTime(e.RowNumber - 1, "jsrq", rq);
}
catch (Exception ex)
{
MessageBox.Show("转换日期发生异常:" + ex.Message, MsgTitle.Warning);
e.Action = ItemChangedAction.Reject;
}
}
}
}
else if (e.ColumnName == "jsrq")
{
if (string.IsNullOrEmpty(e.Data))
{
MessageBox.Show("请输入正确的开始日期!", MsgTitle.Warning);
e.Action = ItemChangedAction.Accept;
return;
}
else
{
if (e.RowNumber< 12)
{
try
{
DateTime rq = Convert.ToDateTime(e.Data.Substring(0,10)).AddDays(1);
dwKjQj.SetItemDateTime(e.RowNumber + 1, "ksrq", rq);
}
catch(Exception ex)
{
MessageBox.Show("转换日期发生异常:"+ex.Message, MsgTitle.Warning);
e.Action = ItemChangedAction.Reject;
}
}
}
}
}
private void dwKjQj_ItemError(object sender, ItemErrorEventArgs e)
{
e.Action = ItemErrorAction.RejectWithNoMessage;
}
private void btnClose_Click(object sender, EventArgs e)
{
ParentForm.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -