667 lines
33 KiB
C#
667 lines
33 KiB
C#
using BLL;
|
||
using Model;
|
||
using Newtonsoft.Json.Linq;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Data;
|
||
using System.Data.SqlClient;
|
||
using System.Linq;
|
||
using System.Linq.Expressions;
|
||
using System.Text.RegularExpressions;
|
||
using System.Web;
|
||
using System.Web.UI;
|
||
using System.Web.UI.WebControls;
|
||
|
||
namespace FineUIPro.Web.CCP
|
||
{
|
||
public partial class CcpEdit : PageBase
|
||
{
|
||
protected void Page_Load(object sender, EventArgs e)
|
||
{
|
||
if (!IsPostBack)
|
||
{
|
||
hidCcpId.Text = Request.Params["CcpId"] != null ? Request.Params["CcpId"].ToString() : string.Empty;
|
||
hidContractNo.Text = Request.Params["contractNo"] != null ? Request.Params["contractNo"].ToString() : string.Empty;
|
||
var contractNos = from contractNo in Funs.DB.FC_SESRelatedData
|
||
join cpt in Funs.DB.CPTList on contractNo.FO_NO equals cpt.Contract_No
|
||
group contractNo by contractNo.FO_NO into g
|
||
select g.Key;
|
||
if (contractNos.Count() == 0)
|
||
{
|
||
Grid1.DataSource = null;
|
||
Grid1.DataBind();
|
||
return;
|
||
}
|
||
ddlContractNo.DataTextField = "FO_NO";
|
||
ddlContractNo.DataValueField = "FO_NO";
|
||
ddlContractNo.DataSource = contractNos.ToList();
|
||
ddlContractNo.DataBind();
|
||
//Funs.FineUIPleaseSelect(ddlContractNo);
|
||
ddlContractNo.SelectedValue = contractNos.FirstOrDefault();
|
||
|
||
BindGrid();
|
||
}
|
||
}
|
||
|
||
#region 绑定数据
|
||
/// <summary>
|
||
/// 绑定CPTlist
|
||
/// </summary>
|
||
private void BindGrid()
|
||
{
|
||
if (string.IsNullOrWhiteSpace(ddlContractNo.SelectedValue))
|
||
{
|
||
Alert.ShowInParent("必须选择一个合同号!");
|
||
return;
|
||
}
|
||
|
||
var ccpNo = string.Empty;
|
||
|
||
int ccpId = 0;
|
||
var upCptLs = new List<CCP_List>();
|
||
string strSql = @"SELECT cpt.ID,cpt.CPT_No,cpt.Contract_No,cpt.Tax,
|
||
(cpt.ContractorEng+' '+cpt.ContractorCN) AS Contractor,
|
||
cpt.FC_Desctription,cpt.Report_Date,ps.PriceScheme,
|
||
cpt.FC_Start_Date,cpt.FC_End_Date,u.UserName
|
||
FROM dbo.CPTList cpt
|
||
LEFT JOIN dbo.Base_PriceScheme ps ON ps.PriceSchemeId=cpt.FC_Price_Scheme
|
||
LEFT JOIN dbo.Sys_User u ON u.UserId = cpt.UserId
|
||
WHERE 1=1";
|
||
|
||
List<SqlParameter> listStr = new List<SqlParameter>();
|
||
|
||
if (!string.IsNullOrEmpty(hidCcpId.Text))
|
||
{
|
||
strSql = strSql + " AND cpt.Contract_No=@Contract_No";
|
||
listStr.Add(new SqlParameter("@Contract_No", hidContractNo.Text));
|
||
}
|
||
else
|
||
{
|
||
if (!string.IsNullOrEmpty(ddlContractNo.SelectedValue) && ddlContractNo.SelectedValue != Const._Null)
|
||
{
|
||
strSql = strSql + " AND cpt.Contract_No=@Contract_No";
|
||
listStr.Add(new SqlParameter("@Contract_No", ddlContractNo.SelectedValue.Trim()));
|
||
}
|
||
}
|
||
if (!string.IsNullOrEmpty(txtCPT_No.Text))
|
||
{
|
||
strSql = strSql + " AND cpt.CPT_No=@CPT_No";
|
||
listStr.Add(new SqlParameter("@CPT_No", txtCPT_No.Text));
|
||
}
|
||
//添加的时候隐藏已经选择的cpt
|
||
if (string.IsNullOrEmpty(hidCcpId.Text))
|
||
{
|
||
var adCptLs = Funs.DB.CCP_List.Select(p => p.CPT_Id).ToList();
|
||
if (adCptLs.Count > 0)
|
||
{
|
||
var idstr = string.Format("'{0}'", string.Join("','", string.Join(",", adCptLs).Split(',')));
|
||
strSql += string.Format(" and cpt.ID not in ({0})", idstr);
|
||
}
|
||
var itemContractNo = string.IsNullOrEmpty(hidContractNo.Text) ? ddlContractNo.SelectedValue : hidContractNo.Text;
|
||
if (Funs.DB.CCP_List.Count(p => p.Contract_No == itemContractNo) > 0)
|
||
{
|
||
txtCcpNo.Text = string.Format("{0:d3}", Funs.DB.CCP_List.Where(p => p.Contract_No == itemContractNo).Max(p => p.CCP_No) + 1);
|
||
}
|
||
else
|
||
{
|
||
txtCcpNo.Text = string.Format("{0:d3}", 1);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
ccpId = int.Parse(hidCcpId.Text);
|
||
upCptLs = Funs.DB.CCP_List.Where(p => p.Contract_No == hidContractNo.Text).ToList();
|
||
if (upCptLs.Count > 0)
|
||
{
|
||
var itemCpt = upCptLs.Where(p => p.ID != ccpId).ToList();
|
||
if (itemCpt.Count > 0)
|
||
{
|
||
var idstr = string.Format("'{0}'", string.Join("','", string.Join(",", itemCpt.Select(p => p.CPT_Id)).Split(',')));
|
||
strSql += string.Format(" and cpt.ID not in ({0})", idstr);
|
||
}
|
||
ddlContractNo.SelectedValue = upCptLs.FirstOrDefault().Contract_No;
|
||
ddlContractNo.Enabled = false;
|
||
|
||
txtCcpNo.Text = string.Format("{0:d3}", upCptLs.FirstOrDefault(p => p.ID == ccpId).CCP_No);
|
||
}
|
||
else
|
||
{
|
||
txtCcpNo.Text = string.Format("{0:d3}", 1);
|
||
}
|
||
}
|
||
|
||
strSql = strSql + " ORDER BY cpt.Contract_No ASC";
|
||
SqlParameter[] parameter = listStr.ToArray();
|
||
|
||
DataTable dt = SQLHelper.GetDataTableRunText(strSql, parameter);
|
||
//Grid1.RecordCount = dt.Rows.Count;
|
||
//var table = this.GetPagedDataTable(Grid1, dt);
|
||
//Grid1.DataSource = table;
|
||
Grid1.DataSource = dt;
|
||
Grid1.DataBind();
|
||
//修改获取ses
|
||
if (!string.IsNullOrEmpty(hidCcpId.Text))
|
||
{
|
||
var ccpModel = upCptLs.FirstOrDefault(p => p.ID == ccpId);
|
||
if (ccpModel != null)
|
||
{
|
||
if (!string.IsNullOrEmpty(ccpModel.Payment_Term)) ddlPaymentTerm.SelectedValue = ccpModel.Payment_Term;
|
||
if (ccpModel.DeductionDeductionRateType != null) ddlDeductionDeductionRate.SelectedValue = ccpModel.DeductionDeductionRateType.ToString();
|
||
if (ccpModel.DelayedDeductionType != null) ddlDelayedDeduction.SelectedValue = ccpModel.DelayedDeductionType.ToString();
|
||
|
||
var cptls = Array.ConvertAll(ccpModel.CPT_Id.Split(','), p => int.TryParse(p, out int s) ? s : 0);
|
||
var cptNos = dt.AsEnumerable().Where(p => cptls.Contains(p.Field<int>("ID"))).Select(p => p.Field<string>("CPT_No")).Distinct().ToList();
|
||
BindGrid1(cptNos);
|
||
|
||
List<int> selectedLs = new List<int>();
|
||
var selectedCptIds = Array.ConvertAll(ccpModel.CPT_Id.Split(','), p => int.TryParse(p, out int s) ? s : 0);
|
||
for (int i = 0; i < Grid1.Rows.Count; i++)
|
||
{
|
||
int rowCptId = Convert.ToInt32(Grid1.DataKeys[i][0]);
|
||
//选中列
|
||
if (selectedCptIds.Contains(rowCptId)) selectedLs.Add(i);
|
||
}
|
||
Grid1.SelectedRowIndexArray = selectedLs.ToArray();
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 绑定SESList
|
||
/// </summary>
|
||
private void BindGrid1(List<string> cptNos)
|
||
{
|
||
if (cptNos.Count > 0)
|
||
{
|
||
string strSql = @"SELECT a.ID,a.SES,a.CPT_No,a.Requistioner,a.Short_Description,a.End_Date,
|
||
a.Budget,a.Quotation,a.Net_Value,a.Tax_Value,a.Deviation,a.By_Perc,
|
||
a.Deduction,ISNULL(c.Con_Days,a.Con_Days) as Con_Days,a.BoQ_Days,a.SES_Days,
|
||
a.Submit_Date,a.Remark,a.UserId,b.ContractorCN+' '+b.ContractorEng as ContractorName,
|
||
b.Contract_No,c.ThirdParty_PriceReview
|
||
FROM dbo.SESList as a
|
||
inner join CPTList as b on a.CPT_No=b.CPT_No
|
||
left join CCP_SESList as c on c.Ses_No=a.SES
|
||
WHERE a.CPT_No in ('{0}') ";
|
||
|
||
strSql = string.Format(strSql, string.Join("','", cptNos.ToArray()));
|
||
|
||
List<SqlParameter> listStr = new List<SqlParameter>();
|
||
SqlParameter[] parameter = listStr.ToArray();
|
||
|
||
DataTable dt = SQLHelper.GetDataTableRunText(strSql, parameter);
|
||
Grid2.RecordCount = dt.Rows.Count;
|
||
Grid2.DataSource = dt;
|
||
Grid2.DataBind();
|
||
|
||
JObject summary = new JObject();
|
||
summary.Add("Quotation", dt.AsEnumerable().Sum(s => s.Field<decimal>("Quotation")).ToString("#,##0.00"));
|
||
summary.Add("Tax_Value", dt.AsEnumerable().Sum(s => s.Field<decimal>("Tax_Value")).ToString("#,##0.00"));
|
||
|
||
summary.Add("Reduction", 0.00);
|
||
summary.Add("DeductionDeduction_Rate", 0.00);
|
||
summary.Add("DelayedDeduction", 0.00);
|
||
summary.Add("Final_SettlementAmount", 0.00);
|
||
Grid2.SummaryData = summary;
|
||
}
|
||
else
|
||
{
|
||
Grid2.DataSource = null;
|
||
Grid2.DataBind();
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 关闭弹出窗口
|
||
/// <summary>
|
||
/// 关闭窗口
|
||
/// </summary>
|
||
protected void Window1_Close(object sender, EventArgs e)
|
||
{
|
||
BindGrid();
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 排序
|
||
|
||
/// <summary>
|
||
/// 排序
|
||
/// </summary>
|
||
protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e)
|
||
{
|
||
Grid1.SortDirection = e.SortDirection;
|
||
Grid1.SortField = e.SortField;
|
||
BindGrid();
|
||
}
|
||
#endregion
|
||
|
||
#region 搜索
|
||
/// <summary>
|
||
/// 搜索
|
||
/// </summary>
|
||
protected void btnSearch_Click(object sender, EventArgs e)
|
||
{
|
||
BindGrid();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 合同号筛选
|
||
/// </summary>
|
||
protected void ddlContractNo_SelectedIndexChanged(object sender, EventArgs e)
|
||
{
|
||
BindGrid();
|
||
}
|
||
#endregion
|
||
|
||
#region 选择加载
|
||
|
||
/// <summary>
|
||
/// 选择加载
|
||
/// </summary>
|
||
protected void Grid1_RowClick(object sender, GridRowClickEventArgs e)
|
||
{
|
||
//判断选中的行中是否存在不同的合同
|
||
var cptNos = new List<string>();
|
||
var cptTaxs = new List<string>();
|
||
int[] selections = Grid1.SelectedRowIndexArray;
|
||
|
||
foreach (int rowIndex in selections)
|
||
{
|
||
cptNos.Add(Grid1.DataKeys[rowIndex][1].ToString());
|
||
cptTaxs.Add(Grid1.DataKeys[rowIndex][3].ToString());
|
||
}
|
||
//判断选中的合同是否是同一个合同
|
||
if (cptNos.Select(p => p.Substring(0, p.LastIndexOf("-"))).Distinct().Count() > 1)
|
||
{
|
||
Grid1.ClearSelection();
|
||
Alert.ShowInParent("不同合同的CPT不允许创建CCP!");
|
||
return;
|
||
}
|
||
else
|
||
{
|
||
if (cptTaxs.Distinct().Count() > 1)
|
||
{
|
||
Grid1.ClearSelection();
|
||
Alert.ShowInParent("不同税率的CPT不允许创建CCP!");
|
||
return;
|
||
}
|
||
}
|
||
|
||
BindGrid1(cptNos);
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 保存
|
||
|
||
/// <summary>
|
||
/// 保存
|
||
/// </summary>
|
||
protected void btnSave_Click(object sender, EventArgs e)
|
||
{
|
||
//判断必须选择一行
|
||
if (Grid1.SelectedRowIndexArray.Length == 0)
|
||
{
|
||
Alert.ShowInParent("Please select at least one record!");
|
||
return;
|
||
}
|
||
//判断付款条件是否选择
|
||
if (string.IsNullOrWhiteSpace(ddlPaymentTerm.SelectedValue))
|
||
{
|
||
Alert.ShowInParent("请选择付款条件!");
|
||
return;
|
||
}
|
||
//判断CCP是否填写
|
||
if (string.IsNullOrWhiteSpace(txtCcpNo.Text))
|
||
{
|
||
Alert.ShowInParent("CCP No不能为空!");
|
||
return;
|
||
}
|
||
else
|
||
{
|
||
if (IsNumeric(txtCcpNo.Text) == false)
|
||
{
|
||
Alert.ShowInParent("请输入正确的CCP No!");
|
||
return;
|
||
}
|
||
}
|
||
//判断选中的行中是否存在不同的合同
|
||
var cptNos = new List<string>();
|
||
var cptTaxs = new List<string>();
|
||
var contractNo = string.Empty;
|
||
int[] selections = Grid1.SelectedRowIndexArray;
|
||
foreach (int rowIndex in selections)
|
||
{
|
||
cptNos.Add(Grid1.DataKeys[rowIndex][1].ToString());
|
||
contractNo = Grid1.DataKeys[rowIndex][2].ToString();
|
||
cptTaxs.Add(Grid1.DataKeys[rowIndex][3].ToString());
|
||
}
|
||
//判断选中的合同是否是同一个合同
|
||
if (cptNos.Select(p => p.Substring(0, p.LastIndexOf("-"))).Distinct().Count() > 1 && string.IsNullOrEmpty(hidCcpId.Text))
|
||
{
|
||
Grid1.ClearSelection();
|
||
Alert.ShowInParent("不同合同的CPT不允许创建CCP!");
|
||
return;
|
||
}
|
||
else
|
||
{
|
||
if (cptTaxs.Distinct().Count() > 1)
|
||
{
|
||
Grid1.ClearSelection();
|
||
Alert.ShowInParent("不同税率的CPT不允许创建CCP!");
|
||
return;
|
||
}
|
||
}
|
||
//获取合同表
|
||
var contractModel = Funs.DB.View_FC_SESRelatedData.FirstOrDefault(p => p.FO_NO == contractNo);
|
||
//获取CCP合同最大序号
|
||
var ccpNo = Funs.DB.CCP_List.Count(p => p.Contract_Id == contractModel.ID) == 0 ? 0 : Funs.DB.CCP_List.Where(p => p.Contract_Id == contractModel.ID).Max(p => p.CCP_No);
|
||
//获取CPT信息
|
||
var cpts = Funs.DB.CPTList.Where(p => cptNos.Contains(p.CPT_No)).ToList();
|
||
//获取SES信息
|
||
var sess = Funs.DB.SESList.Where(p => cptNos.Contains(p.CPT_No)).ToList();
|
||
//筛选第一个cpt
|
||
var cptModel = cpts.FirstOrDefault();
|
||
//数据操作
|
||
if (string.IsNullOrEmpty(hidCcpId.Text))
|
||
{
|
||
var itemCcpId = int.Parse(txtCcpNo.Text);
|
||
if (Funs.DB.CCP_List.Count(p => p.Contract_No == ddlContractNo.SelectedValue && p.CCP_No == itemCcpId) > 0)
|
||
{
|
||
Alert.ShowInParent("CCP No重复!");
|
||
return;
|
||
}
|
||
|
||
//添加CCP合同主表
|
||
var ccp = new CCP_List();
|
||
ccp.CPT_Id = string.Join(",", cpts.ConvertAll(p => p.ID));
|
||
ccp.Contract_Id = contractModel.ID;
|
||
ccp.Contractor_CN = cptModel.ContractorCN;
|
||
ccp.Contractor_Eng = cptModel.ContractorEng;
|
||
ccp.Vendor_Code = contractModel.Vendor_NO;
|
||
ccp.Contract_Title = cptModel.FC_Desctription;
|
||
ccp.Contract_No = cptModel.Contract_No;
|
||
ccp.Contract_Type = "Frame Contract 框架合同";
|
||
ccp.Buyer = CurrUser.UserName;
|
||
ccp.Pricing_Method = contractModel.Pricing_Scheme;
|
||
ccp.Contract_Budget = contractModel.Actual_Budget;
|
||
ccp.Contract_PaymentTerm = string.Format("合同价款{0}支付,业主将在收到正确的发票原件以后{0}({1})日内支付。", ddlPaymentTerm.SelectedText, ddlPaymentTerm.SelectedValue == "0" ? "三十" : "九十", ddlPaymentTerm.SelectedValue == "0" ? "30" : "90");
|
||
ccp.Payment_Term = ddlPaymentTerm.SelectedValue;
|
||
ccp.CCP_No = int.Parse(txtCcpNo.Text); //ccpNo + 1;
|
||
ccp.CPT_No = string.Join(",", cpts.ConvertAll(p => p.CPT_No));
|
||
ccp.Created_Time = DateTime.Now;
|
||
ccp.Created_UserId = CurrUser.UserId;
|
||
ccp.Created_UserName = CurrUser.UserName;
|
||
ccp.Created_ChineseName = CurrUser.ChineseName;
|
||
ccp.DeductionDeductionRateType = int.Parse(ddlDeductionDeductionRate.SelectedValue);
|
||
ccp.DelayedDeductionType = int.Parse(ddlDelayedDeduction.SelectedValue);
|
||
Funs.DB.CCP_List.InsertOnSubmit(ccp);
|
||
Funs.DB.SubmitChanges();
|
||
|
||
//循环添加ses信息
|
||
List<CCP_SESList> ccpSess = new List<CCP_SESList>();
|
||
var ccpModel = Funs.DB.CCP_List.FirstOrDefault(p => p.CCP_No == ccp.CCP_No && p.Contract_Id == ccp.Contract_Id);
|
||
for (int i = 0; i < Grid2.Rows.Count; i++)
|
||
{
|
||
Dictionary<int, Dictionary<string, object>> modifiedDict = Grid2.GetModifiedDict();
|
||
if (modifiedDict == null) modifiedDict = new Dictionary<int, Dictionary<string, object>>();
|
||
if (string.IsNullOrEmpty(Grid2.DataKeys[i][0].ToString())) continue;
|
||
|
||
int sesId = int.Parse(Grid2.DataKeys[i][0].ToString());
|
||
var itemSes = sess.FirstOrDefault(p => p.ID == sesId);
|
||
var itemCpt = cpts.FirstOrDefault(p => p.CPT_No == Grid2.DataKeys[i][1].ToString());
|
||
|
||
CCP_SESList itemCcpSes = new CCP_SESList();
|
||
itemCcpSes.CCP_No = ccpModel.CCP_No;
|
||
itemCcpSes.CCP_Id = ccpModel.ID;
|
||
itemCcpSes.CPT_No = itemCpt.CPT_No;
|
||
itemCcpSes.CPT_Id = itemCpt.ID;
|
||
itemCcpSes.Ses_No = itemSes.SES;
|
||
itemCcpSes.Ses_Id = itemSes.ID;
|
||
itemCcpSes.Contract_No = contractModel.FO_NO;
|
||
itemCcpSes.Contract_Id = contractModel.ID;
|
||
itemCcpSes.Project_Name = itemSes.Short_Description;
|
||
itemCcpSes.Contractor_Quotation = itemSes.Quotation;
|
||
itemCcpSes.Incl_Tax = itemSes.Tax_Value;
|
||
itemCcpSes.Con_Days = itemSes.Con_Days;
|
||
if (modifiedDict.ContainsKey(i))
|
||
{
|
||
itemCcpSes.ThirdParty_PriceReview = (modifiedDict[i].ContainsKey("ThirdParty_PriceReview") && !string.IsNullOrWhiteSpace(modifiedDict[i]["ThirdParty_PriceReview"].ToString())) ? decimal.Parse(modifiedDict[i]["ThirdParty_PriceReview"].ToString()) : 0;
|
||
itemCcpSes.Reduction = decimal.Parse(modifiedDict[i]["Reduction"].ToString());
|
||
itemCcpSes.Reduction_Rate = decimal.Parse(modifiedDict[i]["Reduction_Rate"].ToString());
|
||
if (ddlDeductionDeductionRate.SelectedValue == "1")
|
||
{
|
||
itemCcpSes.Deduction_DeductionRate = decimal.Parse(modifiedDict[i]["DeductionDeduction_Rate"].ToString());
|
||
}
|
||
else
|
||
{
|
||
itemCcpSes.Deduction_DeductionRate = 0;
|
||
}
|
||
if (ddlDelayedDeduction.SelectedValue == "1")
|
||
{
|
||
itemCcpSes.DelayedDeduction = decimal.Parse(modifiedDict[i]["DelayedDeduction"].ToString());
|
||
}
|
||
else
|
||
{
|
||
itemCcpSes.DelayedDeduction = 0;
|
||
}
|
||
itemCcpSes.Final_SettlementAmount = decimal.Parse(modifiedDict[i]["Final_SettlementAmount"].ToString());
|
||
if (modifiedDict[i].ContainsKey("Con_Days") && !string.IsNullOrWhiteSpace(modifiedDict[i]["Con_Days"].ToString()))
|
||
{
|
||
itemCcpSes.Con_Days = int.Parse(modifiedDict[i]["Con_Days"].ToString());
|
||
}
|
||
}
|
||
else
|
||
{
|
||
itemCcpSes.ThirdParty_PriceReview = 0;
|
||
itemCcpSes.Reduction = 0;
|
||
itemCcpSes.Reduction_Rate = Math.Round(Convert.ToDecimal((itemSes.Quotation - itemSes.Tax_Value) / itemSes.Quotation) * 100, 2, MidpointRounding.AwayFromZero);
|
||
if (ddlDeductionDeductionRate.SelectedValue == "1")
|
||
{
|
||
|
||
itemCcpSes.Deduction_DeductionRate = itemCcpSes.Reduction_Rate > 10 ? -(Math.Round(Convert.ToDecimal((float)itemSes.Tax_Value * 0.02), 2, MidpointRounding.AwayFromZero)) : 0;
|
||
}
|
||
else
|
||
{
|
||
itemCcpSes.Deduction_DeductionRate = 0;
|
||
}
|
||
if (ddlDelayedDeduction.SelectedValue == "1")
|
||
{
|
||
if (itemSes.Con_Days != null)
|
||
{
|
||
if (itemSes.Con_Days > 15 && itemSes.Con_Days <= 20)
|
||
{
|
||
itemCcpSes.DelayedDeduction = -Math.Round(Convert.ToDecimal((float)itemSes.Tax_Value * 0.05));
|
||
}
|
||
else if (itemSes.Con_Days > 20)
|
||
{
|
||
itemCcpSes.DelayedDeduction = -Math.Round(Convert.ToDecimal((float)itemSes.Tax_Value * 0.1));
|
||
}
|
||
else
|
||
{
|
||
itemCcpSes.DelayedDeduction = 0;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
itemCcpSes.DelayedDeduction = 0;
|
||
}
|
||
//itemCcpSes.DelayedDeduction = itemSes.Con_Days > 15 ? -(Math.Round(Convert.ToDecimal((float)itemSes.Tax_Value * 0.1))) : 0;
|
||
}
|
||
else
|
||
{
|
||
itemCcpSes.DelayedDeduction = 0;
|
||
}
|
||
itemCcpSes.Final_SettlementAmount = itemSes.Tax_Value + itemCcpSes.DelayedDeduction + itemCcpSes.DelayedDeduction;
|
||
}
|
||
itemCcpSes.Created_Time = DateTime.Now;
|
||
itemCcpSes.Created_UserId = CurrUser.UserId;
|
||
itemCcpSes.Created_UserName = CurrUser.UserName;
|
||
itemCcpSes.Created_ChineseName = CurrUser.ChineseName;
|
||
ccpSess.Add(itemCcpSes);
|
||
}
|
||
Funs.DB.CCP_SESList.InsertAllOnSubmit(ccpSess);
|
||
Funs.DB.SubmitChanges();
|
||
hidCcpId.Text = ccpModel.ID.ToString();
|
||
}
|
||
else
|
||
{
|
||
//修改CCP合同主表
|
||
int ccpId = int.Parse(hidCcpId.Text);
|
||
var ccp = Funs.DB.CCP_List.FirstOrDefault(p => p.ID == ccpId);
|
||
if (ccp != null)
|
||
{
|
||
var itemCcpId = int.Parse(txtCcpNo.Text);
|
||
if (Funs.DB.CCP_List.Count(p => p.Contract_Id == ccp.Contract_Id && p.CCP_No == itemCcpId && p.ID != ccp.ID) > 0)
|
||
{
|
||
Alert.ShowInParent("CCP No重复!");
|
||
return;
|
||
}
|
||
|
||
ccp.CPT_Id = string.Join(",", cpts.ConvertAll(p => p.ID));
|
||
ccp.Contract_Id = contractModel.ID;
|
||
ccp.Contractor_CN = cptModel.ContractorCN;
|
||
ccp.Contractor_Eng = cptModel.ContractorEng;
|
||
ccp.Vendor_Code = contractModel.Vendor_NO;
|
||
ccp.Contract_Title = cptModel.FC_Desctription;
|
||
ccp.Buyer = CurrUser.UserName;
|
||
ccp.Pricing_Method = contractModel.Pricing_Scheme;
|
||
ccp.Contract_Budget = contractModel.Actual_Budget;
|
||
ccp.Contract_PaymentTerm = string.Format("合同价款{0}支付,业主将在收到正确的发票原件以后{0}({1})日内支付。", ddlPaymentTerm.SelectedText, ddlPaymentTerm.SelectedValue == "0" ? "三十" : "九十", ddlPaymentTerm.SelectedValue == "0" ? "30" : "90");
|
||
ccp.Payment_Term = ddlPaymentTerm.SelectedValue;
|
||
ccp.CCP_No = int.Parse(txtCcpNo.Text);
|
||
ccp.CPT_No = string.Join(",", cpts.ConvertAll(p => p.CPT_No));
|
||
ccp.Modify_Time = DateTime.Now;
|
||
ccp.Modify_UserId = CurrUser.UserId;
|
||
ccp.Modify_UserName = CurrUser.UserName;
|
||
ccp.Modify_ChineseName = CurrUser.ChineseName;
|
||
ccp.DeductionDeductionRateType = int.Parse(ddlDeductionDeductionRate.SelectedValue);
|
||
ccp.DelayedDeductionType = int.Parse(ddlDelayedDeduction.SelectedValue);
|
||
Funs.DB.SubmitChanges();
|
||
|
||
//删除已经存在的ccpses
|
||
var deleteccpses = Funs.DB.CCP_SESList.Where(p => p.CCP_Id == ccpId).ToList();
|
||
Funs.DB.CCP_SESList.DeleteAllOnSubmit(deleteccpses);
|
||
Funs.DB.SubmitChanges();
|
||
|
||
//循环添加ses信息
|
||
List<CCP_SESList> ccpSess = new List<CCP_SESList>();
|
||
for (int i = 0; i < Grid2.Rows.Count; i++)
|
||
{
|
||
Dictionary<int, Dictionary<string, object>> modifiedDict = Grid2.GetModifiedDict();
|
||
if (modifiedDict == null) modifiedDict = new Dictionary<int, Dictionary<string, object>>();
|
||
if (string.IsNullOrEmpty(Grid2.DataKeys[i][0].ToString())) continue;
|
||
|
||
int sesId = int.Parse(Grid2.DataKeys[i][0].ToString());
|
||
var itemSes = sess.FirstOrDefault(p => p.ID == sesId);
|
||
var itemCpt = cpts.FirstOrDefault(p => p.CPT_No == Grid2.DataKeys[i][1].ToString());
|
||
var itemDeleteCcp = deleteccpses.FirstOrDefault(p => p.Ses_No == itemSes.SES);
|
||
CCP_SESList itemCcpSes = new CCP_SESList();
|
||
itemCcpSes.CCP_No = ccp.CCP_No;
|
||
itemCcpSes.CCP_Id = ccp.ID;
|
||
itemCcpSes.CPT_No = itemCpt.CPT_No;
|
||
itemCcpSes.CPT_Id = itemCpt.ID;
|
||
itemCcpSes.Ses_No = itemSes.SES;
|
||
itemCcpSes.Ses_Id = itemSes.ID;
|
||
itemCcpSes.Contract_No = contractModel.FO_NO;
|
||
itemCcpSes.Contract_Id = contractModel.ID;
|
||
itemCcpSes.Project_Name = itemSes.Short_Description;
|
||
itemCcpSes.Contractor_Quotation = itemSes.Quotation;
|
||
itemCcpSes.Incl_Tax = itemSes.Tax_Value;
|
||
itemCcpSes.Con_Days = itemSes.Con_Days;
|
||
if (modifiedDict.ContainsKey(i))
|
||
{
|
||
if (itemDeleteCcp != null)
|
||
{
|
||
itemCcpSes.ThirdParty_PriceReview = (modifiedDict[i].ContainsKey("ThirdParty_PriceReview") && !string.IsNullOrWhiteSpace(modifiedDict[i]["ThirdParty_PriceReview"].ToString())) ? decimal.Parse(modifiedDict[i]["ThirdParty_PriceReview"].ToString()) : itemDeleteCcp.ThirdParty_PriceReview;
|
||
itemCcpSes.Reduction = modifiedDict[i].ContainsKey("Reduction") ? decimal.Parse(modifiedDict[i]["Reduction"].ToString()) : itemDeleteCcp.Reduction;
|
||
itemCcpSes.Reduction_Rate = modifiedDict[i].ContainsKey("Reduction_Rate") ? decimal.Parse(modifiedDict[i]["Reduction_Rate"].ToString()) : itemDeleteCcp.Reduction_Rate;
|
||
itemCcpSes.Deduction_DeductionRate = modifiedDict[i].ContainsKey("DeductionDeduction_Rate") ? decimal.Parse(modifiedDict[i]["DeductionDeduction_Rate"].ToString()) : itemDeleteCcp.Deduction_DeductionRate;
|
||
itemCcpSes.DelayedDeduction = modifiedDict[i].ContainsKey("DelayedDeduction") ? decimal.Parse(modifiedDict[i]["DelayedDeduction"].ToString()) : itemDeleteCcp.DelayedDeduction;
|
||
itemCcpSes.Final_SettlementAmount = modifiedDict[i].ContainsKey("Final_SettlementAmount") ? decimal.Parse(modifiedDict[i]["Final_SettlementAmount"].ToString()) : itemDeleteCcp.Final_SettlementAmount;
|
||
}
|
||
else
|
||
{
|
||
itemCcpSes.ThirdParty_PriceReview = (modifiedDict[i].ContainsKey("ThirdParty_PriceReview") && !string.IsNullOrWhiteSpace(modifiedDict[i]["ThirdParty_PriceReview"].ToString())) ? decimal.Parse(modifiedDict[i]["ThirdParty_PriceReview"].ToString()) : 0;
|
||
itemCcpSes.Reduction = modifiedDict[i]["Reduction"] != null ? decimal.Parse(modifiedDict[i]["Reduction"].ToString()) : 0;
|
||
itemCcpSes.Reduction_Rate = decimal.Parse(modifiedDict[i]["Reduction_Rate"].ToString());
|
||
itemCcpSes.Deduction_DeductionRate = decimal.Parse(modifiedDict[i]["DeductionDeduction_Rate"].ToString());
|
||
itemCcpSes.DelayedDeduction = decimal.Parse(modifiedDict[i]["DelayedDeduction"].ToString());
|
||
itemCcpSes.Final_SettlementAmount = decimal.Parse(modifiedDict[i]["Final_SettlementAmount"].ToString());
|
||
}
|
||
|
||
if (modifiedDict[i].ContainsKey("Con_Days") && !string.IsNullOrWhiteSpace(modifiedDict[i]["Con_Days"].ToString()))
|
||
{
|
||
itemCcpSes.Con_Days = int.Parse(modifiedDict[i]["Con_Days"].ToString());
|
||
}
|
||
}
|
||
else
|
||
{
|
||
itemCcpSes.ThirdParty_PriceReview = 0;
|
||
itemCcpSes.Reduction = 0;
|
||
itemCcpSes.Reduction_Rate = Math.Round(Convert.ToDecimal((itemSes.Quotation - itemSes.Tax_Value) / itemSes.Quotation) * 100, 2, MidpointRounding.AwayFromZero);
|
||
itemCcpSes.Deduction_DeductionRate = itemCcpSes.Reduction_Rate > 10 ? -(Math.Round(Convert.ToDecimal((float)itemSes.Tax_Value * 0.02), 2, MidpointRounding.AwayFromZero)) : 0;
|
||
if (itemSes.Con_Days != null)
|
||
{
|
||
if (itemSes.Con_Days > 15 && itemSes.Con_Days <= 20)
|
||
{
|
||
itemCcpSes.DelayedDeduction = -Math.Round(Convert.ToDecimal((float)itemSes.Tax_Value * 0.05));
|
||
}
|
||
else if (itemSes.Con_Days > 20)
|
||
{
|
||
itemCcpSes.DelayedDeduction = -Math.Round(Convert.ToDecimal((float)itemSes.Tax_Value * 0.1));
|
||
}
|
||
else
|
||
{
|
||
itemCcpSes.DelayedDeduction = 0;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
itemCcpSes.DelayedDeduction = 0;
|
||
}
|
||
// itemCcpSes.DelayedDeduction = itemSes.Con_Days > 15 ? -(Math.Round(Convert.ToDecimal((float)itemSes.Tax_Value * 0.1))) : 0;
|
||
|
||
itemCcpSes.Final_SettlementAmount = itemSes.Tax_Value + itemCcpSes.DelayedDeduction + itemCcpSes.DelayedDeduction;
|
||
}
|
||
|
||
itemCcpSes.Created_Time = DateTime.Now;
|
||
itemCcpSes.Created_UserId = CurrUser.UserId;
|
||
itemCcpSes.Created_UserName = CurrUser.UserName;
|
||
itemCcpSes.Created_ChineseName = CurrUser.ChineseName;
|
||
ccpSess.Add(itemCcpSes);
|
||
}
|
||
Funs.DB.CCP_SESList.InsertAllOnSubmit(ccpSess);
|
||
Funs.DB.SubmitChanges();
|
||
}
|
||
hidCcpId.Text = ccp.ID.ToString();
|
||
}
|
||
|
||
hidContractNo.Text = contractModel.FO_NO;
|
||
BindGrid();
|
||
ShowNotify("操作成功!");
|
||
}
|
||
|
||
/// <summary>
|
||
/// 是否为数字
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public bool IsNumeric(string str)
|
||
{
|
||
var result = false;
|
||
try
|
||
{
|
||
int.Parse(str);
|
||
result = true;
|
||
}
|
||
catch
|
||
{
|
||
result = false;
|
||
}
|
||
return result;
|
||
}
|
||
|
||
#endregion
|
||
}
|
||
} |