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 CoreFS.CA06;using Pur.Entity;using Pur.Entity;
using Pur.Entity.pur_planEntity;
using Core.Mes.Client.Comm.Tool;
using Core.Mes.Client.Comm.Control;
using System.Collections;
using Pur.Entity.configureEntity;
using com.hnshituo.pur.vo;
namespace Pur.Pop_upWindow
{
public partial class FrmPop_GetMinPrice : FrmPmsBase
{
string Q_strTASKID = "";
DataTable Q_dtMinPrice = null;//保存显示最低价格供应商
public FrmPop_GetMinPrice(OpeBase ob, string strTASKID, DataTable dt)
{
InitializeComponent();
this.ob = ob;
Q_strTASKID = strTASKID;
GetMinPrice(dt);
GetTaskM(strTASKID);
//ultraGrid1.DataSource = dt;
}
///
/// 查询任务主表
///
public void GetTaskM(string strTASKID)
{
PurTaskMEntity M_PurTaskM = this.execute("com.hnshituo.pur.purplan.service.TaskMService", "findById", new object[] { strTASKID });
if (M_PurTaskM != null)
{
lb_taskId.Text = M_PurTaskM.TaskId;
lb_taskName.Text = M_PurTaskM.TaskName;
if (M_PurTaskM.OfferTimeStart.Value != null)
lb_OFFER_TIME_START.Text = M_PurTaskM.OfferTimeStart.Value.ToShortDateString();
if (M_PurTaskM.OfferTimeEnd.Value != null)
lb_OFFER_TIME_END.Text = M_PurTaskM.OfferTimeEnd.Value.ToShortDateString();
}
}
///
/// 初拟最低价格
///
/// 竞标价格表
public void GetMinPrice(DataTable dt)
{
Q_dtMinPrice = new DataTable();
DataColumn dcItem = new System.Data.DataColumn();
dcItem.ColumnName = "ITEM";
dcItem.Caption = "物料信息";
Q_dtMinPrice.Columns.Add(dcItem);
DataColumn dcSupp = new System.Data.DataColumn();
dcSupp.ColumnName = "Supp";
dcSupp.Caption = "最低报价供应商";
Q_dtMinPrice.Columns.Add(dcSupp);
int ItemCount = dt.Rows.Count / 6;//供应商个数
for (int i = 0; i < ItemCount; i++)
{
double minPrice = 0;//最小价格供应商单价
string strMinPriceSuppCode = "";//最小价格供应商代码
string strMinPriceSuppName = "";//最小价格供应商名称
for (int j = 1; j < dt.Columns.Count; j++)//比较每个供应商报价
{
if (dt.Rows[i * 6 + 1][j] != null && dt.Rows[i * 6 + 1][j].ToString().Trim() != "")
{
double suppPrice = double.Parse(dt.Rows[i * 6 + 1][j].ToString());
if (minPrice == 0 && suppPrice > 0)
{
minPrice = suppPrice;
}
if (suppPrice <= minPrice)
{
minPrice = suppPrice;
strMinPriceSuppCode = dt.Columns[j].ColumnName;
strMinPriceSuppName = dt.Columns[j].Caption;
}
}
}
for (int k = 0; k < 3; k++)//保存每个物料对应的最低供应商报价信息
{
if (k == 0)
{
DataRow dr = Q_dtMinPrice.NewRow();
dr["ITEM"] = dt.Rows[i * 6 + k]["ITEM"].ToString();//物料名
if (minPrice > 0)
{
dr["Supp"] = strMinPriceSuppName + "(" + strMinPriceSuppCode + ")";//供应商名称
}
else
{
dr["Supp"] = "";//供应商价格
}
Q_dtMinPrice.Rows.Add(dr);
}
else if (k == 1)
{
DataRow dr = Q_dtMinPrice.NewRow();
dr["ITEM"] = dt.Rows[i * 6 + k]["ITEM"].ToString();//物料名价格
if (minPrice > 0)
{
dr["Supp"] = minPrice.ToString();//供应商价格
}
else
{
dr["Supp"] = "";
}
Q_dtMinPrice.Rows.Add(dr);
}
else
{
DataRow dr = Q_dtMinPrice.NewRow();
dr["ITEM"] = dt.Rows[i * 6 + 5]["ITEM"].ToString();//物料名价格
dr["Supp"] = "";
Q_dtMinPrice.Rows.Add(dr);
}
}
}
Q_dtMinPrice = dt;
ultraGrid1.DataSource = dt;
//给物料名称行设置背景颜色
for (int i = 0; i < dt.Rows.Count / 3; i++)
{
for (int j = 0; j < 3; j++)//设置物料信第一列所有单元格背景颜色
{
if (j != 0)
{
ultraGrid1.Rows[i * 3 + j].Cells[0].Appearance.FontData.Bold = Infragistics.Win.DefaultableBoolean.True;
ultraGrid1.Rows[i * 3 + j].Cells[0].Appearance.BackColor = Color.YellowGreen;
ultraGrid1.Rows[i * 3 + j].Cells[0].Appearance.ForeColor = Color.Black;
}
}
//物料名所在行背景颜色
ultraGrid1.Rows[i * 3].Appearance.FontData.Bold = Infragistics.Win.DefaultableBoolean.True;
ultraGrid1.Rows[i * 3].Appearance.ForeColor = Color.White;
ultraGrid1.Rows[i * 3].Appearance.BorderColor3DBase = Color.CornflowerBlue;
ultraGrid1.Rows[i * 3].Appearance.BackColor = Color.DodgerBlue;
}
}
///
/// 确认操作
///
///
///
private void conFirmation()
{
// 查询任务从表
ultraGrid1.UpdateData();
PurTaskCEntity M_PurTaskC = new PurTaskCEntity();
M_PurTaskC.TaskId = Q_strTASKID;
M_PurTaskC.Validflag = "1";
DataTable dt = this.execute("com.hnshituo.pur.purplan.service.TaskCService", "find", new object[] { M_PurTaskC, 0, 0 });
ArrayList al = new ArrayList();
for (int i = 0; i < dt.Rows.Count; i++)
{
for (int j = 0; j < Q_dtMinPrice.Rows.Count; j++)
{
PurTaskCEntity M_PurTaskC_al = new PurTaskCEntity();
M_PurTaskC_al.TaskId = Q_strTASKID;
M_PurTaskC_al.Validflag = "1";
string str = Q_dtMinPrice.Rows[j]["ITEM"].ToString();
if (dt.Rows[i]["ITEMCODE"].ToString() == str.Substring(str.LastIndexOf(":") + 1) && str.IndexOf("备") != 0)//任务单对应物料
{
M_PurTaskC_al.TaskLineId = dt.Rows[i]["TASKLINEID"].ToString();
if (Q_dtMinPrice.Rows[j][1] != null && Q_dtMinPrice.Rows[j][1].ToString() != "")//中标价
{
double db = 0;
double.TryParse(Q_dtMinPrice.Rows[j+1][1].ToString(), out db);
M_PurTaskC_al.BidPrice = db;
}
else
{
M_PurTaskC_al.BidPrice = null;
}
if (Q_dtMinPrice.Rows[j + 2][1] != null)
{
M_PurTaskC_al.BidPriceReason = Q_dtMinPrice.Rows[j + 2][1].ToString();//中标价理由
}
al.Add(M_PurTaskC_al);
break;
}
}
}
if (al.Count > 0)
{
CoreResult crt = this.execute("com.hnshituo.pur.purplan.service.TaskCService", "UpdMinPrice", new object[] { al });
if (crt.Resultcode != 0)
{
MessageUtil.ShowTips("提交失败 " + crt.Resultmsg);
return;
}
MessageUtil.ShowTips("提交成功");
this.Close();
}
}
///
/// 按钮控件
///
///
///
private void barsManagerButon_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
{
switch (e.Tool.Key.ToString())
{
case "Query":
{
}
break;
case "conFirmation":
{
conFirmation();
}
break;
case "ESC":
{
this.Close();
}
break;
}
}
}
}