You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/ParameterSet/CodeFeeTemplateSetEdit.aspx.cs

578 lines
28 KiB
C#

2 years ago
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using DSWeb.Models;
using DSWeb.EntityDA;
namespace DSWeb.ParameterSet
{
public partial class CodeFeeTemplateSetEdit : System.Web.UI.Page
{
public string strUserID;//用户GID
private string strCompanyID;//公司GID
private string strShowName;//用户显示名
private string strDeptName;//部门名称
private string strFeeTemplateID;//费用模板主表GID
private string strHandle;
public string strGID="";//用户GID
protected void Page_Load(object sender, EventArgs e)
{
if (Session["USERID"] != null)
{
strUserID = Session["USERID"].ToString();
}
if (Session["SHOWNAME"] != null)
{
strShowName = Session["SHOWNAME"].ToString();
}
if (Session["COMPANYID"] != null)
{
strCompanyID = Session["COMPANYID"].ToString();
}
if (Session["DEPTNAME"] != null)
{
strDeptName = Session["DEPTNAME"].ToString();
}
//
if (Request.QueryString["id"] != null)
{
strFeeTemplateID = Request.QueryString["id"].ToString();
h_templateid.Value = strFeeTemplateID;
strGID = strFeeTemplateID;
}
if (Request.QueryString["handle"] != null)
{
strHandle = Request.QueryString["handle"].ToString().ToLower();
}
//
if (!IsPostBack)
{
}
if (this.h_post.Value.Trim() != "")
{
if (this.h_post.Value.Trim().Equals("3") && this.h_feecache.Value.Trim() != "")
{
SaveFeeTemplateAndDetail();
}
else if (this.h_post.Value.Trim().Equals("2"))
{
SaveFeeTemplate();
}
else if (this.h_post.Value.Trim().Equals("1") && this.h_feecache.Value.Trim() != "")
{
SaveFeeTemplateDetail();
}
else
{
SaveFeeTemplate();
}
}
else
{
//权限可视范围
RangeDA RangeDA = new EntityDA.RangeDA();
string strV = RangeDA.GetVISIBLERANGE(strUserID, "modCodeFeeTemplateSet");//海运进口委托管理列表
string strO = RangeDA.GetOPERATERANGE(strUserID, "modCodeFeeTemplateSet");//海运进口委托管理列表
//
if (strHandle == "add")
{
if (strO.Trim().Equals("4"))//无
{
getEnabled();
Page.ClientScript.RegisterStartupScript(this.GetType(), "key1", "<script>alert('无添加权限!');window.close();</script>");
return;
}
this.txt_createuser.InnerHtml = strShowName;
}
else if (strHandle == "edit" && strFeeTemplateID != null)
{
InitFeeTemplate(strFeeTemplateID);
#region 权限可视范围
string alt = "";
if (strV.Trim() != strO.Trim())
{
if (strO.Trim().Equals("0"))//全部
{
}
else if (strO.Trim().Equals("1"))//分公司
{
alt = RangeDA.GetCodeFeeTemplateSetCompany(strUserID, strGID);
if (alt == "")
{
getEnabled();
}
}
else if (strO.Trim().Equals("2"))//部门
{
alt = RangeDA.GetCodeFeeTemplateSetDEPT(strDeptName, strGID, strCompanyID, strUserID);
if (alt == "")
{
getEnabled();
}
}
else if (strO.Trim().Equals("3"))//个人
{
alt = RangeDA.GetCodeFeeTemplateSetPerson(strUserID, strGID, strCompanyID);
if (alt == "")
{
getEnabled();
}
}
else if (strO.Trim().Equals("4"))//无
{
getEnabled();
}
}
#endregion
}
}
}
protected void getEnabled()
{
this.dvOptype.Disabled = true;
this.sel_optype.Disabled = true;
this.sel_feetype.Disabled = true;
this.txt_name.Disabled = true;
this.txt_description.Disabled = true;
this.txt_createuser.Disabled = true;
this.txt_createtime.Disabled = true;
this.txt_remark.Disabled = true;
//
this.btn_update.Disabled = true;;//保存
this.dvAf.Disabled = true;;//添加新费用
this.dvStl.Disabled = true;;//保存费用
this.dvDf.Disabled = true;;//删除费用
this.dvRfl.Disabled = true;;//刷新列表
this.mygrid_container_fee.Disabled = true;
}
#region 加载已生成的费用模板信息
/// <summary>
/// 加载已生成的费用模板信息
/// </summary>
/// <param name="tempFeeTemplateID">费用模板GID</param>
private void InitFeeTemplate(string tempFeeTemplateID)
{
FeeTemplateEntity feeTemplateEntity = new FeeTemplateEntity();
FeeTemplateDA feeTemplateDA = new FeeTemplateDA();
feeTemplateEntity = feeTemplateDA.GetFeeTemplateByGID(tempFeeTemplateID);
UserDA userDA = new UserDA();
UserEntity userEntity = new UserEntity();
userEntity = userDA.GetUserSignByID(feeTemplateEntity.CreateUser);
if (feeTemplateEntity.GID != null)
{
this.sel_optype.Value = feeTemplateEntity.OpType.ToString();
this.sel_feetype.Value = feeTemplateEntity.FeeType.ToString();
this.txt_name.Value = feeTemplateEntity.Name;
this.txt_description.Value = feeTemplateEntity.Description;
this.txt_createuser.InnerHtml = userEntity.ShowName;
this.txt_createtime.InnerHtml = feeTemplateEntity.CreateTime.ToString();
this.txt_remark.Value = feeTemplateEntity.Remark;
}
}
#endregion
private void SaveFeeTemplate()
{
int iState = 0;
FeeTemplateDA feeTemplateDA = new FeeTemplateDA();
FeeTemplateEntity feeTemplateEntity = new FeeTemplateEntity();
if (h_templateid.Value.Trim() != "")
{
feeTemplateEntity.GID = h_templateid.Value.Trim();
feeTemplateEntity.OpType = int.Parse(this.sel_optype.Value);
feeTemplateEntity.FeeType = int.Parse(this.sel_feetype.Value);
feeTemplateEntity.Name = this.txt_name.Value.Trim();
feeTemplateEntity.Description = this.txt_description.Value.Trim();
feeTemplateEntity.ModifiedUser = strUserID;
feeTemplateEntity.Remark = this.txt_remark.Value.Trim();
feeTemplateEntity.CORPID = strCompanyID;
iState = feeTemplateDA.UpdateFeeTemplate(feeTemplateEntity);
if (iState == 1)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key2", "<script>alert('保存成功');window.opener.location.href=window.opener.location.href;</script>");
}
}
else
{
feeTemplateEntity.GID = Guid.NewGuid().ToString();
feeTemplateEntity.OpType = int.Parse(this.sel_optype.Value);
feeTemplateEntity.FeeType = int.Parse(this.sel_feetype.Value);
feeTemplateEntity.Name = this.txt_name.Value.Trim();
feeTemplateEntity.Description = this.txt_description.Value.Trim();
feeTemplateEntity.CreateUser = strUserID;
feeTemplateEntity.Remark = this.txt_remark.Value.Trim();
feeTemplateEntity.CORPID = strCompanyID;
iState = feeTemplateDA.InsertFeeTemplate(feeTemplateEntity);
if (iState == 1)
{
h_templateid.Value = feeTemplateEntity.GID;
Page.ClientScript.RegisterStartupScript(this.GetType(), "key3", "<script>alert('保存成功');window.opener.location.href=window.opener.location.href;</script>");
}
}
}
private void SaveFeeTemplateAndDetail()
{
FeeTemplateDA feeTemplateDA = new FeeTemplateDA();
FeeTemplateEntity feeTemplateEntity = new FeeTemplateEntity();
int iState = 0;
if (h_templateid.Value.Trim() != "")
{
feeTemplateEntity.GID = h_templateid.Value.Trim();
feeTemplateEntity.OpType = int.Parse(this.sel_optype.Value);
feeTemplateEntity.FeeType = int.Parse(this.sel_feetype.Value);
feeTemplateEntity.Name = this.txt_name.Value.Trim();
feeTemplateEntity.Description = this.txt_description.Value.Trim();
feeTemplateEntity.ModifiedUser = strUserID;
feeTemplateEntity.Remark = this.txt_remark.Value.Trim();
feeTemplateEntity.CORPID = strCompanyID;
iState = feeTemplateDA.UpdateFeeTemplate(feeTemplateEntity);
}
else
{
feeTemplateEntity.GID = Guid.NewGuid().ToString();
feeTemplateEntity.OpType = int.Parse(this.sel_optype.Value);
feeTemplateEntity.FeeType = int.Parse(this.sel_feetype.Value);
feeTemplateEntity.Name = this.txt_name.Value.Trim();
feeTemplateEntity.Description = this.txt_description.Value.Trim();
feeTemplateEntity.CreateUser = strUserID;
feeTemplateEntity.Remark = this.txt_remark.Value.Trim();
feeTemplateEntity.CORPID = strCompanyID;
iState = feeTemplateDA.InsertFeeTemplate(feeTemplateEntity);
if (iState == 1)
{
h_templateid.Value = feeTemplateEntity.GID;
}
}
//
if (iState == 1)
{
if (this.h_feecache.Value.Trim() != "")
{
string strList = "";
string strFilter = "";
IList<FeeTemplateDetailEntity> feeTemplateDetailEntities = new List<FeeTemplateDetailEntity>();
strList = this.h_feecache.Value.Trim();
if (strList.IndexOf("[") >= 0 && strList.IndexOf("]") > 0)
{
strFilter = strList.Substring(strList.IndexOf("[") + 1, strList.IndexOf("]") - strList.IndexOf("[") - 1);
string[] strFees = strFilter.Split(new string[] { "},{" }, System.StringSplitOptions.RemoveEmptyEntries);
if (strFees.Length > 0)
{
for (int i = 0; i < strFees.Length; i++)
{
strFees[i] = strFees[i].ToString().Replace("{", "");
strFees[i] = strFees[i].ToString().Replace("}", "");
string[] strCell = strFees[i].Split(new char[] { ',' });
if (strCell.Length > 0)
{
FeeTemplateDetailEntity feeTemplateDetailEntity = new FeeTemplateDetailEntity();
for (int j = 0; j < strCell.Length; j++)
{
string[] strArg = strCell[j].Split(new char[] { ':' });
switch (strArg[0].Replace("\"", ""))
{
case "id":
feeTemplateDetailEntity.GID = strArg[1].ToString().Replace("\"", "").Trim();
break;
case "type":
feeTemplateDetailEntity.FeeType = int.Parse(strArg[1].ToString().Replace("\"", "").Trim());
break;
case "fname":
feeTemplateDetailEntity.FeeName = strArg[1].ToString().Replace("\"", "").Trim().Equals("") ? "" : UnicodeToGB(strArg[1].ToString().Replace("\"", "").Trim());
break;
case "cust":
feeTemplateDetailEntity.CustomerName = strArg[1].ToString().Replace("\"", "").Trim().ToLower().Equals("null") ? "" : UnicodeToGB(strArg[1].ToString().Replace("\"", "").Trim());
break;
case "client":
feeTemplateDetailEntity.Client = strArg[1].ToString().Replace("\"", "").Trim().Equals("") ? GetClientIdByName("") : GetClientIdByName(UnicodeToGB(strArg[1].ToString().Replace("\"", "").Trim()));
break;
case "unit":
feeTemplateDetailEntity.Unit = strArg[1].ToString().Replace("\"", "").Trim().Equals("") ? "" : UnicodeToGB(strArg[1].ToString().Replace("\"", "").Trim());
break;
case "price":
feeTemplateDetailEntity.UnitPrice = strArg[1].ToString().Replace("\"", "").Trim().Equals("") ? 0 : decimal.Parse(strArg[1].ToString().Replace("\"", "").Trim());
break;
case "cur":
feeTemplateDetailEntity.Currency = strArg[1].ToString().Replace("\"", "").Trim();
break;
case "exchange":
feeTemplateDetailEntity.ExchangeRate = decimal.Parse(strArg[1].ToString().Replace("\"", "").Trim());
break;
case "remark":
feeTemplateDetailEntity.Remark = strArg[1].ToString().Replace("\"", "").Trim();
break;
case "sort":
feeTemplateDetailEntity.Sort = int.Parse(strArg[1].ToString().Replace("\"", "").Trim());
break;
default:
break;
}
}
feeTemplateDetailEntity.CreateUser = strUserID;
feeTemplateDetailEntity.ModifiedUser = strUserID;
feeTemplateDetailEntity.TemplateID = feeTemplateEntity.GID;
feeTemplateDetailEntity.FeeCode = "";
feeTemplateDetailEntities.Add(feeTemplateDetailEntity);
}
}
}
}
if (feeTemplateDetailEntities.Count > 0)
{
FeeTemplateDetailDA feeTemplateDetailDA = new FeeTemplateDetailDA();
int iResult = 0;
iResult = feeTemplateDetailDA.SaveFeeTemplateDetail(feeTemplateDetailEntities);
this.h_post.Value = "0";
if (iResult == 1)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key4", "<script>alert('保存成功');window.opener.location.href=window.opener.location.href;</script>");
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key5", "<script>alert('操作出错');</script>");
return;
}
}
}
else
{
if (iState == 1)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key6", "<script>alert('保存成功');window.opener.location.href=window.opener.location.href;</script>");
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key7", "<script>alert('操作出错');</script>");
return;
}
}
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key8", "<script>alert('操作出错');</script>");
return;
}
}
private void SaveFeeTemplateDetail()
{
if (this.h_feecache.Value.Trim() != "")
{
string strList = "";
string strFilter = "";
IList<FeeTemplateDetailEntity> feeTemplateDetailEntities = new List<FeeTemplateDetailEntity>();
strList = this.h_feecache.Value.Trim();
if (strList.IndexOf("[") >= 0 && strList.IndexOf("]") > 0)
{
strFilter = strList.Substring(strList.IndexOf("[") + 1, strList.IndexOf("]") - strList.IndexOf("[") - 1);
string[] strFees = strFilter.Split(new string[] { "},{" }, System.StringSplitOptions.RemoveEmptyEntries);
if (strFees.Length > 0)
{
for (int i = 0; i < strFees.Length; i++)
{
strFees[i] = strFees[i].ToString().Replace("{", "");
strFees[i] = strFees[i].ToString().Replace("}", "");
string[] strCell = strFees[i].Split(new char[] { ',' });
if (strCell.Length > 0)
{
FeeTemplateDetailEntity feeTemplateDetailEntity = new FeeTemplateDetailEntity();
for (int j = 0; j < strCell.Length; j++)
{
string[] strArg = strCell[j].Split(new char[] { ':' });
switch (strArg[0].Replace("\"", ""))
{
case "id":
feeTemplateDetailEntity.GID = strArg[1].ToString().Replace("\"", "").Trim();
break;
case "type":
feeTemplateDetailEntity.FeeType = int.Parse(strArg[1].ToString().Replace("\"", "").Trim());
break;
case "fname":
feeTemplateDetailEntity.FeeName = UnicodeToGB(strArg[1].ToString().Replace("\"", "").Trim());
break;
case "cust":
feeTemplateDetailEntity.CustomerName = strArg[1].ToString().Replace("\"", "").Trim().ToLower().Equals("null") ? "" : UnicodeToGB(strArg[1].ToString().Replace("\"", "").Trim());
break;
case "client":
feeTemplateDetailEntity.Client = strArg[1].ToString().Replace("\"", "").Trim().Equals("") ? GetClientIdByName("") : GetClientIdByName(UnicodeToGB(strArg[1].ToString().Replace("\"", "").Trim()));
break;
case "unit":
feeTemplateDetailEntity.Unit = UnicodeToGB(strArg[1].ToString().Replace("\"", "").Trim());
break;
case "price":
feeTemplateDetailEntity.UnitPrice = strArg[1].ToString().Replace("\"", "").Trim().Equals("") ? 0 : decimal.Parse(strArg[1].ToString().Replace("\"", "").Trim());
break;
case "cur":
feeTemplateDetailEntity.Currency = strArg[1].ToString().Replace("\"", "").Trim();
break;
case "exchange":
feeTemplateDetailEntity.ExchangeRate = decimal.Parse(strArg[1].ToString().Replace("\"", "").Trim());
break;
case "remark":
feeTemplateDetailEntity.Remark = strArg[1].ToString().Replace("\"", "").Trim();
break;
case "sort":
feeTemplateDetailEntity.Sort = int.Parse(strArg[1].ToString().Replace("\"", "").Trim());
break;
default:
break;
}
}
feeTemplateDetailEntity.TemplateID = this.h_templateid.Value.Trim();
feeTemplateDetailEntity.CreateUser = strUserID;
feeTemplateDetailEntity.ModifiedUser = strUserID;
feeTemplateDetailEntity.FeeCode = "";
feeTemplateDetailEntities.Add(feeTemplateDetailEntity);
}
}
}
}
//
if (feeTemplateDetailEntities.Count > 0)
{
FeeTemplateDetailDA feeTemplateDetailDA = new FeeTemplateDetailDA();
int iResult = 0;
iResult = feeTemplateDetailDA.SaveFeeTemplateDetail(feeTemplateDetailEntities);
if (iResult == 1)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key9", "<script>alert('保存成功');window.opener.location.href=window.opener.location.href;</script>");
}
}
}
}
#region Unicode-GB Code转换
/// <summary>
/// Unicode-GB Code转换
/// </summary>
/// <param name="text">将Unicode编码字符转换成GB编码字符</param>
/// <returns>GB Code字符串</returns>
public string UnicodeToGB(string text)
{
UnicodeEncoding unicode = new UnicodeEncoding();
text = unicode.GetString(unicode.GetBytes(Regex.Unescape(text.Trim())));
return text;
}
/// <summary>
/// Unicode-GB Code转换
/// </summary>
/// <param name="text">将Unicode编码字符转换成GB编码字符</param>
/// <returns>GB Code字符串</returns>
public string UnicodeToGB_Old(string text)
{
MatchCollection mc = Regex.Matches(text, "([\\w]+)|(\\\\u([\\w]{4}))");
if (mc != null && mc.Count > 0)
{
StringBuilder sb = new StringBuilder();
foreach (Match m2 in mc)
{
string v = m2.Value;
if (v.IndexOf("\\") >= 0)
{
string word = v.Substring(2);
byte[] codes = new byte[2];
int code = Convert.ToInt32(word.Substring(0, 2), 16);
int code2 = Convert.ToInt32(word.Substring(2), 16);
codes[0] = (byte)code2;
codes[1] = (byte)code;
sb.Append(Encoding.Unicode.GetString(codes));
}
else
{
sb.Append(v);
}
}
return sb.ToString();
}
else
{
return text;
}
}
#endregion
#region 根据结算对象类型名称获取结算单位对象类型数值
/// <summary>
/// 根据结算对象类型名称获取结算单位对象类型数值
/// </summary>
/// <param name="strClientName">结算对象类型名称</param>
/// <returns>返回结算单位对象类型数值</returns>
private int GetClientIdByName(string strClientName)
{
int iResult = 0;
switch (strClientName)
{
case "船公司":
iResult = 1;
break;
case "订舱代理":
iResult = 2;
break;
case "场站":
iResult = 3;
break;
case "车队":
iResult = 4;
break;
case "委托单位":
iResult = 5;
break;
case "报关行":
iResult = 6;
break;
case "代理":
iResult = 7;
break;
case "航空公司":
iResult = 8;
break;
case "发货人":
iResult = 9;
break;
case "收货人":
iResult = 10;
break;
case "通知人":
iResult = 11;
break;
case "船代":
iResult = 12;
break;
case "码头":
iResult = 13;
break;
case "其他":
iResult = 14;
break;
default:
iResult = 0;
break;
}
return iResult;
}
#endregion
}
}