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 Core.Mes.Client.Comm.Server;
using Core.Mes.Client.Comm.Control;
using Infragistics.Win.UltraWinGrid;
using Core.Mes.Client.Comm.Format;
using System.Collections;
using Core.Mes.Client.Comm.Tool;
namespace Core.StlMes.Client.SaleOrder.Dialog
{
public partial class frmOrderPriceDetails : FrmBase
{
///
/// 合同号
///
private String ordPk;
public String OrdPk
{
get { return ordPk; }
set { ordPk = value; }
}
private OpeBase ob;
public OpeBase Ob
{
get { return ob; }
set { ob = value; }
}
public frmOrderPriceDetails()
{
InitializeComponent();
}
private void frmOrderPriceDetails_Load(object sender, EventArgs e)
{
EntityHelper.ShowGridCaption(ultraGrid1.DisplayLayout.Bands[0]);
setColumnsReadOnly();
DoQuery();
}
private void setColumnsReadOnly()
{
foreach (UltraGridColumn ugc in ultraGrid1.DisplayLayout.Bands[0].Columns)
{
if (!ugc.Key.Equals("CHC"))
{
ugc.CellActivation = Activation.ActivateOnly;
}
}
}
private void ultraToolbarsManager1_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
{
switch (e.Tool.Key)
{
case "Save":
DoSave();
break;
case "Cancel":
DoCancel();
break;
case "Commit":
DoCommit();
break;
case "Close":
this.Close();
break;
default:
break;
}
}
private void DoQuery()
{
if (ordPk.Length == 0)
{
return;
}
List listSource = EntityHelper.GetData(
"com.steering.pss.sale.order.CoreOrderPriceDetails.getOrdLineByOrdPk", new object[] { ordPk }, ob);
slmOrderLineEntityBindingSource.DataSource = listSource;
}
private void DoSave()
{
ultraGrid1.UpdateData();
IQueryable ultraGrid1CheckedRows = ultraGrid1.Rows.AsQueryable().Where(" CHC = 'True'");
if (ultraGrid1CheckedRows.Count() == 0)
{
MessageUtil.ShowWarning("请选择合同行");
return;
}
String priceBase = textBox1.Text.Trim();
if (priceBase.Length == 0)
{
MessageUtil.ShowWarning("请填写定价内容");
return;
}
String jsPrice = txtJsPrice.Value == null ? "" : txtJsPrice.Value.ToString().Trim();
String ccPrice = txtCcPrice.Value == null ? "" : txtCcPrice.Value.ToString().Trim();
String dzPrice = txtDzfPrice.Value == null ? "" : txtDzfPrice.Value.ToString().Trim();
String yfPrice = txtYfPrice.Value == null ? "" : txtYfPrice.Value.ToString().Trim();
if (jsPrice.Equals("") || ccPrice.Equals(""))
{
MessageUtil.ShowWarning("请填写出厂价/结算价");
return;
}
//合同头状态
if (MessageUtil.ShowYesNoAndQuestion("是否保存定价信息") == DialogResult.No)
{
return;
}
String[] statuses = getOrderHeadStatus(ordPk);
if (statuses == null)
{
MessageUtil.ShowWarning("合同状态异常,不能维护定价");
return;
}
String status = statuses[0];
ArrayList list = new ArrayList() { "12020212", "12020213", "12020221", "12020223", "12020231", "12020241" };
if (list.Contains(status))
{
ArrayList listStr = new ArrayList();
String ordLnPk = "";
foreach (UltraGridRow ugr in ultraGrid1CheckedRows)
{
SlmOrderLineEntity orderLineEntity = (SlmOrderLineEntity)ugr.ListObject;
orderLineEntity.TrsPrice = yfPrice;
orderLineEntity.BlaPrice = jsPrice;
orderLineEntity.OutPrice = ccPrice;
orderLineEntity.PakPrice = dzPrice;
ordLnPk = orderLineEntity.OrdLnPk.ToString();
orderLineEntity.OrderAddDesc = "";
orderLineEntity.OrderSpecialDesc = "";
string strJSON = JSONFormat.Format(orderLineEntity);
listStr.Add(strJSON);
}
string saleOrg = ClsBaseInfo.GetSaleOrg(UserInfo.GetDeptid());
CoreClientParam ccp = new CoreClientParam();
ccp.ServerName = "com.steering.pss.sale.order.CoreOrderPriceDetails";
ccp.MethodName = "savePrice";
ccp.ServerParams = new object[] { listStr, ordPk, priceBase, UserInfo.GetUserName(), saleOrg };
ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
if (ccp.ReturnCode == -1)
{
return;
}
MessageUtil.ShowTips("保存成功!");
DoQuery();
activeRow(ultraGrid1, ordLnPk);
}
else
{
MessageUtil.ShowWarning("合同已审批,不能定价维护");
return;
}
}
private void DoCancel()
{
ultraGrid1.UpdateData();
IQueryable ultraGrid1CheckedRows = ultraGrid1.Rows.AsQueryable().Where(" CHC = 'True'");
if (MessageUtil.ShowYesNoAndQuestion("是否撤销对此合同定价维护!") == DialogResult.No)
{
return;
}
String[] statuses = getOrderHeadStatus(ordPk);
if (statuses == null)
{
MessageUtil.ShowWarning("合同状态异常,不能撤销合同定价");
return;
}
String status = statuses[0];
{
if (status.Equals("12020220"))
{
MessageUtil.ShowWarning("合同已经审批,不能撤销合同定价");
return;
}
}
ArrayList listStr = new ArrayList();
String ordLnPk = "";
foreach (UltraGridRow ugr in ultraGrid1CheckedRows)
{
SlmOrderLineEntity orderLineEntity = (SlmOrderLineEntity)ugr.ListObject;
orderLineEntity.TrsPrice = txtYfPrice.Value.ToString().Trim();
orderLineEntity.BlaPrice = txtJsPrice.Value.ToString().Trim();
orderLineEntity.OutPrice = txtCcPrice.Value.ToString().Trim();
orderLineEntity.PakPrice = txtDzfPrice.Value.ToString().Trim();
ordLnPk = orderLineEntity.OrdLnPk.ToString();
orderLineEntity.OrderAddDesc = "";
orderLineEntity.OrderSpecialDesc = "";
string strJSON = JSONFormat.Format(orderLineEntity);
listStr.Add(strJSON);
}
CoreClientParam ccp = new CoreClientParam();
ccp.ServerName = "com.steering.pss.sale.order.CoreOrderPriceDetails";
ccp.MethodName = "cancelPriceNo";
ccp.ServerParams = new object[] { listStr, ordPk };
ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
if (ccp.ReturnCode == -1)
{
return;
}
MessageUtil.ShowTips("撤销成功!");
DoQuery();
activeRow(ultraGrid1, ordLnPk);
}
private void DoCommit()
{
if (MessageUtil.ShowYesNoAndQuestion("是否提交") == DialogResult.No)
{
return;
}
if (!checkPriceComplete(ordPk))
{
MessageUtil.ShowWarning("定价信息没有维护完整,不能提交");
return;
}
this.Close();
}
///
/// 查询合同头状态/定价编号 2015/06/18
///
/// 合同头号
///
private String[] getOrderHeadStatus(String ordPk)
{
String[] status = null;
DataTable dt = ServerHelper.GetData("com.steering.pss.sale.order.CopyOrderApproval.getOrdPkStatus", new Object[] { ordPk }, ob);
if (dt != null && dt.Rows.Count > 0)
{
status = new String[2];
status[0] = dt.Rows[0][0].ToString();
status[1] = dt.Rows[0][1].ToString();
}
return status;
}
///
/// 查询定价内容
///
///
///
private String getPriceBase()
{
DataTable dt = ServerHelper.GetData("com.steering.pss.sale.order.CoreOrderPriceDetails.getPriceBase", new Object[] { ordPk }, ob);
if (dt != null && dt.Rows.Count > 0)
{
return dt.Rows[0][0].ToString();
}
else
{
return "";
}
}
private void ultraGrid1_AfterRowActivate(object sender, EventArgs e)
{
ultraGrid1.UpdateData();
UltraGridRow ugr = ultraGrid1.ActiveRow;
if (ugr != null)
{
String priceBase = getPriceBase();
textBox1.Text = priceBase;
txtYfPrice.Value = ugr.Cells["TrsPrice"].Value;
txtJsPrice.Value = ugr.Cells["BlaPrice"].Value;
txtCcPrice.Value = ugr.Cells["OutPrice"].Value;
txtDzfPrice.Value = ugr.Cells["PakPrice"].Value;
}
}
private void frmOrderPriceDetails_FormClosing(object sender, FormClosingEventArgs e)
{
if (!checkPriceComplete(ordPk))
{
if (MessageUtil.ShowYesNoAndQuestion("合同定价维护不完整,是否退出") == DialogResult.No)
{
e.Cancel = true;
}
}
}
///
/// 验证合同头是否存在订价编号
///
///
///
private Boolean checkPriceComplete(String ordPk)
{
if (ordPk.Length == 0)
{
return false;
}
DataTable dt = ServerHelper.GetData("com.steering.pss.sale.order.CoreOrderPriceDetails.getOrdHeadPriceNo", new Object[] { ordPk }, ob);
if (dt != null && dt.Rows.Count > 0)
{
String str = dt.Rows[0][0].ToString();
if (str.Length > 0)
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
private void activeRow(UltraGrid ug, String value)
{
foreach (UltraGridRow ugr in ug.Rows)
{
if (ugr.Cells["OrdLnPk"].Value.ToString().Equals(value))
{
ugr.Activate();
}
}
}
}
}