using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using LYFZ.BLL;
using LYFZ.Helper;
namespace LYFZ.Software.MainBusiness.OAShopManagement
{
public class frmMattersApply : LYFZ.Software.UI.OAShopManagement.frmMattersApply
{
///
/// 当前事项角色
///
MattersApplyType currentMatterRole = MattersApplyType.申请人;
///
/// 不当查询的审核状态
///
state currentAuditStatus = state.申请中;
public frmMattersApply(string parameter)
:this()
{
this.currentMatterRole = (MattersApplyType)Enum.Parse(typeof(MattersApplyType), parameter);
}
public frmMattersApply()
{
//我要申请
this.btnAddApplication.Click += btnAddTask_Click;
//审批申请
this.btnApproving.Click += btnApproving_Click;
//删除申请
this.btndel.Click += btndel_Click;
//关闭
this.btnClose.Click += btnClose_Click;
//dgv事件
this.dgvTaskView.CellDoubleClick += dgvTaskView_CellDoubleClick;
// this.dgvTaskView.RowsAdded += dgvTaskView_RowsAdded;
//加载事件
this.Load += frmMattersApply_Load;
this.ucMatt.EventPaging += ucMatt_EventPaging;
this.btnAddApplication.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.MattersApplication, CustomAttributes.OperatingAuthority.Add);
this.btndel.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.MattersApplication, CustomAttributes.OperatingAuthority.Delete);
this.btnApproving.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.MattersApplication, CustomAttributes.OperatingAuthority.Audit);
this.ucMatt.PageSize = LYFZ.BLL.BLL_SystemGlobalSetting.SysTemGlobalSetMoel.ReportFormPageSize;
this.rdoapply.Click += RdoClick_Click;
this.rdopassed.Click += RdoClick_Click;
this.rdoNotpassed.Click += RdoClick_Click;
}
void RdoClick_Click(object sender, EventArgs e)
{
ComponentLibrary.RadioButtonEx rdoBtn = (ComponentLibrary.RadioButtonEx)sender;
if (rdoBtn.Checked)
{
this.currentAuditStatus = (state)Convert.ToInt32(rdoBtn.Tag);
}
ucMatt.Bind();
}
//void dgvTaskView_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
//{
// if (!string.IsNullOrEmpty(this.dgvTaskView.Rows[e.RowIndex].Cells["Column5"].Value.ToString().Trim()))
// {
// this.dgvTaskView.Rows[e.RowIndex].Cells["Column5"].Value = LYFZ.Command.Command_Validate.DateTimeToString(this.dgvTaskView.Rows[e.RowIndex].Cells["Column5"].Value, "yyyy-MM-dd HH:mm");
// }
//}
string GetWhereString()
{
string whereStr = "Matter_Type=0 ";
if (currentMatterRole == MattersApplyType.申请人)
{
whereStr += " and Matter_CreateName='" + LYFZ.BLL.BLL_ErpUser.UsersModel.User_EmployeeID.Trim() + "'";
}
else if(currentMatterRole == MattersApplyType.审核人){
whereStr += " and Matter_UpdateName='" + LYFZ.BLL.BLL_ErpUser.UsersModel.User_EmployeeID.Trim() + "'";
}
whereStr += " and Matter_state='" + this.currentAuditStatus.ToString().Trim() + "'";
return whereStr;
}
public int ucMatt_EventPaging(UCPager.EventPagingArg e)
{
LYFZ.UCPager.PageData pageData = new LYFZ.UCPager.PageData();
pageData.TableName = "tb_ErpShopEvententry";
pageData.PageIndex = this.ucMatt.PageCurrent;
pageData.PageSize = this.ucMatt.PageSize;
pageData.QueryCondition = GetWhereString();
pageData.QueryFieldName = " [ID]"
+" ,[Matter_CreateName]"
+" ,[Matter_CreateDatetime]"
+" ,[Matter_content]"
+" ,[Matter_state]"
+" ,[Matter_UpdateName]"
+" ,[Matter_UpdateDatetime]"
+" ,[Matter_opinion]"
+" ,[Matter_Type]"
+" ,[Matter_Category]"
+" ,[Matter_Title]"
+" ,[Matter_StarLeaveTime]"
+" ,[Matter_EndLeaveTime]"
+" ,[Matter_LeadershipInstruction]"
+" ,[Matter_InstructedPeople]"
+" ,[Matter_InstructedTime] ";
pageData.OrderStr = "ID desc";
DataTable dt = null;
LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
{
dt = pageData.QueryDataTable().Tables[0];
});
try
{
if (dt != null)
{
this.dgvTaskView.Rows.Clear();
for (int i = 0; i < dt.Rows.Count; i++)
{
DataGridViewRow row = new DataGridViewRow();
row.CreateCells(this.dgvTaskView);
row.Tag = dt.Rows[i];
row.Cells[0].Value = dt.Rows[i]["ID"].ToString();
string Matter_Title = "无主题";
if (dt.Rows[i]["Matter_Title"] != null && !string.IsNullOrEmpty(dt.Rows[i]["Matter_Title"].ToString().Trim()))
{
Matter_Title = dt.Rows[i]["Matter_Title"].ToString();
}
row.Cells[1].Value = Matter_Title;
row.Cells[2].Value = dt.Rows[i]["Matter_content"].ToString();
row.Cells[3].Value = LYFZ.BLL.WageStatisticsProcess.GetClassCodeToCalssName(dt.Rows[i]["Matter_Category"].ToString()); ;
row.Cells[4].Value = UserIDToName(dt.Rows[i]["Matter_CreateName"]);
row.Cells[4].Tag = dt.Rows[i]["Matter_CreateName"].ToString();
row.Cells[5].Value = LYFZ.Command.Command_Validate.DateTimeToString(dt.Rows[i]["Matter_CreateDatetime"], "yyyy-MM-dd HH:mm");
row.Cells[6].Value = dt.Rows[i]["Matter_state"].ToString();
row.Cells[7].Value = UserIDToName(dt.Rows[i]["Matter_UpdateName"]);
row.Cells[7].Tag = dt.Rows[i]["Matter_UpdateName"].ToString();
row.Cells[8].Value = LYFZ.Command.Command_Validate.DateTimeToString(dt.Rows[i]["Matter_UpdateDatetime"], "yyyy-MM-dd HH:mm");
if (dt.Rows[i]["Matter_opinion"] != null)
{
row.Cells[9].Value = dt.Rows[i]["Matter_opinion"].ToString();
}
if (dt.Rows[i]["Matter_LeadershipInstruction"] != null)
{
row.Cells[10].Value = dt.Rows[i]["Matter_LeadershipInstruction"].ToString();
}
if (dt.Rows[i]["Matter_InstructedPeople"] != null)
{
row.Cells[11].Value = UserIDToName(dt.Rows[i]["Matter_InstructedPeople"]);
row.Cells[11].Tag = dt.Rows[i]["Matter_InstructedPeople"].ToString();
}
row.Cells[12].Value = LYFZ.Command.Command_Validate.DateTimeToString(dt.Rows[i]["Matter_InstructedTime"], "yyyy-MM-dd HH:mm");
this.dgvTaskView.Rows.Add(row);
}
this.ucMatt.TbDataSource = dt;
}
}
catch (Exception ex){
MessageBoxCustom.Show("加载数据出错:"+ex.Message);
}
return pageData.TotalCount;
}
string UserIDToName(object uid)
{
if (uid != null)
{
return UserIDToName(uid.ToString());
}
else {
return "";
}
}
public static string UserIDToName(string uid)
{
DataRow row = LYFZ.DAL.DAL_ErpUser.SimpleUserDataTable.Rows.Find(uid);
if (row != null)
{
return row["User_Name"].ToString();
}
else {
return "";
}
}
//页面加载事件
void frmMattersApply_Load(object sender, EventArgs e)
{
bool b;
this.UcNavigationTool.LabTitle = "事项审核";
switch (currentMatterRole)
{
case MattersApplyType.批示领导:
this.tpMyApplication.Text = "事项管理";
this.btnAddApplication.Visible = false;
this.btnApproving.Visible = true;
this.btndel.Visible = true;
b = LYFZ.Software.MainBusiness.VersionControl.StaticVersion.UIFunctionVersion(VersionControl.VersionFunctionEnum.店务管理事项申请);
if (!b)
{
this.Close();
return;
}
break;
case MattersApplyType.申请人:
this.UcNavigationTool.LabTitle = "事项申请";
this.tpMyApplication.Text = "事项申请";
this.btnAddApplication.Visible = true;
this.btnApproving.Visible = false;
this.btndel.Visible = true;
b = LYFZ.Software.MainBusiness.VersionControl.StaticVersion.UIFunctionVersion(VersionControl.VersionFunctionEnum.店务管理事项审批);
if (!b)
{
this.Close();
return;
}
break;
case MattersApplyType.审核人:
this.tpMyApplication.Text = "事项审核";
this.btnAddApplication.Visible = false;
this.btnApproving.Visible = true;
this.btndel.Visible = false;
b = LYFZ.Software.MainBusiness.VersionControl.StaticVersion.UIFunctionVersion(VersionControl.VersionFunctionEnum.店务管理事项管理);
if (!b)
{
this.Close();
return;
}
break;
}
ucMatt.Bind();
}
///
/// 公共刷新方法
///
public void refresh()
{
ucMatt.Bind();
}
//dgv双击事件
void dgvTaskView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
if (this.currentMatterRole == MattersApplyType.申请人 && this.currentAuditStatus != state.申请通过)
{
if (e.RowIndex >= 0 && e.ColumnIndex >= 0)
{
frmAddApply releaseApply = new frmAddApply();
releaseApply.ID = this.dgvTaskView.CurrentRow.Cells["ID"].Value.ToString();
if (releaseApply.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
ucMatt.Bind();
}
}
}
}
//关闭
void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
///
/// 删除事件
///
///
///
void btndel_Click(object sender, EventArgs e)
{
if (this.currentMatterRole == MattersApplyType.申请人 || this.currentMatterRole == MattersApplyType.批示领导)
{
if (this.currentMatterRole == MattersApplyType.申请人 && this.currentAuditStatus == state.申请通过)
{
MessageBoxCustom.Show("已通过申请事项不能删除");
return;
}
if (this.dgvTaskView.SelectedRows != null && this.dgvTaskView.SelectedRows.Count > 0)
{
if (MessageBoxCustom.Show("是否删除?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
BLL_ErpShopEvententry bll = new BLL_ErpShopEvententry();
bool ret = true;
foreach (DataGridViewRow row in this.dgvTaskView.SelectedRows)
{
if (!bll.Delete(Convert.ToInt32(row.Cells["ID"].Value.ToString())))
{
ret = false;
break;
}
}
if (ret)
{
ucMatt.Bind();
}
else
{
MessageBoxCustom.Show("删除失败");
}
}
}
else
{ MessageBoxCustom.Show("请选中信息"); }
}
else
{
MessageBoxCustom.Show("审核人只能审核申请,不能删除申请");
}
}
///
///
///
///
///
void btnApproving_Click(object sender, EventArgs e)
{
if (this.dgvTaskView.SelectedRows != null && this.dgvTaskView.SelectedRows.Count > 0)
{
frmMattersApplyView applyView = new frmMattersApplyView();
applyView.ID = dgvTaskView.CurrentRow.Cells["ID"].Value.ToString();
applyView.ApplyType = this.currentMatterRole;
if (applyView.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
ucMatt.Bind();
}
}
else
{
MessageBoxCustom.Show("请选择申请事项");
}
}
///
/// 我要申请
///
///
///
void btnAddTask_Click(object sender, EventArgs e)
{
frmAddApply releaseApply = new frmAddApply();
if (releaseApply.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
ucMatt.Bind();
}
}
}
public enum state
{
申请中=0,
申请通过=1,
申请打回=2
}
///
/// 任务关系类型 是发布人还是办理人
///
public enum MattersApplyType
{
批示领导=0,
申请人=1,
审核人=2
}
}