using LYFZ.DAL;
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.Collections;
using System.IO;
using LYFZ.ComponentLibrary;
using LYFZ.Helper;
namespace LYFZ.Software.MainBusiness.OAShopManagement
{
public class frmTaskAssigned : LYFZ.Software.UI.OAShopManagement.frmTaskAssigned
{
string strUserID = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID;
LYFZ.BLL.BLL_ErpShopAssignmente ambll = new BLL.BLL_ErpShopAssignmente();
///
/// 当前任务状态
///
CompleteStatus currentCompleteStatus = CompleteStatus.新任务;
///
/// 任务处理人角色类型
///
TeskType currentTeskType = TeskType.办理人;
ComponentLibrary.DataGridViewEx currentTaskView = null;
public frmTaskAssigned(string Parameters)
: this()
{
if (Parameters.Trim() == TeskType.发布人.ToString())
{
currentTeskType = TeskType.发布人;
this.tbMain.TabPages.Remove(this.tpReceivingTask);
}
else
{
currentTeskType = TeskType.办理人;
this.tbMain.TabPages.Remove(this.tpPublishingTasks);
}
}
public frmTaskAssigned()
{
this.tbMain.SelectedIndexChanged += tbMain_SelectedIndexChanged;
//发布任务
this.btnAddTask.Click += btnAddTask_Click;
//任务处理
this.btnTaskSummary.Click += btnTaskSummary_Click;
this.btnReply.Click += btnReply_Click;
//删除任务
this.btndel.Click += btndel_Click;
//关闭
this.btnClose.Click += btnClose_Click;
this.dgvMyTaskView.CellDoubleClick += dgvMyTaskView_CellDoubleClick;
this.dgvTaskView.CellDoubleClick += dgvTaskView_CellDoubleClick;
this.ucPagerEx1.EventPaging += ucMyPagerEx_EventPaging;
this.ucMyPagerEx.EventPaging += ucMyPagerEx_EventPaging;
this.Load += frmTaskAssigned_Load;
if (LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.TasksAssigned, CustomAttributes.OperatingAuthority.Delete))
{
this.btndel.Enabled = true;
}
else
{
this.btndel.Enabled = false;
}
if (LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.TasksAssigned, CustomAttributes.OperatingAuthority.Add))
{
this.btnAddTask.Enabled = true;
}
else
{
this.btnAddTask.Enabled = false;
}
this.btnReply.Enabled = false;
this.rdoNewTask.Click += rdoRadioButton_Click;
this.rdoExecutionIngTask.Click += rdoRadioButton_Click;
this.rdoCompletedTask.Click += rdoRadioButton_Click;
this.rdoterminationTask.Click += rdoRadioButton_Click;
this.rdoMyNewTask.Click += rdoRadioButton_Click;
this.rdoMyExecutionIngTask.Click += rdoRadioButton_Click;
this.rdoMyCompletedTask.Click += rdoRadioButton_Click;
this.rdoMyTerminationTask.Click += rdoRadioButton_Click;
}
void btnReply_Click(object sender, EventArgs e)
{
if (this.dgvTaskView.CurrentRow != null)
{
frmTeskView frm = new frmTeskView();
frm.MyTeskType = this.currentTeskType;
frm.TeskRow = this.dgvTaskView.Rows[this.dgvTaskView.CurrentRow.Index];
if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
RefreshingBind();
}
}
else
{
MessageBoxCustom.Show("请选中你要处理的任务!");
}
}
void rdoRadioButton_Click(object sender, EventArgs e)
{
ComponentLibrary.RadioButtonEx rdoBtn = (ComponentLibrary.RadioButtonEx)sender;
if (rdoBtn.Checked)
{
this.currentCompleteStatus = (CompleteStatus)Convert.ToInt32(rdoBtn.Tag);
}
if (this.currentTeskType == TeskType.发布人)
{
if (this.currentCompleteStatus == CompleteStatus.新任务 || this.currentCompleteStatus == CompleteStatus.执行中)
{
this.btnReply.Enabled = false;
}
else {
this.btnReply.Enabled = true;
}
this.ucPagerEx1.Bind();
}
else {
this.ucMyPagerEx.Bind();
}
}
///
/// 接收任务/新任务双击列表事件
///
///
///
void dgvMyTaskView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0 && e.ColumnIndex >= 0)
{
if (this.dgvMyTaskView.CurrentRow != null)
{
frmTeskView frm1 = new frmTeskView();
frm1.MyTeskType = this.currentTeskType;
frm1.TeskRow = this.dgvMyTaskView.Rows[this.dgvMyTaskView.CurrentRow.Index];
if (frm1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
RefreshingBind();
}
}
}
}
///
/// 加载事件
///
///
///
void frmTaskAssigned_Load(object sender, EventArgs e)
{
BindData();
}
///
/// 新任务双击列表事件
///
///
///
void dgvTaskView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
if (this.dgvTaskView.Rows.Count > 0)
{
if (this.dgvTaskView.CurrentRow.Index >= 0 && this.dgvTaskView.CurrentCell.ColumnIndex >= 0)
{
if (this.dgvTaskView.CurrentRow != null)
{
if (this.currentCompleteStatus == CompleteStatus.新任务 || this.currentCompleteStatus == CompleteStatus.无法完成)
{
frmReleaseTask frm = new frmReleaseTask();
frm.TaskRow = this.dgvTaskView.Rows[this.dgvTaskView.CurrentRow.Index];
if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
RefreshingBind();
}
}
else {
MessageBoxCustom.Show("“执行中”和“已完成”的任务不可修改");
}
}
}
}
}
///
/// 关闭窗体
///
///
///
void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
///
/// 删除
///
///
///
void btndel_Click(object sender, EventArgs e)
{
try
{
if (this.dgvTaskView.CurrentRow.Index >= 0 && this.dgvTaskView.CurrentCell.ColumnIndex >= 0)
{
if (this.dgvTaskView.CurrentRow != null)
{
if (MessageBoxCustom.Show("你确定要删除吗?", "删除提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
if (ambll.Delete(ambll.GetModel(Convert.ToInt32(dgvTaskView.CurrentRow.Cells["ID"].Value))))
{
MessageBoxCustom.Show("删除成功!");
this.dgvTaskView.Rows.Remove(this.dgvTaskView.CurrentRow);
}
else
{
MessageBoxCustom.Show("删除失败!");
}
}
}
else
{
MessageBoxCustom.Show("请选中你要删除的数据!");
}
}
}
catch (Exception ex)
{
MessageBoxCustom.Show(ex.Message);
}
}
///
/// 处理任务
///
///
///
void btnTaskSummary_Click(object sender, EventArgs e)
{
if (this.dgvMyTaskView.CurrentRow != null)
{
frmTeskView frm = new frmTeskView();
frm.MyTeskType = this.currentTeskType;
frm.TeskRow = this.dgvMyTaskView.Rows[this.dgvMyTaskView.CurrentRow.Index];
if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
RefreshingBind();
}
}
else {
MessageBoxCustom.Show("请选中你要处理的任务!");
}
}
///
/// 发布
///
///
///
void btnAddTask_Click(object sender, EventArgs e)
{
frmReleaseTask frm = new frmReleaseTask();
if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
RefreshingBind();
}
}
///
/// 绑定数据
///
///
private void ucPagerExBind(UCPager.ucPagerEx ucPager)
{
if (currentTeskType == TeskType.发布人)
{
this.currentTaskView = this.dgvTaskView;
}
else {
this.currentTaskView = this.dgvMyTaskView;
}
ucPager.PageCurrent = 1;
ucPager.PageSize = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetPageSize();//3;分页条数
ucPager.Bind();
}
///
/// 画分页1
///
///
///
private int ucMyPagerEx_EventPaging(UCPager.EventPagingArg e)
{
string filterName = "Agt_ManageName";
LYFZ.UCPager.PageData pageData = new LYFZ.UCPager.PageData();
if (this.currentTeskType == TeskType.发布人)
{
filterName = "Agt_PublishName";
pageData.PageIndex = this.ucPagerEx1.PageCurrent;
pageData.PageSize = this.ucPagerEx1.PageSize;
}
else {
filterName = "Agt_ManageName";
pageData.PageIndex = this.ucMyPagerEx.PageCurrent;
pageData.PageSize = this.ucMyPagerEx.PageSize;
}
pageData.TableName = "tb_ErpShopAssignmente";//表名
pageData.QueryCondition = filterName + "='" + strUserID + "' and Agt_CompleteStatus = '" + ((int)this.currentCompleteStatus).ToString() + "'";//查询条件
pageData.QueryFieldName = "ID,Agt_Priority,Agt_PublishName,Agt_PublishTime,Agt_Content,Agt_ManageName,Agt_CompleteTime,Agt_CompleteStatus,Agt_Summary,Agt_Revert,Agt_TaskTopic,Agt_Deadlines";//查询字段
pageData.OrderStr = "ID";
pageData.OrderType = 1;
DataTable dt = new DataTable();
LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
{
dt = pageData.QueryDataTable().Tables[0];
});
try
{
this.currentTaskView.Rows.Clear();
for (int i = 0; i < dt.Rows.Count; i++)
{
DataGridViewRow row1 = new DataGridViewRow();
row1.CreateCells(this.currentTaskView);
row1.Cells[0].Value = dt.Rows[i]["ID"].ToString();
string Agt_TaskTopic = "无主题";
if (dt.Rows[i]["Agt_TaskTopic"] != null && !string.IsNullOrEmpty(dt.Rows[i]["Agt_TaskTopic"].ToString().Trim()))
{
Agt_TaskTopic = dt.Rows[i]["Agt_TaskTopic"].ToString();
}
row1.Cells[1].Value = Agt_TaskTopic;
row1.Cells[2].Value = dt.Rows[i]["Agt_Content"].ToString();
row1.Cells[3].Value = ((Priority)Convert.ToInt32(dt.Rows[i]["Agt_Priority"])).ToString();
row1.Cells[4].Value = LYFZ.DAL.DAL_ErpUser.SimpleUserDataTable.Rows.Find(dt.Rows[i]["Agt_PublishName"].ToString())["User_Name"].ToString().Trim();
row1.Cells[5].Value = LYFZ.Command.Command_Validate.DateTimeToString(dt.Rows[i]["Agt_PublishTime"], "yyyy-MM-dd HH:mm");
string Agt_ManageName = "";
DataRow dtRow = LYFZ.DAL.DAL_ErpUser.SimpleUserDataTable.Rows.Find(dt.Rows[i]["Agt_ManageName"].ToString());
if (dtRow != null)
{
Agt_ManageName = dtRow["User_Name"].ToString().Trim();
}
row1.Cells[6].Value = Agt_ManageName;
row1.Cells[6].Tag = dt.Rows[i]["Agt_ManageName"].ToString();
row1.Cells[7].Value = LYFZ.Command.Command_Validate.DateTimeToString(dt.Rows[i]["Agt_Deadlines"], "yyyy-MM-dd HH:mm");
row1.Cells[8].Value = ((CompleteStatus)Convert.ToInt32(dt.Rows[i]["Agt_CompleteStatus"])).ToString();
row1.Cells[9].Value = LYFZ.Command.Command_Validate.DateTimeToString(dt.Rows[i]["Agt_CompleteTime"], "yyyy-MM-dd HH:mm");
row1.Cells[10].Value = dt.Rows[i]["Agt_Summary"].ToString();//任务总结
row1.Cells[11].Value = dt.Rows[i]["Agt_Revert"].ToString();//发布人回复
this.currentTaskView.Rows.Add(row1);
}
}
catch (Exception ex)
{
MessageBoxCustom.Show("绑定数据时出错:" + ex.Message);
}
try
{
e.CurrentPager.TbDataSource = dt;
}
catch { }
this.currentTaskView.ClearSelection();
return pageData.TotalCount;
}
void RefreshingBind()
{
if (this.currentTeskType == TeskType.发布人)
{
ucPagerExBind(this.ucPagerEx1);
}
else {
ucPagerExBind(this.ucMyPagerEx);
}
}
// private delegate void UpdateControl();
///
/// 选项卡
///
///
///
void tbMain_SelectedIndexChanged(object sender, EventArgs e)
{
switch (this.tbMain.SelectedIndex)
{
case 0:
this.currentTeskType = TeskType.发布人;
break;
case 1:
this.currentTeskType = TeskType.办理人;
break;
}
BindData();
}
void BindData()
{
bool b;
if (this.currentTeskType == TeskType.发布人)
{
b = LYFZ.Software.MainBusiness.VersionControl.StaticVersion.UIFunctionVersion(VersionControl.VersionFunctionEnum.店务管理发布任务);
if (!b)
{
this.Close();
return;
}
ucPagerExBind(this.ucPagerEx1);
}
else {
b = LYFZ.Software.MainBusiness.VersionControl.StaticVersion.UIFunctionVersion(VersionControl.VersionFunctionEnum.店务管理我的任务);
if (!b)
{
this.Close();
return;
}
ucPagerExBind(this.ucMyPagerEx);
}
}
public enum CompleteStatus
{
新任务 = 0,
执行中 = 1,
已完成 = 2,
无法完成 = 3
}
public enum Priority
{
高 = 0,
中 = 1,
低 = 2
}
}
}