using LYFZ.ComponentLibrary;
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;
namespace LYFZ.Software.MainBusiness.InventoryManagement
{
public partial class FrmPurchasingManagement : LYFZ.Software.UI.InventoryManagement.FrmPurchasingManagement
{
private delegate void UpdateControl();
public FrmPurchasingManagement()
{
this.ucPagerEx1.EventPaging += ucPagerEx1_EventPaging;
}
///
/// 加载
///
///
///
protected override void FrmPurchasingManagement_Shown(object sender, EventArgs e)
{
this.btnDelete.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.PurchasingManagementCompetence, CustomAttributes.OperatingAuthority.Delete);
this.btnPurchasingManagement.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.PurchasingManagementCompetence, CustomAttributes.OperatingAuthority.PurchasingManagement);
this.btnAcceptanceManagement.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.PurchasingManagementCompetence, CustomAttributes.OperatingAuthority.AcceptanceManagement);
this.cmbPord_PurchaseStatus.Text = "全部";
this.GetPurchaseOrder();
}
///
/// 获取采购订单表
///
public void GetPurchaseOrder()
{
this.ucPagerEx1.PageCurrent = 1;
this.ucPagerEx1.PageSize = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetPageSize();//3;分页条数
this.ucPagerEx1.Bind();
}
///
/// 查询状态
///
///
///
protected override void cmbPord_PurchaseStatus_SelectedIndexChanged(object sender, EventArgs e)
{
this.GetPurchaseOrder();
}
///
/// 采购管理
///
///
///
protected override void btnPurchasingManagement_Click(object sender, EventArgs e)
{
if (dgv.SelectedRows.Count == 0)
{ MessageBoxCustom.Show("请选择采购订单!"); return; }
LYFZ.Software.MainBusiness.InventoryManagement.PurchasingManagement.FrmPurchase set = new PurchasingManagement.FrmPurchase();
set.Pord_PurchaseNumber = dgv.CurrentRow.Cells["Pord_PurchaseNumber"].Value.ToString().Trim();
if (set.ShowDialog() == DialogResult.OK)
{ this.GetPurchaseOrder(); }
}
///
/// 验收管理
///
///
///
protected override void btnAcceptanceManagement_Click(object sender, EventArgs e)
{
if (dgv.SelectedRows.Count == 0)
{ MessageBoxCustom.Show("请选择验收订单!"); return; }
LYFZ.Software.MainBusiness.InventoryManagement.PurchasingManagement.FrmAcceptanceManagement set = new PurchasingManagement.FrmAcceptanceManagement();
set.Pord_PurchaseNumber = dgv.CurrentRow.Cells["Pord_PurchaseNumber"].Value.ToString().Trim();
if (set.ShowDialog() == DialogResult.OK)
{ this.GetPurchaseOrder(); }
}
///
/// 关闭
///
///
///
protected override void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
///
/// 画分页
///
///
///
private int ucPagerEx1_EventPaging(UCPager.EventPagingArg e)
{
dgv.Rows.Clear();
DataTable dt = new DataTable();
StringBuilder str = new StringBuilder();
if (!string.IsNullOrEmpty(cmbPord_PurchaseStatus.Text))
{
if (cmbPord_PurchaseStatus.Text == "采购中")
{ str.Append("Pord_PurchaseStatus='0'"); }
else if (cmbPord_PurchaseStatus.Text == "采购完成")
{ str.Append("Pord_PurchaseStatus='1'"); }
else if (cmbPord_PurchaseStatus.Text == "采购取消")
{ str.Append("Pord_PurchaseStatus='2' "); }
else if (cmbPord_PurchaseStatus.Text == "申请中")
{ str.Append("Pord_PurchaseStatus='3' "); }
}
else
{ str.Append(" Pord_PurchaseStatus = '3' or Pord_PurchaseStatus='0'"); }
LYFZ.UCPager.PageData pageData = new LYFZ.UCPager.PageData();
LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
{
pageData.TableName = "tb_ErpPurchaseOrder";
pageData.PageIndex = this.ucPagerEx1.PageCurrent;
pageData.PageSize = this.ucPagerEx1.PageSize;
pageData.QueryCondition = str.ToString();
pageData.QueryFieldName = "ID,Pord_PurchaseNumber,Pord_PurchaseName,Pord_RequisitionName,Pord_RequisitionTime,Pord_ApprovalStatus,Pord_ApprovalName,Pord_ApprovalTime,Pord_ApprovalRemark,Pord_PurchaseStatus";
pageData.OrderStr = " ID desc ";
DataSet da = pageData.QueryDataTable();
dt = da.Tables[0];
if (dt.Rows.Count > 0)
{
this.Invoke(new UpdateControl(delegate()
{
for (int t = 0; t < dt.Rows.Count; t++)
{
DataGridViewRow dgvr = new DataGridViewRow();
DataGridViewCell cell = null;
cell = new DataGridViewTextBoxCell();
cell.Value = dt.Rows[t]["ID"].ToString().Trim();
dgvr.Cells.Add(cell);
cell = new DataGridViewTextBoxCell();
cell.Value = dt.Rows[t]["Pord_PurchaseNumber"].ToString().Trim();
dgvr.Cells.Add(cell);
cell = new DataGridViewTextBoxCell();
LYFZ.BLL.BLL_ErpUser ErpUserBll = new BLL.BLL_ErpUser();
cell.Value = ErpUserBll.GetUserName(dt.Rows[t]["Pord_RequisitionName"].ToString().Trim());
dgvr.Cells.Add(cell);
cell = new DataGridViewTextBoxCell();
cell.Value = Convert.ToDateTime(dt.Rows[t]["Pord_RequisitionTime"]).ToString("yyyy-MM-dd").Trim();
dgvr.Cells.Add(cell);
#region 采购状态
cell = new DataGridViewTextBoxCell();
if (dt.Rows[t]["Pord_PurchaseStatus"].ToString().Trim() == "0")
{
cell.Value = LYFZ.EnumPublic.Ppt_PurchaseStatus.采购中.ToString();
dgvr.DefaultCellStyle.ForeColor = Color.Orange;
}
else if (dt.Rows[t]["Pord_PurchaseStatus"].ToString().Trim() == "1")
{
cell.Value = LYFZ.EnumPublic.Ppt_PurchaseStatus.采购完成.ToString();
}
else if (dt.Rows[t]["Pord_PurchaseStatus"].ToString().Trim() == "2")
{
cell.Value = LYFZ.EnumPublic.Ppt_PurchaseStatus.采购取消.ToString();
}
else if (dt.Rows[t]["Pord_PurchaseStatus"].ToString().Trim() == "3")
{
cell.Value = LYFZ.EnumPublic.Ppt_PurchaseStatus.申请中.ToString();
dgvr.DefaultCellStyle.ForeColor = Color.Orange;
}
dgvr.Cells.Add(cell);
#endregion
this.dgv.Rows.Add(dgvr);
}
dgv.ClearSelection();
}));
}
});
try
{
this.ucPagerEx1.TbDataSource = dt;
}
catch { }
return pageData.TotalCount;
}
///
/// 删除
///
///
///
protected override void btnDelete_Click(object sender, EventArgs e)
{
if (this.dgv.SelectedRows.Count == 0)
{
MessageBoxCustom.Show("请选中你要删除的数据!");
return;
}
string Pord_PurchaseStatus = dgv.CurrentRow.Cells["Pord_PurchaseStatus"].Value.ToString();
string Pord_PurchaseNumber = dgv.CurrentRow.Cells["Pord_PurchaseNumber"].Value.ToString();
if (Pord_PurchaseStatus == "采购完成")
{
MessageBoxCustom.Show("此订单采购完成不能删除!");
return;
}
if (MessageBoxCustom.Show("此订单正在【" + Pord_PurchaseStatus + "】,你确定要删除吗?", "删除提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
if (new LYFZ.BLL.BLL_ErpPurchaseOrder().DeletePord_PurchaseNumber(Pord_PurchaseNumber) > 0)
{
string logsContent = "删除采购单订单号:" + Pord_PurchaseNumber;
LYFZ.BLL.BLL_ErpSystemLogs.WriteSystemLog(LYFZ.EnumPublic.SystemLogsType.删除采购单, logsContent, LYFZ.BLL.BLL_ErpUser.UsersModel.User_EmployeeID, LYFZ.BLL.BLL_ErpUser.UsersModel.User_Name);
MessageBoxCustom.Show("删除成功!");
GetPurchaseOrder();
}
else
{ MessageBoxCustom.Show("删除失败!"); }
}
}
}
}