Commit 91c64fe7 authored by charleslee's avatar charleslee

feat:fee batch

parent 104076d9
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using WebAPI.Tool;
namespace WebAPI
{
......@@ -9,6 +11,8 @@ namespace WebAPI
{
public static void Register(HttpConfiguration config)
{
LogHelper.InitLog4Net(HttpContext.Current.Server.MapPath("\\log4net.config"));
//EnableCors
config.EnableCors();
// Web API 設定和服務
......
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;
using WebAPI.Dal;
using WebAPI.Models;
using WebAPI.Tool;
namespace WebAPI.Controllers
{
public class AnnualInfoController : ApiController
{
public AnnualInfoController()
{
}
#region 獲取年費訊息
[Route("AnnualInfo")]
[CorsHandle]
[HttpGet]
public HttpResponseMessage GetAnnualInfo(string id)
{
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
CommonResponseMsg response = new CommonResponseMsg();
DalProcInfo dal_proc_info = new DalProcInfo();
string cur_review_stage = "";
int cur_stage = dal_proc_info.GetAnnualStageByProc("66AE6B1D-690E-49D1-A98C-2195FDFDAA2A", "CN", ref cur_review_stage);
//AnnualInfo ai = this.GetAnnualInfo(cur_stage, case_type_id, country_id, apply_type_id);
try
{
/*if (string.IsNullOrWhiteSpace(case_type_id))
{
response.Code = "0";
response.Msg = "no case_type_id";
}
else
{
*/
}
catch (Exception e)
{
response.Code = "0";
response.Msg = e.Message;
}
result.Content = new StringContent(JsonConvert.SerializeObject(response), System.Text.Encoding.UTF8, "application/json");
return result;
}
#endregion
}
}
\ No newline at end of file
......@@ -10,7 +10,9 @@ using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Http;
using System.Web.Http.Cors;
......@@ -213,40 +215,390 @@ namespace WebAPI.Controllers
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
CommonResponseMsg response = new CommonResponseMsg();
try
{
var mode = HttpContext.Current.Request.Form["mode"];
if (!string.IsNullOrEmpty(mode))
{
if (mode == "check")
{
var file = HttpContext.Current.Request.Files.Count > 0 ? HttpContext.Current.Request.Files[0] : null;
//var input = HttpContext.Current.Request.Params;
if (file != null)
{
ExcelHelper excel_helper = new ExcelHelper();
CommonResponseMsg result_excel = excel_helper.LoadFromStream(file.InputStream, file.FileName);
DataSet ds_excel = (DataSet)result_excel.Msg;
if(result_excel.Code=="1" && ds_excel.Tables.Count > 0)
if (result_excel.Code == "1" && ds_excel.Tables.Count > 0)
{
DataTable dt_excel = ds_excel.Tables[0];
dt_excel.Columns.Add("id", typeof(String));
dt_excel.Columns.Add("check_status", typeof(String));
dt_excel.Columns.Add("update_status", typeof(String));
dt_excel.Columns.Add("import_data", typeof(String));
DalProcInfo dal_proc_info = new DalProcInfo();
DalBaseInfo dal_base_info = new DalBaseInfo();
DalFee dal_fee = new DalFee();
DalCaseInfo dal_case_info = new DalCaseInfo();
CommonResponseMsg result_ctrl_proc = dal_proc_info.GetCtrlProc("ctrl_proc_id, case_type_id, ctrl_proc_zh_cn, ctrl_proc_zh_tw, proc_status_id, case_status_id");
CommonResponseMsg result_ctrl_proc = dal_proc_info.GetCtrlProc("ctrl_proc_id, case_type_id, ctrl_proc_zh_cn, ctrl_proc_zh_tw, proc_status_id, case_status_id, country_id, business_type_id, apply_type_id");
CommonResponseMsg result_case_status = dal_proc_info.GetCaseStatus("case_status_id, case_type_id, case_status_zh_cn, case_status_zh_tw");
CommonResponseMsg result_fee_cate_workitem = dal_base_info.GetDictionaryByName("*", "fee_cate_workitem");//科目
CommonResponseMsg result_fo_tax_rate_name = dal_base_info.GetDictionaryByName("*", "fo_tax_rate_name");//稅別
CommonResponseMsg result_tax_type = dal_base_info.GetDictionaryByName("*", "tax_type");//稅計算類型
CommonResponseMsg result_fc_cate = dal_base_info.GetFcCategory();//程序名稱
CommonResponseMsg result_currency = dal_base_info.GetDataByTable("*", "i_currency");//幣別
CommonResponseMsg result_customer = dal_base_info.GetDataByTable("customer_id, customer_name, customer_name_en", "c_customer", true);//客戶
CommonResponseMsg result_case_type = dal_base_info.GetDataByTable("*", "i_case_type");//案件類型
CommonResponseMsg result_country = dal_base_info.GetDataByTable("*", "i_country");//國家
CommonResponseMsg result_apply_type = dal_base_info.GetDataByTable("*", "i_apply_type");//申請類型
CommonResponseMsg result_business_type = dal_base_info.GetDataByTable("*", "i_business_type");//業務類型
if (result_ctrl_proc.Code == "1" && result_case_status.Code == "1" && result_fee_cate_workitem.Code == "1" && result_fo_tax_rate_name.Code == "1" && result_tax_type.Code == "1" && result_fc_cate.Code == "1" && result_currency.Code == "1" && result_customer.Code == "1" && result_case_type.Code == "1" && result_country.Code == "1" && result_apply_type.Code == "1" && result_business_type.Code == "1")
{
DataTable dt_ctrl_proc = (DataTable)result_ctrl_proc.Msg;
DataTable dt_case_status = (DataTable)result_case_status.Msg;
DataTable dt_fee_cate_workitem = (DataTable)result_fee_cate_workitem.Msg;
DataTable dt_fo_tax_rate_name = (DataTable)result_fo_tax_rate_name.Msg;
DataTable dt_tax_type = (DataTable)result_tax_type.Msg;
DataTable dt_fc_cate = (DataTable)result_fc_cate.Msg;
DataTable dt_currency = (DataTable)result_currency.Msg;
DataTable dt_customer = (DataTable)result_customer.Msg;
DataTable dt_case_type = (DataTable)result_case_type.Msg;
DataTable dt_country = (DataTable)result_country.Msg;
DataTable dt_apply_type = (DataTable)result_apply_type.Msg;
DataTable dt_business_type = (DataTable)result_business_type.Msg;
int total_check_failed = 0;
foreach (DataRow dr_excel in dt_excel.Rows)
{
CommonResponseMsg result_check = new CommonResponseMsg();
result_check.Code = "1";
result_check.Msg = "OK";
DataRow[] selected_ctrl_proc = null;
DataRow[] selected_case_status = null;
DataRow[] selected_fee_cate_workitem = null;
DataRow[] selected_fo_tax_rate_name = null;
DataRow[] selected_tax_type = null;
DataRow[] selected_fc_cate = null;
DataRow[] selected_currency = null;
DataRow[] selected_customer = null;
DataRow[] selected_case_type = null;
DataRow[] selected_country = null;
DataRow[] selected_apply_type = null;
DataRow[] selected_business_type = null;
DataTable dt_proc_info = null;
DataTable dt_fee_type = null;
DataRow dr_best_match_fee = null;
//檢查excel值是否合法
if (result_check.Code == "1")
result_check = CheckInputValid(dt_customer, "客户名称", dr_excel["客户名称"].ToString(), string.Format("customer_name = '{0}'", dr_excel["客户名称"].ToString()), true, ref selected_customer);
if (result_check.Code == "1")
result_check = CheckInputValid(dt_case_type, "案件类型", dr_excel["案件类型"].ToString(), string.Format("case_type_zh_cn = '{0}' or case_type_zh_tw = '{0}'", dr_excel["案件类型"].ToString()), true, ref selected_case_type);
if (result_check.Code == "1")
result_check = CheckInputValid(dt_country, "申请国家", dr_excel["申请国家"].ToString(), string.Format("country_id = '{0}'", dr_excel["申请国家"].ToString()), true, ref selected_country);
if (result_check.Code == "1")
result_check = CheckInputValid(dt_apply_type, "申请类型", dr_excel["申请类型"].ToString(), string.Format("(apply_type_zh_cn = '{0}' or apply_type_zh_tw = '{0}') and (country_id = '{1}' or country_id = 'ALL') and case_type_id = '{2}'", dr_excel["申请类型"].ToString(), selected_country.FirstOrDefault()["country_id"], selected_case_type.FirstOrDefault()["case_type_id"]), true, ref selected_apply_type);
if (result_check.Code == "1")
result_check = CheckInputValid(dt_business_type, "业务类型", dr_excel["业务类型"].ToString(), string.Format("(business_type_zh_cn = '{0}' or business_type_zh_tw = '{0}') and case_type_id = '{1}'", dr_excel["业务类型"].ToString(), selected_case_type.FirstOrDefault()["case_type_id"]), true, ref selected_business_type);
if (result_check.Code == "1")
{
result_check = CheckInputValid(dt_ctrl_proc, "处理事项", dr_excel["处理事项"].ToString(), string.Format("(ctrl_proc_zh_cn = '{0}' or ctrl_proc_zh_tw = '{0}') and (';'+country_id+';' like '%;{1};%' or country_id = 'ALL') and (';'+business_type_id+';' like '%;{2};%' or business_type_id = 'ALL') and (';'+apply_type_id+';' like '%;{3};%' or apply_type_id = 'ALL') and ';'+case_type_id+';' like '%;{4};%'",
dr_excel["处理事项"].ToString(),
selected_country.FirstOrDefault()["country_id"],
selected_business_type.FirstOrDefault()["business_type_id"],
selected_apply_type.FirstOrDefault()["apply_type_id"],
selected_case_type.FirstOrDefault()["case_type_id"]), true, ref selected_ctrl_proc);
}
if (result_check.Code == "1")
result_check = CheckInputValid(dt_case_status, "案件阶段", dr_excel["案件阶段"].ToString(), string.Format("(case_status_zh_cn = '{0}' or case_status_zh_tw = '{0}') and case_type_id = '{1}'", dr_excel["案件阶段"].ToString(), selected_case_type.FirstOrDefault()["case_type_id"]), false, ref selected_case_status);
if (result_check.Code == "1")
result_check = CheckInputValid(dt_fee_cate_workitem, "科目", dr_excel["科目"].ToString(), string.Format("text = '{0}' or text_zh_cn = '{0}' or text_zh_tw = '{0}'", dr_excel["科目"].ToString()), false, ref selected_fee_cate_workitem);
if (result_check.Code == "1")
result_check = CheckInputValid(dt_fc_cate, "程序名称", dr_excel["程序名称"].ToString(), string.Format("text_zh_cn = '{0}' or text_zh_tw = '{0}'", dr_excel["程序名称"].ToString()), false, ref selected_fc_cate);
if (result_check.Code == "1")
result_check = CheckInputValid(dt_currency, "币别", dr_excel["币别"].ToString(), string.Format("currency_id = '{0}'", dr_excel["币别"].ToString()), false, ref selected_currency);
if (result_check.Code == "1")
result_check = CheckInputValid(dt_fo_tax_rate_name, "税别", dr_excel["税别"].ToString(), string.Format("text = '{0}' or text_zh_cn = '{0}' or text_zh_tw = '{0}'", dr_excel["税别"].ToString()), false, ref selected_fo_tax_rate_name);
if (result_check.Code == "1")
result_check = CheckInputValid(dt_tax_type, "内含/外加", dr_excel["内含/外加"].ToString(), string.Format("text = '{0}' or text_zh_cn = '{0}' or text_zh_tw = '{0}'", dr_excel["内含/外加"].ToString()), false, ref selected_tax_type);
//CommonResponseMsg result_case_type = dal_base_info.GetDataByTable("*", "i_case_type");//案件類型
CommonResponseMsg result_case_info = dal_case_info.GetCaseInfoByCaseVolume("*", dr_excel["我方文号"].ToString());//案件信息
DataTable dt_case_info = (DataTable)result_case_info.Msg;
//檢查案件是否存在
if (result_check.Code == "1")
{
if (result_case_info.Code == "0" || dt_case_info.Rows.Count != 1)
{
result_check.Code = "0";
result_check.Msg = "此案號無法找到唯一的案件";
}
}
//檢查處理事項是否存在且唯一
if (result_check.Code == "1")
{
string proc_id = dr_excel["处理事项ID"].ToString();
if (string.IsNullOrEmpty(proc_id))
{
string case_volume = dr_excel["我方文号"].ToString();
string proc_name = dr_excel["处理事项"].ToString();
if (!string.IsNullOrEmpty(case_volume) && !string.IsNullOrEmpty(proc_name))
{
CommonResponseMsg result_proc_info = dal_proc_info.GetProcInfoByName("*", dr_excel["我方文号"].ToString(), dr_excel["处理事项"].ToString(), dr_excel["案件阶段"].ToString());
dt_proc_info = (DataTable)result_proc_info.Msg;
if (result_proc_info.Code == "0" || dt_proc_info.Rows.Count != 1)
{
result_check.Code = "0";
result_check.Msg = "此案号 + 处理事项名称无法找到唯一的处理事项";
}
}
else
{
result_check.Code = "0";
result_check.Msg = "需要有处理事项ID或是案号+处理事项名称";
}
}
else
{
CommonResponseMsg result_proc_info = dal_proc_info.GetProcInfo("proc_id", dr_excel["处理事项ID"].ToString());
dt_proc_info = (DataTable)result_proc_info.Msg;
if (result_proc_info.Code == "0" || dt_proc_info.Rows.Count != 1)
{
result_check.Code = "0";
result_check.Msg = "此ID无法找到唯一的处理事项";
}
}
}
//檢查工作項目是否存在
if (result_check.Code == "1")
{
CommonResponseMsg result_fee_type = dal_fee.GetFeeTypeByName("*",
selected_case_type.FirstOrDefault()["case_type_id"].ToString(),
selected_business_type.FirstOrDefault()["business_type_id"].ToString(),
selected_apply_type.FirstOrDefault()["apply_type_id"].ToString(),
selected_country.FirstOrDefault()["country_id"].ToString(),
selected_fee_cate_workitem.FirstOrDefault()["value"].ToString(),
selected_fc_cate.FirstOrDefault()["fc_cate_id"].ToString(),
dr_excel["费用名称"].ToString());
dt_fee_type = (DataTable)result_fee_type.Msg;
if (result_fee_type.Code == "0" || dt_fee_type.Rows.Count == 0)
{
result_check.Code = "0";
result_check.Msg = "无法找到唯一的工作项目";
}
else
{
dr_best_match_fee = get_best_match_fee(dt_fee_type);
}
}
//檢查是否存在相同費用
if (result_check.Code == "1")
{
CommonResponseMsg result_proc_fee_list = dal_fee.GetProcFeeList("*", dt_proc_info.Rows[0]["proc_id"].ToString(), dr_best_match_fee["fee_type_id"].ToString());
DataTable dt_proc_fee_list = (DataTable)result_proc_fee_list.Msg;
if (result_proc_fee_list.Code == "1" && dt_proc_fee_list.Rows.Count > 0)
{
result_check.Code = "2";
result_check.Msg = "該處理事項已存在相同費用";
}
}
dr_excel["check_status"] = result_check.Msg;
if (result_check.Code == "0")
{
total_check_failed++;
}
else if (result_check.Code == "2")
{
}
else if (result_check.Code == "1")
{
CommonResponseMsg result_agency_list = dal_case_info.GetpAgencyList("*", dt_case_info.Rows[0]["case_id"].ToString());
DataTable dt_agency_list = (DataTable)result_agency_list.Msg;
Dictionary<string, object> dic_proc_fee = new Dictionary<string, object>();
dic_proc_fee["invoice_no"] = "";
dic_proc_fee["workitem_desc"] = dr_best_match_fee["workitem_desc"].ToString();
dic_proc_fee["out_bill_no"] = "";
dic_proc_fee["notice_date"] = null;
dic_proc_fee["request_date"] = null;
dic_proc_fee["tax_id"] = selected_fo_tax_rate_name.Length > 0 ? selected_fo_tax_rate_name.FirstOrDefault()["value"] : "";
dic_proc_fee["recieve_currency_id"] = dr_excel["币别"].ToString();
dic_proc_fee["price"] = dr_excel["金额"].ToString();
dic_proc_fee["receive_due_date"] = null;
dic_proc_fee["request_no"] = "";
dic_proc_fee["pay_due_date"] = null;
dic_proc_fee["pay_type"] = "0";
dic_proc_fee["mid_amount"] = dr_excel["金额"].ToString();
dic_proc_fee["recieve_amount"] = "0";
dic_proc_fee["mid_is_divided"] = "0";
dic_proc_fee["receive_date"] = null;
dic_proc_fee["tax_type"] = selected_tax_type.Length > 0 ? selected_tax_type.FirstOrDefault()["value"] : "";
dic_proc_fee["coefficient"] = "1";
dic_proc_fee["ori_rate"] = null;
dic_proc_fee["fee_type_id"] = dr_best_match_fee["fee_type_id"].ToString();
dic_proc_fee["receive_status"] = "MW";
dic_proc_fee["fee_id"] = Guid.NewGuid().ToString().ToUpper();
dic_proc_fee["pay_date"] = null;
dic_proc_fee["mid_currency_id"] = dr_excel["币别"].ToString();
dic_proc_fee["remark2"] = "";
dic_proc_fee["proc_id"] = dt_proc_info.Rows[0]["proc_id"].ToString();
dic_proc_fee["is_confirm"] = 0;
dic_proc_fee["invoice_time"] = null;
dic_proc_fee["remark"] = "";
dic_proc_fee["currency_id"] = dr_excel["币别"].ToString();
dic_proc_fee["mid_rate"] = null;
dic_proc_fee["out_bill_date"] = null;
dic_proc_fee["amount"] = dr_excel["金额"].ToString();
dic_proc_fee["agency_id"] = (result_agency_list.Code == "1" && dt_agency_list.Rows.Count > 0) ? dt_agency_list.Rows[0]["agency_id"].ToString() : null;
dic_proc_fee["ori_is_divided"] = "0";
dic_proc_fee["update_time"] = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
dic_proc_fee["update_user_id"] = "5ce5b6fb-66d2-4281-a124-10034a6c0546";
dr_excel["import_data"] = JsonConvert.SerializeObject(dic_proc_fee);
dr_excel["id"] = dic_proc_fee["fee_id"];
}
}
response.Code = "1";
response.Msg = dt_excel;
if (total_check_failed > 0)
response.ExtraInfo = string.Format("{0}筆資料檢查異常,請修正後再次檢查", total_check_failed);
}
else
{
response.Code = "0";
response.Msg = "DB Access Fail";
}
}
else
{
response.Code = "0";
response.Msg = "File Parsed Fail";
}
}
else
{
response.Code = "0";
response.Msg = "No File";
}
}
else if(mode=="update")
{
DalProcInfo dal_proc_info = new DalProcInfo();
var data_to_upload = HttpContext.Current.Request.Form["data_to_upload"];
var obj_fee_list = JArray.Parse(data_to_upload);
Dictionary<string, object> dic_result = new Dictionary<string, object>();
foreach (var item in obj_fee_list)
{
var dic = item.ToObject<Dictionary<string, object>>();
//CommonResponseMsg result_update = new CommonResponseMsg();
//dic_result[item["fee_id"].ToString()] = "1";
CommonResponseMsg result_update = dal_proc_info.update_by_dict("insert", "p_proc_fee_list", dic);
dic_result[item["fee_id"].ToString()] = result_update.Msg;
LogHelper.WriteInfoLog(string.Format(@"{0};{1};{2}", result_update.Code, result_update.Msg, item["fee_id"]), this.GetType().Name+":"+ MethodBase.GetCurrentMethod().Name);
}
response.Code = "1";
response.Msg = dic_result;
}
else
{
response.Code = "0";
response.Msg = "Unknown Mode";
}
}
else
{
response.Code = "0";
response.Msg = "No Mode";
}
}
catch (Exception e)
{
response.Code = "0";
response.Msg = e.Message;
}
result.Content = new StringContent(JsonConvert.SerializeObject(response), System.Text.Encoding.UTF8, "application/json");
return result;
}
#endregion
protected DataRow get_best_match_fee(DataTable dt_fee_list)
{
DataRow temp_row = dt_fee_list.Rows[0];
if (dt_fee_list.Rows.Count > 1)
{
DataRow[] selected_fee1 = dt_fee_list.Select(string.Format("case_type_id <> 'ALL' and business_type_id <> 'ALL' and country_id <> 'ALL' and apply_type_id <> 'ALL'"));
DataRow[] selected_fee2 = dt_fee_list.Select(string.Format("case_type_id <> 'ALL' and business_type_id = 'ALL' and country_id <> 'ALL' and apply_type_id <> 'ALL'"));
DataRow[] selected_fee3 = dt_fee_list.Select(string.Format("case_type_id <> 'ALL' and business_type_id <> 'ALL' and country_id = 'ALL' and apply_type_id <> 'ALL'"));
if (selected_fee1.Length > 0)
temp_row = selected_fee1[0];
else if (selected_fee2.Length > 0)
temp_row = selected_fee2[0];
else if (selected_fee3.Length > 0)
temp_row = selected_fee3[0];
}
return temp_row;
}
#region 導入處理事項
[Route("ProcInfo/Import")]
[CorsHandle]
[HttpPost]
public HttpResponseMessage ProcInfoImport()
{
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
CommonResponseMsg response = new CommonResponseMsg();
try
{
var mode = HttpContext.Current.Request.Form["mode"];
if (!string.IsNullOrEmpty(mode))
{
if (mode == "check")
{
var file = HttpContext.Current.Request.Files.Count > 0 ? HttpContext.Current.Request.Files[0] : null;
if (file != null)
{
ExcelHelper excel_helper = new ExcelHelper();
CommonResponseMsg result_excel = excel_helper.LoadFromStream(file.InputStream, file.FileName);
DataSet ds_excel = (DataSet)result_excel.Msg;
if (result_excel.Code == "1" && ds_excel.Tables.Count > 0)
{
DataTable dt_excel = ds_excel.Tables[0];
dt_excel.Columns.Add("id", typeof(String));
dt_excel.Columns.Add("check_status", typeof(String));
dt_excel.Columns.Add("update_status", typeof(String));
dt_excel.Columns.Add("import_data", typeof(String));
DalProcInfo dal_proc_info = new DalProcInfo();
DalBaseInfo dal_base_info = new DalBaseInfo();
DalFee dal_fee = new DalFee();
DalCaseInfo dal_case_info = new DalCaseInfo();
CommonResponseMsg result_ctrl_proc = dal_proc_info.GetCtrlProc("ctrl_proc_id, case_type_id, ctrl_proc_zh_cn, ctrl_proc_zh_tw, proc_status_id, case_status_id");
CommonResponseMsg result_case_status = dal_proc_info.GetCaseStatus("case_status_id, case_type_id, case_status_zh_cn, case_status_zh_tw");
if (result_ctrl_proc.Code == "1" && result_case_status.Code == "1")
{
DataTable dt_ctrl_proc = (DataTable)result_ctrl_proc.Msg;
DataTable dt_case_status = (DataTable)result_case_status.Msg;
int total_check_failed = 0;
foreach (DataRow dr_proc in dt_excel.Rows)
{
CommonResponseMsg result_check = new CommonResponseMsg();
result_check.Code = "1";
result_check.Msg = "OK";
DataTable dt_proc_info = null;
CommonResponseMsg result_case_info = dal_case_info.GetCaseInfoByCaseVolume("*", dr_proc["我方文号"].ToString());//案件信息
DataTable dt_case_info = (DataTable)result_case_info.Msg;
//檢查案件是否存在
......@@ -259,6 +611,7 @@ namespace WebAPI.Controllers
}
}
Dictionary<string, object> dic_proc_info = new Dictionary<string, object>();
//檢查處理事項是否存在且唯一
if (result_check.Code == "1")
{
......@@ -269,12 +622,17 @@ namespace WebAPI.Controllers
string proc_name = dr_proc["处理事项"].ToString();
if (!string.IsNullOrEmpty(case_volume) && !string.IsNullOrEmpty(proc_name))
{
CommonResponseMsg result_proc_info = dal_proc_info.GetProcInfoByName("proc_id", dr_proc["我方文号"].ToString(), dr_proc["处理事项"].ToString(), dr_proc["案件阶段"].ToString());
if (result_proc_info.Code == "0" || ((DataTable)result_proc_info.Msg).Rows.Count != 1)
CommonResponseMsg result_proc_info = dal_proc_info.GetProcInfoByName("*", dr_proc["我方文号"].ToString(), dr_proc["处理事项"].ToString(), dr_proc["案件阶段"].ToString());
dt_proc_info = (DataTable)result_proc_info.Msg;
if (result_proc_info.Code == "0" || dt_proc_info.Rows.Count != 1)
{
result_check.Code = "0";
result_check.Msg = "此案号 + 处理事项名称无法找到唯一的处理事项";
}
else
{
dic_proc_info["proc_id"] = dt_proc_info.Rows[0]["proc_id"].ToString();
}
}
else
{
......@@ -285,47 +643,293 @@ namespace WebAPI.Controllers
else
{
CommonResponseMsg result_proc_info = dal_proc_info.GetProcInfo("proc_id", dr_proc["处理事项ID"].ToString());
if (result_proc_info.Code == "0" || ((DataTable)result_proc_info.Msg).Rows.Count != 1)
dt_proc_info = (DataTable)result_proc_info.Msg;
if (result_proc_info.Code == "0" || dt_proc_info.Rows.Count != 1)
{
result_check.Code = "0";
result_check.Msg = "此ID无法找到唯一的处理事项";
}
}
}
//檢查工作項目是否存在
if (result_check.Code == "1")
dr_proc["check_status"] = result_check.Msg;
if (result_check.Code == "0")
{
if (result_fee_cate_workitem.Code == "1" && result_fc_cate.Code == "1" && result_case_info.Code == "1")
total_check_failed++;
}
else
{
DataTable dt_fee_cate_workitem = (DataTable)result_fee_cate_workitem.Msg;
DataTable dt_fc_cate = (DataTable)result_fc_cate.Msg;
CommonResponseMsg result_agency_list = dal_case_info.GetpAgencyList("*", dt_case_info.Rows[0]["case_id"].ToString());
DataTable dt_agency_list = (DataTable)result_agency_list.Msg;
DataRow[] selected_fee_cate_workitem = dt_fee_cate_workitem.Select(string.Format("text = '{0}' or text_zh_cn = '{0}' or text_zh_tw = '{0}'", dr_proc["科目"].ToString()));
DataRow[] selected_fc_cate = dt_fc_cate.Select(string.Format("text_zh_cn = '{0}' or text_zh_tw = '{0}'", dr_proc["程序名称"].ToString()));
if (selected_fee_cate_workitem.Length > 0 && selected_fc_cate.Length > 0)
dic_proc_info["back_inventor_date"] = DateTime.Parse(dr_proc["返发明人日"].ToString()).ToString("yyyy-MM-dd");
dr_proc["id"] = dic_proc_info["proc_id"];
dr_proc["import_data"] = JsonConvert.SerializeObject(dic_proc_info);
}
}
response.Code = "1";
response.Msg = dt_excel;
if (total_check_failed > 0)
response.ExtraInfo = string.Format("{0}筆資料檢查異常,請修正後再次檢查", total_check_failed);
}
else
{
CommonResponseMsg result_fee_type = dal_fee.GetFeeTypeByName("fee_type_id", dt_case_info.Rows[0]["case_type_id"].ToString(), dt_case_info.Rows[0]["business_type_id"].ToString(), dt_case_info.Rows[0]["apply_type_id"].ToString(), dt_case_info.Rows[0]["country_id"].ToString(), selected_fee_cate_workitem.FirstOrDefault()["value"].ToString(), selected_fc_cate.FirstOrDefault()["fc_cate_id"].ToString(), dr_proc["工作项目"].ToString());
if(result_fee_type.Code=="0" || ((DataTable)result_fee_type.Msg).Rows.Count!=1)
response.Code = "0";
response.Msg = "DB Access Fail";
}
}
else
{
result_check.Msg = "无法找到唯一的工作项目";
response.Code = "0";
response.Msg = "File Parsed Fail";
}
}
else
{
result_check.Code = "0";
result_check.Msg = "科目或程序名称不正确";
response.Code = "0";
response.Msg = "No File";
}
}
else if (mode == "update")
{
DalProcInfo dal_proc_info = new DalProcInfo();
var data_to_upload = HttpContext.Current.Request.Form["data_to_upload"];
var obj_fee_list = JArray.Parse(data_to_upload);
Dictionary<string, object> dic_result = new Dictionary<string, object>();
foreach (var item in obj_fee_list)
{
var dic = item.ToObject<Dictionary<string, object>>();
CommonResponseMsg result_sql = dal_proc_info.update_by_dict("update", "p_proc_info", dic, "proc_id");
dic_result[item["proc_id"].ToString()] = result_sql.Msg;
}
response.Code = "1";
response.Msg = dic_result;
}
else
{
response.Code = "0";
response.Msg = "Unknown Mode";
}
}
else
{
response.Code = "0";
response.Msg = "No Mode";
}
}
catch (Exception e)
{
response.Code = "0";
response.Msg = e.Message;
}
result.Content = new StringContent(JsonConvert.SerializeObject(response), System.Text.Encoding.UTF8, "application/json");
return result;
}
#endregion
#region 根據規則生成處理事項費用
[Route("ProcInfo/FeeListForecast")]
[CorsHandle]
[HttpPost]
public HttpResponseMessage ProcInfoFeeListForecast()
{
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
CommonResponseMsg response = new CommonResponseMsg();
try
{
var mode = HttpContext.Current.Request.Form["mode"];
if (!string.IsNullOrEmpty(mode))
{
if (mode == "check")
{
var file = HttpContext.Current.Request.Files.Count > 0 ? HttpContext.Current.Request.Files[0] : null;
if (file != null)
{
ExcelHelper excel_helper = new ExcelHelper();
CommonResponseMsg result_excel = excel_helper.LoadFromStream(file.InputStream, file.FileName);
DataSet ds_excel = (DataSet)result_excel.Msg;
if (result_excel.Code == "1" && ds_excel.Tables.Count > 0)
{
DataTable dt_excel = ds_excel.Tables[0];
dt_excel.Columns.Add("id", typeof(String));
dt_excel.Columns.Add("check_status", typeof(String));
dt_excel.Columns.Add("update_status", typeof(String));
dt_excel.Columns.Add("import_data", typeof(String));
DalProcInfo dal_proc_info = new DalProcInfo();
DalBaseInfo dal_base_info = new DalBaseInfo();
DalFee dal_fee = new DalFee();
DalCaseInfo dal_case_info = new DalCaseInfo();
CommonResponseMsg result_ctrl_proc = dal_proc_info.GetCtrlProc("ctrl_proc_id, case_type_id, ctrl_proc_zh_cn, ctrl_proc_zh_tw, proc_status_id, case_status_id, country_id, business_type_id, apply_type_id");
CommonResponseMsg result_case_status = dal_proc_info.GetCaseStatus("case_status_id, case_type_id, case_status_zh_cn, case_status_zh_tw");
CommonResponseMsg result_fee_cate_workitem = dal_base_info.GetDictionaryByName("*", "fee_cate_workitem");//科目
CommonResponseMsg result_fo_tax_rate_name = dal_base_info.GetDictionaryByName("*", "fo_tax_rate_name");//稅別
CommonResponseMsg result_tax_type = dal_base_info.GetDictionaryByName("*", "tax_type");//稅計算類型
CommonResponseMsg result_fc_cate = dal_base_info.GetFcCategory();//程序名稱
CommonResponseMsg result_currency = dal_base_info.GetDataByTable("*", "i_currency");//幣別
CommonResponseMsg result_customer = dal_base_info.GetDataByTable("customer_id, customer_name, customer_name_en", "c_customer", true);//客戶
CommonResponseMsg result_case_type = dal_base_info.GetDataByTable("*", "i_case_type");//案件類型
CommonResponseMsg result_country = dal_base_info.GetDataByTable("*", "i_country");//國家
CommonResponseMsg result_apply_type = dal_base_info.GetDataByTable("*", "i_apply_type");//申請類型
CommonResponseMsg result_business_type = dal_base_info.GetDataByTable("*", "i_business_type");//業務類型
if (result_ctrl_proc.Code == "1" && result_case_status.Code == "1" && result_fee_cate_workitem.Code == "1" && result_fo_tax_rate_name.Code == "1" && result_tax_type.Code == "1" && result_fc_cate.Code == "1" && result_currency.Code == "1" && result_customer.Code == "1" && result_case_type.Code == "1" && result_country.Code == "1" && result_apply_type.Code == "1" && result_business_type.Code=="1")
{
DataTable dt_ctrl_proc = (DataTable)result_ctrl_proc.Msg;
DataTable dt_case_status = (DataTable)result_case_status.Msg;
DataTable dt_fee_cate_workitem = (DataTable)result_fee_cate_workitem.Msg;
DataTable dt_fo_tax_rate_name = (DataTable)result_fo_tax_rate_name.Msg;
DataTable dt_tax_type = (DataTable)result_tax_type.Msg;
DataTable dt_fc_cate = (DataTable)result_fc_cate.Msg;
DataTable dt_currency = (DataTable)result_currency.Msg;
DataTable dt_customer = (DataTable)result_customer.Msg;
DataTable dt_case_type = (DataTable)result_case_type.Msg;
DataTable dt_country = (DataTable)result_country.Msg;
DataTable dt_apply_type = (DataTable)result_apply_type.Msg;
DataTable dt_business_type = (DataTable)result_business_type.Msg;
Dictionary<string, object> dic_fee_rule = new Dictionary<string, object>();
int total_check_failed = 0;
foreach (DataRow dr_excel in dt_excel.Rows)
{
CommonResponseMsg result_check = new CommonResponseMsg();
result_check.Code = "1";
result_check.Msg = "OK";
DataRow[] selected_ctrl_proc = null;
DataRow[] selected_case_status = null;
DataRow[] selected_fee_cate_workitem = null;
DataRow[] selected_fo_tax_rate_name = null;
DataRow[] selected_tax_type = null;
DataRow[] selected_fc_cate = null;
DataRow[] selected_currency = null;
DataRow[] selected_customer = null;
DataRow[] selected_case_type = null;
DataRow[] selected_country = null;
DataRow[] selected_apply_type = null;
DataRow[] selected_business_type = null;
DataTable dt_proc_info = null;
DataTable dt_fee_type = null;
//檢查excel值是否合法
if (result_check.Code == "1")
result_check = CheckInputValid(dt_customer, "客户名称", dr_excel["客户名称"].ToString(), string.Format("customer_name = '{0}'", dr_excel["客户名称"].ToString()), true, ref selected_customer);
if (result_check.Code == "1")
result_check = CheckInputValid(dt_case_type, "案件类型", dr_excel["案件类型"].ToString(), string.Format("case_type_zh_cn = '{0}' or case_type_zh_tw = '{0}'", dr_excel["案件类型"].ToString()), true, ref selected_case_type);
if (result_check.Code == "1")
result_check = CheckInputValid(dt_country, "申请国家", dr_excel["申请国家"].ToString(), string.Format("country_id = '{0}'", dr_excel["申请国家"].ToString()), true, ref selected_country);
if (result_check.Code == "1")
result_check = CheckInputValid(dt_apply_type, "申请类型", dr_excel["申请类型"].ToString(), string.Format("(apply_type_zh_cn = '{0}' or apply_type_zh_tw = '{0}') and (country_id = '{1}' or country_id = 'ALL') and case_type_id = '{2}'", dr_excel["申请类型"].ToString(), selected_country.FirstOrDefault()["country_id"], selected_case_type.FirstOrDefault()["case_type_id"]), true, ref selected_apply_type);
if (result_check.Code == "1")
result_check = CheckInputValid(dt_business_type, "业务类型", dr_excel["业务类型"].ToString(), string.Format("(business_type_zh_cn = '{0}' or business_type_zh_tw = '{0}') and case_type_id = '{1}'", dr_excel["业务类型"].ToString(), selected_case_type.FirstOrDefault()["case_type_id"]), true, ref selected_business_type);
if (result_check.Code == "1")
{
result_check = CheckInputValid(dt_ctrl_proc, "处理事项", dr_excel["处理事项"].ToString(), string.Format("(ctrl_proc_zh_cn = '{0}' or ctrl_proc_zh_tw = '{0}') and (';'+country_id+';' like '%;{1};%' or country_id = 'ALL') and (';'+business_type_id+';' like '%;{2};%' or business_type_id = 'ALL') and (';'+apply_type_id+';' like '%;{3};%' or apply_type_id = 'ALL') and ';'+case_type_id+';' like '%;{4};%'",
dr_excel["处理事项"].ToString(),
selected_country.FirstOrDefault()["country_id"],
selected_business_type.FirstOrDefault()["business_type_id"],
selected_apply_type.FirstOrDefault()["apply_type_id"],
selected_case_type.FirstOrDefault()["case_type_id"]), true, ref selected_ctrl_proc);
}
if (result_check.Code == "1")
result_check = CheckInputValid(dt_case_status, "案件阶段", dr_excel["案件阶段"].ToString(), string.Format("(case_status_zh_cn = '{0}' or case_status_zh_tw = '{0}') and case_type_id = '{1}'", dr_excel["案件阶段"].ToString(), selected_case_type.FirstOrDefault()["case_type_id"]), false, ref selected_case_status);
if (result_check.Code == "1")
result_check = CheckInputValid(dt_fee_cate_workitem, "科目", dr_excel["科目"].ToString(), string.Format("text = '{0}' or text_zh_cn = '{0}' or text_zh_tw = '{0}'", dr_excel["科目"].ToString()), false, ref selected_fee_cate_workitem);
if (result_check.Code == "1")
result_check = CheckInputValid(dt_fc_cate, "程序名称", dr_excel["程序名称"].ToString(), string.Format("text_zh_cn = '{0}' or text_zh_tw = '{0}'", dr_excel["程序名称"].ToString()), false, ref selected_fc_cate);
if (result_check.Code == "1")
result_check = CheckInputValid(dt_currency, "币别", dr_excel["币别"].ToString(), string.Format("currency_id = '{0}'", dr_excel["币别"].ToString()), false, ref selected_currency);
if (result_check.Code == "1")
result_check = CheckInputValid(dt_fo_tax_rate_name, "税别", dr_excel["税别"].ToString(), string.Format("text = '{0}' or text_zh_cn = '{0}' or text_zh_tw = '{0}'", dr_excel["税别"].ToString()), false, ref selected_fo_tax_rate_name);
if (result_check.Code == "1")
result_check = CheckInputValid(dt_tax_type, "内含/外加", dr_excel["内含/外加"].ToString(), string.Format("text = '{0}' or text_zh_cn = '{0}' or text_zh_tw = '{0}'", dr_excel["内含/外加"].ToString()), false, ref selected_tax_type);
//檢查工作項目是否存在
if (result_check.Code == "1")
{
CommonResponseMsg result_fee_type = dal_fee.GetFeeTypeByRule("*",
selected_case_type.FirstOrDefault()["case_type_id"].ToString(),
selected_business_type.FirstOrDefault()["business_type_id"].ToString(),
selected_apply_type.FirstOrDefault()["apply_type_id"].ToString(),
selected_country.FirstOrDefault()["country_id"].ToString(),
selected_fee_cate_workitem.FirstOrDefault()["value"].ToString(),
selected_fc_cate.FirstOrDefault()["fc_cate_id"].ToString(),
dr_excel["费用名称"].ToString());
dt_fee_type = (DataTable)result_fee_type.Msg;
if (result_fee_type.Code == "0" || dt_fee_type.Rows.Count == 0)
{
result_check.Code = "0";
result_check.Msg = "需要有我方文号、科目、程序名称以及费用名称";
result_check.Msg = "无法找到唯一的工作项目";
}
else
{
string rule_name = string.Format("{0}_{1}_{2}_{3}_{4}_{5}_{6}_{7}",
(selected_customer != null ? selected_customer.FirstOrDefault()["customer_id"] : ""),
(selected_case_type != null ? selected_case_type.FirstOrDefault()["case_type_id"] : ""),
(selected_business_type != null ? selected_business_type.FirstOrDefault()["business_type_id"] : ""),
(selected_country != null ? selected_country.FirstOrDefault()["country_id"] : ""),
(selected_apply_type != null ? selected_apply_type.FirstOrDefault()["apply_type_id"] : ""),
(selected_ctrl_proc != null ? selected_ctrl_proc.FirstOrDefault()["ctrl_proc_id"] : ""),
(selected_case_status != null ? selected_case_status.FirstOrDefault()["case_status_id"] : ""),
(dr_excel["费用名称"].ToString().Contains("英文PCT")?"1":"0"));
rule_name = rule_name.Replace("ALL", ".+");
if (!dic_fee_rule.Keys.Contains(rule_name))
{
dic_fee_rule[rule_name] = new List<DataRow>();
}
dr_proc["check_status"] = result_check.Msg;
((List<DataRow>)dic_fee_rule[rule_name]).Add(dr_excel);
}
}
//檢查是否存在相同費用
/*CommonResponseMsg result_proc_fee_list = dal_fee.GetProcFeeList("*", dt_proc_info.Rows[0]["proc_id"].ToString(), dt_fee_type.Rows[0]["fee_type_id"].ToString());
DataTable dt_proc_fee_list = (DataTable)result_proc_fee_list.Msg;
if (result_proc_fee_list.Code == "1" && dt_proc_fee_list.Rows.Count > 0)
{
result_check.Code = "2";
result_check.Msg = "該處理事項已存在相同費用";
}*/
dr_excel["check_status"] = result_check.Msg;
if (result_check.Code == "0")
{
total_check_failed++;
}
else if (result_check.Code == "2")
{
}
else if (result_check.Code == "1")
{
}
}
response.Code = "1";
response.Msg = dt_excel;
if (total_check_failed > 0)
response.ExtraInfo = string.Format("{0}筆資料檢查異常,請修正後再次檢查", total_check_failed);
else
{
//從excel獲取客戶清單
DataView view = new DataView(dt_excel);
DataTable dt_distinct_customer = view.ToTable(true, "客户名称");
List<string> list_customer_id = new List<string>();
foreach (DataRow dr in dt_distinct_customer.Rows)
{
DataRow selected_customer = dt_customer.Select(string.Format("customer_name='{0}'", dr[0])).FirstOrDefault();
if (selected_customer != null)
{
string customer_id = selected_customer["customer_id"].ToString();
list_customer_id.Add(customer_id);
//break;
}
}
CommonResponseMsg result_proc_info_list_for_forecast = dal_proc_info.GetProcInfoListForForecast(string.Join(",", list_customer_id.ToArray()), "create_time", "2021-01-01", "");
DataTable dt_output = CreateFeeForecast((DataTable)result_proc_info_list_for_forecast.Msg, dic_fee_rule);
response.Code = "2";
response.Msg = dt_output;
}
}
else
{
......@@ -344,7 +948,38 @@ namespace WebAPI.Controllers
response.Code = "0";
response.Msg = "No File";
}
//DataSet ds = excel_helper.LoadFromStream();
}
else if (mode == "update")
{
DalProcInfo dal_proc_info = new DalProcInfo();
var data_to_upload = HttpContext.Current.Request.Form["data_to_upload"];
var obj_fee_list = JArray.Parse(data_to_upload);
Dictionary<string, object> dic_result = new Dictionary<string, object>();
foreach (var item in obj_fee_list)
{
var dic = item.ToObject<Dictionary<string, object>>();
//CommonResponseMsg result_update = new CommonResponseMsg();
//dic_result[item["fee_id"].ToString()] = "1";
CommonResponseMsg result_update = dal_proc_info.update_by_dict("insert", "p_proc_fee_list", dic);
dic_result[item["fee_id"].ToString()] = result_update.Msg;
LogHelper.WriteInfoLog(string.Format(@"{0};{1};{2}", result_update.Code, result_update.Msg, item["fee_id"]), this.GetType().Name + ":" + MethodBase.GetCurrentMethod().Name);
}
response.Code = "1";
response.Msg = dic_result;
}
else
{
response.Code = "0";
response.Msg = "Unknown Mode";
}
}
else
{
response.Code = "0";
response.Msg = "No Mode";
}
}
catch (Exception e)
{
......@@ -356,6 +991,133 @@ namespace WebAPI.Controllers
}
#endregion
protected CommonResponseMsg CheckInputValid(DataTable dt, string name, string value, string condition, bool is_required, ref DataRow[] selected)
{
CommonResponseMsg result = new CommonResponseMsg();
result.Code = "1";
result.Msg = "OK";
if (string.IsNullOrEmpty(value))
{
if (is_required)
{
result.Code = "0";
result.Msg = name + "需填寫";
}
}
else
{
if (value == "ALL")
{
DataRow[] temp_rows = new DataRow[1];
DataRow temp_row = dt.NewRow();
temp_row[0] = "ALL";
temp_rows[0] = temp_row;
selected = temp_rows;
}
else
{
selected = dt.Select(condition);
}
if (selected.Length == 0)
{
result.Code = "0";
result.Msg = "無此" + name;
}
}
return result;
}
protected DataTable CreateFeeForecast(DataTable dt_proc_list, Dictionary<string, object> dic_rule)
{
DataTable dt = new DataTable();
dt.Columns.Add("我方文号", typeof(String));
dt.Columns.Add("案件类型", typeof(String));
dt.Columns.Add("业务类型", typeof(String));
dt.Columns.Add("申请国家", typeof(String));
dt.Columns.Add("申请类型", typeof(String));
dt.Columns.Add("客户名称", typeof(String));
dt.Columns.Add("处理事项ID", typeof(String));
dt.Columns.Add("处理事项", typeof(String));
dt.Columns.Add("案件阶段", typeof(String));
dt.Columns.Add("科目", typeof(String));
dt.Columns.Add("程序名称", typeof(String));
dt.Columns.Add("费用名称", typeof(String));
dt.Columns.Add("金额", typeof(Decimal));
dt.Columns.Add("币别", typeof(String));
dt.Columns.Add("税别", typeof(String));
dt.Columns.Add("内含/外加", typeof(String));
dt.Columns.Add("缴费期限", typeof(String));
dt.Columns.Add("备注", typeof(String));
foreach (DataRow dr in dt_proc_list.Rows)
{
if (dr["case_volume"].ToString() == "SZ190740-CN")
{
string a = "";
}
string rule_name = string.Format("{0}_{1}_{2}_{3}_{4}_{5}_{6}_{7}",
dr["customer_id"],
dr["case_type_id"],
dr["business_type_id"],
dr["country_id"],
dr["apply_type_id"],
dr["ctrl_proc_id"],
dr["case_status_id"],
(dr["country_id"].ToString() == "WO" && !string.IsNullOrEmpty(dr["case_name_en"].ToString()) ? "1" : "0"));
DataRow new_row = dt.NewRow();
new_row["我方文号"] = dr["case_volume"];
new_row["案件类型"] = dr["case_type_zh_cn"];
new_row["业务类型"] = dr["business_type_zh_cn"];
new_row["申请国家"] = dr["country_id"];
new_row["申请类型"] = dr["apply_type_zh_cn"];
new_row["客户名称"] = dr["customer_name"];
new_row["处理事项ID"] = dr["proc_id"];
new_row["处理事项"] = dr["ctrl_proc_zh_cn"];
new_row["案件阶段"] = dr["case_status_zh_cn"];
List<DataRow> rule_fired = null;
foreach (string key in dic_rule.Keys)
{
Match m = Regex.Match(rule_name, key, RegexOptions.IgnoreCase);
if (m.Length > 0)
{
rule_fired = (List<DataRow>)dic_rule[key];
break;
}
}
if (rule_fired != null && rule_fired.Count > 0)
{
foreach (DataRow dr_rule in rule_fired)
{
DataRow rule_row = dt.NewRow();
rule_row.ItemArray = new_row.ItemArray.Clone() as object[];
if ((dr["ctrl_proc_zh_cn"].ToString() == "新申请" || dr["ctrl_proc_zh_cn"].ToString() == "申请前检索") && dr["last_flag"] == DBNull.Value)
{
//新申请跟申请前检索只有最後一次收費
}
else
{
rule_row["科目"] = dr_rule["科目"];
rule_row["程序名称"] = dr_rule["程序名称"];
rule_row["费用名称"] = dr_rule["费用名称"];
rule_row["金额"] = Convert.ToDecimal(dr_rule["金额"]);
rule_row["币别"] = dr_rule["币别"];
rule_row["税别"] = dr_rule["税别"];
rule_row["内含/外加"] = dr_rule["内含/外加"];
rule_row["缴费期限"] = "";
rule_row["备注"] = "";
}
dt.Rows.Add(rule_row);
}
}
else
{
dt.Rows.Add(new_row);
}
}
return dt;
}
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using WebAPI.Models;
using WebAPI.Tool;
namespace WebAPI.Dal
{
public class Dal
{
protected SqlServerHelper sql_server_helper = new SqlServerHelper();
public CommonResponseMsg update_by_dict(string type, string table_name, Dictionary<string, object> dic, string where_col_name = null)
{
CommonResponseMsg result = new CommonResponseMsg();
try
{
CommonResponseMsg result_sql = DicToSql(type, table_name, dic, where_col_name);
if (result_sql.Code == "1")
{
result.Code = "1";
result.Msg = sql_server_helper.ExecuteSqlCommand(result_sql.Msg.ToString());
}
}
catch(Exception e)
{
result.Code = "0";
result.Msg = e.Message;
}
return result;
}
public static CommonResponseMsg DicToSql(string type, string table_name, Dictionary<string, object> dic, string where_col_name = null)
{
CommonResponseMsg result = new CommonResponseMsg();
try
{
string sql = "";
List<string> list_col = new List<string>();
List<string> list_val = new List<string>();
if (type == "insert")
{
foreach (string key in dic.Keys)
{
if (dic[key] != null)
{
list_col.Add(key);
if (dic[key].GetType() == typeof(int))
{
list_val.Add(dic[key].ToString());
}
else
{
list_val.Add(string.Format("'{0}'", dic[key].ToString()));
}
}
}
sql = string.Format("insert into {0} ({1}) values({2})", table_name, string.Join(",", list_col), string.Join(",", list_val));
result.Code = "1";
result.Msg = sql;
}
else if (type == "update")
{
sql = string.Format("UPDATE {0} set ", table_name);
int i = 0;
foreach (string key in dic.Keys)
{
if (key == where_col_name || dic[key] == null)
{
continue;
}
if (i > 0)
{
sql += ", ";
}
if (dic[key].GetType() == typeof(int))
{
sql += string.Format("{0} = {1}", key, dic[key].ToString());
}
else
{
sql += string.Format("{0} = '{1}'", key, dic[key].ToString());
}
i++;
}
if (string.IsNullOrEmpty(dic[where_col_name].ToString()))
{
result.Code = "0";
result.Msg = "where col empty";
}
else
{
if (dic[where_col_name].GetType() == typeof(int))
sql += string.Format(" where {0} = {1}", where_col_name, dic[where_col_name].ToString());
else
sql += string.Format(" where {0} = '{1}'", where_col_name, dic[where_col_name].ToString());
result.Code = "1";
result.Msg = sql;
}
}
}
catch (Exception err)
{
result.Code = "0";
result.Msg = err.Message;
}
return result;
}
}
}
\ No newline at end of file
......@@ -8,10 +8,8 @@ using WebAPI.Tool;
namespace WebAPI.Dal
{
public class DalBaseInfo
public class DalBaseInfo : Dal
{
SqlServerHelper sql_server_helper = new SqlServerHelper();
public CommonResponseMsg GetDictionaryByName(string field = "*", string dictionary_name = null)
{
CommonResponseMsg result = new CommonResponseMsg();
......@@ -60,15 +58,33 @@ namespace WebAPI.Dal
return result;
}
public CommonResponseMsg GetDataByTable(string field, string table_name, string primary_key = null, string id = null)
public CommonResponseMsg GetDataByTable(string field, string table_name, bool? is_enabled=null, string primary_key = null, string id = null)
{
CommonResponseMsg result = new CommonResponseMsg();
try
{
string sql = string.Format(@"SELECT {0} FROM dbo.{1}", field, table_name);
Dictionary<string, object> dic_condition = new Dictionary<string, object>();
if (!string.IsNullOrEmpty(id))
{
sql += string.Format(@" where {0} = '{1}'", primary_key, id);
dic_condition[primary_key] = id;
}
if (is_enabled != null)
{
dic_condition["is_enabled"] = is_enabled;
}
int i = 0;
foreach(string key in dic_condition.Keys)
{
if (i > 0)
sql += " and ";
else
sql += " where ";
if (dic_condition[key].GetType() == typeof(int))
sql += string.Format(@"{0} = {1}", key, dic_condition[key]);
else
sql += string.Format(@"{0} = '{1}'", key, dic_condition[key]);
i++;
}
DataTable dt = sql_server_helper.GetTable(sql);
......
......@@ -8,10 +8,8 @@ using WebAPI.Tool;
namespace WebAPI.Dal
{
public class DalCaseInfo
public class DalCaseInfo : Dal
{
SqlServerHelper sql_server_helper = new SqlServerHelper();
public CommonResponseMsg GetCaseInfoByCaseVolume(string field = "*", string case_volume = null)
{
CommonResponseMsg result = new CommonResponseMsg();
......@@ -35,5 +33,29 @@ namespace WebAPI.Dal
}
return result;
}
public CommonResponseMsg GetpAgencyList(string field, string obj_id = null)
{
CommonResponseMsg result = new CommonResponseMsg();
try
{
string sql = string.Format(@"SELECT {0} FROM dbo.p_agency_list", field);
sql += " where is_enabled = 1";
if (!string.IsNullOrEmpty(obj_id))
{
sql += string.Format(@" and obj_id = '{0}'", obj_id);
}
DataTable dt = sql_server_helper.GetTable(sql);
result.Code = "1";
result.Msg = dt;
}
catch (Exception err)
{
result.Code = "0";
result.Msg = err.Message;
}
return result;
}
}
}
\ No newline at end of file
......@@ -8,10 +8,8 @@ using WebAPI.Tool;
namespace WebAPI.Dal
{
public class DalFee
public class DalFee : Dal
{
SqlServerHelper sql_server_helper = new SqlServerHelper();
public CommonResponseMsg GetFeeTypeByName(string field, string case_type_id, string business_type_id, string apply_type_id, string country_id, string fee_cate_workitem, string fc_cate, string fee_type_name)
{
CommonResponseMsg result = new CommonResponseMsg();
......@@ -21,19 +19,19 @@ namespace WebAPI.Dal
sql += " where is_enabled = 1 and is_work_item = 1";
if (!string.IsNullOrEmpty(case_type_id))
{
sql += string.Format(@" and case_type_id = '{0}'", case_type_id);
sql += string.Format(@" and (concat(';',case_type_id,';') like '%;{0};%' or case_type_id = 'ALL')", case_type_id);
}
if (!string.IsNullOrEmpty(business_type_id))
{
sql += string.Format(@" and business_type_id = '{0}'", business_type_id);
sql += string.Format(@" and (concat(';',business_type_id,';') like '%;{0};%' or business_type_id = 'ALL')", business_type_id);
}
if (!string.IsNullOrEmpty(apply_type_id))
{
sql += string.Format(@" and apply_type_id = '{0}'", apply_type_id);
sql += string.Format(@" and (concat(';',apply_type_id,';') like '%;{0};%' or apply_type_id = 'ALL')", apply_type_id);
}
if (!string.IsNullOrEmpty(country_id))
{
sql += string.Format(@" and country_id = '{0}'", country_id);
sql += string.Format(@" and (concat(';',country_id,';') like '%;{0};%' or country_id = 'ALL')", country_id);
}
if (!string.IsNullOrEmpty(fee_cate_workitem))
{
......@@ -59,5 +57,73 @@ namespace WebAPI.Dal
}
return result;
}
public CommonResponseMsg GetFeeTypeByRule(string field, string case_type_id, string business_type_id, string apply_type_id, string country_id, string fee_cate_workitem, string fc_cate, string fee_type_name)
{
CommonResponseMsg result = new CommonResponseMsg();
try
{
string sql = string.Format(@"SELECT {0} FROM dbo.i_fee_type", field);
sql += " where is_enabled = 1 and is_work_item = 1";
if (!string.IsNullOrEmpty(case_type_id) && case_type_id != "ALL")
{
sql += string.Format(@" and (concat(';',case_type_id,';') like '%;{0};%' or case_type_id = 'ALL')", case_type_id);
}
if (!string.IsNullOrEmpty(business_type_id) && business_type_id != "ALL")
{
sql += string.Format(@" and (concat(';',business_type_id,';') like '%;{0};%' or business_type_id = 'ALL')", business_type_id);
}
if (!string.IsNullOrEmpty(apply_type_id) && apply_type_id != "ALL")
{
sql += string.Format(@" and (concat(';',apply_type_id,';') like '%;{0};%' or apply_type_id = 'ALL')", apply_type_id);
}
if (!string.IsNullOrEmpty(country_id) && country_id != "ALL")
{
sql += string.Format(@" and (concat(';',country_id,';') like '%;{0};%' or country_id = 'ALL')", country_id);
}
if (!string.IsNullOrEmpty(fee_cate_workitem))
{
sql += string.Format(@" and fee_cate_workitem = '{0}'", fee_cate_workitem);
}
if (!string.IsNullOrEmpty(fc_cate))
{
sql += string.Format(@" and fc_cate_id = '{0}'", fc_cate);
}
if (!string.IsNullOrEmpty(fee_type_name))
{
sql += string.Format(@" and (fee_type_zh_cn = '{0}' or fee_type_zh_tw = '{0}')", fee_type_name);
}
DataTable dt = sql_server_helper.GetTable(sql);
result.Code = "1";
result.Msg = dt;
}
catch (Exception err)
{
result.Code = "0";
result.Msg = err.Message;
}
return result;
}
public CommonResponseMsg GetProcFeeList(string field, string proc_id, string fee_type_id)
{
CommonResponseMsg result = new CommonResponseMsg();
try
{
string sql = string.Format(@"SELECT {0} FROM dbo.p_proc_fee_list", field);
sql += string.Format(" where proc_id = '{0}' and fee_type_id = '{1}'", proc_id, fee_type_id);
DataTable dt = sql_server_helper.GetTable(sql);
result.Code = "1";
result.Msg = dt;
}
catch (Exception err)
{
result.Code = "0";
result.Msg = err.Message;
}
return result;
}
}
}
\ No newline at end of file
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
......@@ -8,9 +9,8 @@ using WebAPI.Tool;
namespace WebAPI.Dal
{
public class DalProcInfo
public class DalProcInfo : Dal
{
SqlServerHelper sql_server_helper = new SqlServerHelper();
public CommonResponseMsg GetCtrlProc(string field = "*" ,string ctrl_proc_id = null, string ctrl_proc_name = null)
{
CommonResponseMsg result = new CommonResponseMsg();
......@@ -111,7 +111,7 @@ namespace WebAPI.Dal
}
if (!string.IsNullOrEmpty(proc_name))
{
sql += string.Format(@" and (ctrl_proc_zh_cn = '{0}' or ctrl_proc_zh_cn = '{0}')", proc_name);
sql += string.Format(@" and (ctrl_proc_zh_cn = '{0}' or ctrl_proc_zh_tw = '{0}')", proc_name);
}
if (!string.IsNullOrEmpty(case_status_name))
{
......@@ -129,5 +129,183 @@ namespace WebAPI.Dal
}
return result;
}
public CommonResponseMsg GetProcInfoListForForecast(string customer_id, string time_field, string s_time, string e_time)
{
CommonResponseMsg result = new CommonResponseMsg();
try
{
string sql_s_time = "";
string sql_e_time = "";
string sql_customer = "";
if (!string.IsNullOrEmpty(s_time))
{
sql_s_time = string.Format("AND ppi.{0} >= '{1} 00:00:00'", time_field, s_time);
}
if (!string.IsNullOrEmpty(e_time))
{
sql_e_time = string.Format("AND ppi.{0} <= '{1} 23:59:59'", time_field, e_time);
}
if (!string.IsNullOrEmpty(customer_id))
{
sql_customer += "AND pci.customer_id in('" + String.Join("','", customer_id.Split(',')) + "')";
}
string sql = string.Format(@"SELECT ppi.proc_id, pci.case_volume, pci.case_name, pci.case_name_en, cc.customer_id, cc.customer_name
, ict.case_type_id, ict.case_type_zh_cn,
ibt.business_type_id, ibt.business_type_zh_cn,
ic.country_id, ic.country_zh_cn,
iat.apply_type_id, iat.apply_type_zh_cn,
icp.ctrl_proc_id, icp.ctrl_proc_zh_cn,
ics.case_status_id, ics.case_status_zh_cn,
ppi.create_time,
last_one.last_flag
FROM dbo.p_proc_info ppi
INNER JOIN dbo.p_case_info pci ON ppi.case_id = pci.case_id
INNER JOIN dbo.c_customer cc ON pci.customer_id = cc.customer_id
INNER JOIN dbo.i_case_type ict ON pci.case_type_id = ict.case_type_id
INNER JOIN dbo.i_country ic ON pci.country_id = ic.country_id
INNER JOIN dbo.i_apply_type iat on pci.apply_type_id = iat.apply_type_id
INNER JOIN dbo.i_ctrl_proc icp ON ppi.ctrl_proc_id = icp.ctrl_proc_id
LEFT JOIN dbo.i_case_status ics ON ppi.review_stage = ics.case_status_id
INNER JOIN dbo.i_business_type ibt ON pci.business_type_id = ibt.business_type_id
LEFT JOIN (
SELECT ppi.case_id, ppi.ctrl_proc_id, 1 AS last_flag, MAX(ppi.create_time) AS create_time
FROM dbo.p_proc_info ppi,dbo.p_case_info pci
WHERE ppi.is_enabled = 1
{0}
{1}
{2}
AND ppi.ctrl_proc_id IN ('6DD56B2B-1E1A-4E8B-9AC0-760CD305506A','E18F6EC7-0343-4431-9F30-BB86D0AF22B6')
AND ppi.case_id = pci.case_id
AND pci.case_type_id = '31D1A147-2931-43B5-94AE-B72B1525BA8A'
GROUP BY ppi.case_id, ppi.ctrl_proc_id
) last_one ON ppi.case_id = last_one.case_id and ppi.ctrl_proc_id = last_one.ctrl_proc_id and ppi.create_time = last_one.create_time
WHERE ppi.is_enabled = 1
AND icp.ctrl_proc_id IN ('6DD56B2B-1E1A-4E8B-9AC0-760CD305506A','8b96378e-05a0-4a8d-b3d1-39af92fddaf5','E18F6EC7-0343-4431-9F30-BB86D0AF22B6')
AND ict.case_type_id = '31D1A147-2931-43B5-94AE-B72B1525BA8A'
{0}
{1}
{2}", sql_s_time, sql_e_time, sql_customer);
DataTable dt = sql_server_helper.GetTable(sql);
result.Code = "1";
result.Msg = dt;
}
catch (Exception err)
{
result.Code = "0";
result.Msg = err.Message;
}
return result;
}
public AnnualInfo GetAnnualInfo(int proc_stage, string case_type_id, string country_id, string apply_type_id)
{
string sql = "select af.annual_fee_id, af.case_type_id, af.country_id, af.apply_type_id, af.begin_type, af.currency_id, af.update_user_id, af.update_time, fc.config_id, fc.year_from, \r\n fc.year_to, fc.basic_fee, fc.basic_fee_small, fc.basic_fee_micro, fc.item_fee, fc.seq, fc.legal_due_year, fc.legal_due_month, fc.legal_due_day\r\n from i_annual_fee as af inner join\r\n i_annual_fee_config as fc on af.annual_fee_id = fc.annual_fee_id\r\n where (af.case_type_id = @case_type_id) and (af.country_id = @country_id) and (af.apply_type_id = @apply_type_id)";
Hashtable ht = new Hashtable();
ht.Add("case_type_id", case_type_id);
ht.Add("country_id", country_id);
ht.Add("apply_type_id", apply_type_id);
DataSet ds = sql_server_helper.GetDataSet(sql);
if (ds.Tables[0].Rows.Count == 0)
{
return null;
}
AnnualInfo ai = new AnnualInfo();
DataRow[] drs = ds.Tables[0].Select("seq=" + proc_stage.ToString());
if (drs.Length == 0)
{
ai.proc_stage = -1;
return ai;
}
ai.annual_fee_id = Convert.ToString(drs[0]["annual_fee_id"]);
ai.begin_type = Convert.ToString(drs[0]["begin_type"]);
ai.proc_stage = Convert.ToInt32(drs[0]["seq"]);
ai.currency_id = Convert.ToString(drs[0]["currency_id"]);
ai.basic_fee = Convert.ToDouble(drs[0]["basic_fee"]);
ai.basic_fee_small = Convert.ToDouble(drs[0]["basic_fee_small"]);
ai.basic_fee_micro = Convert.ToDouble(drs[0]["basic_fee_micro"]);
ai.item_fee = Convert.ToDouble(drs[0]["item_fee"]);
ai.legal_due_year = Convert.ToInt32(drs[0]["legal_due_year"]);
ai.legal_due_month = Convert.ToInt32(drs[0]["legal_due_month"]);
ai.legal_due_day = Convert.ToInt32(drs[0]["legal_due_day"]);
return ai;
}
public int GetAnnualStageByProc(string proc_id, string country_id, ref string review_stage)
{
int num;
int num1;
string strSql = string.Concat("SELECT ctrl_proc_code,case_id FROM dbo.p_proc_info pr INNER JOIN dbo.i_ctrl_proc ct ON pr.ctrl_proc_id=ct.ctrl_proc_id WHERE proc_id='", proc_id, "' ");
DataSet ds = null;
ds = sql_server_helper.GetDataSet(strSql);
Hashtable ht = new Hashtable();
strSql = "SELECT cs.case_status_code, cp.ctrl_proc_code\r\n FROM p_proc_info AS pi INNER JOIN\r\n i_ctrl_proc AS cp ON pi.ctrl_proc_id = cp.ctrl_proc_id LEFT OUTER JOIN\r\n i_case_status AS cs ON pi.review_stage = cs.case_status_id\r\n WHERE (pi.proc_id = @proc_id)";
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
if (Convert.ToString(ds.Tables[0].Rows[0]["ctrl_proc_code"]).ToUpper() == "GPC")
{
string case_id = Convert.ToString(ds.Tables[0].Rows[0]["case_id"]);
strSql = "SELECT cs.case_status_code, cp.ctrl_proc_code\r\n FROM p_proc_info AS pi INNER JOIN i_ctrl_proc AS cp ON pi.ctrl_proc_id = cp.ctrl_proc_id\r\n left outer join i_case_status as cs on pi.review_stage=cs.case_status_id \r\n WHERE (pi.case_id = @case_id) AND cp.ctrl_proc_code = N'NOA' AND (pi.is_enabled = 1) AND (pi.proc_id <> @proc_id)";
ht.Add("case_id", case_id);
}
if (Convert.ToString(ds.Tables[0].Rows[0]["ctrl_proc_code"]).ToUpper() == "AP")
{
strSql = "SELECT case_status_code,'AF' as ctrl_proc_code FROM dbo.i_case_status WHERE case_status_code='AN2' ";
}
}
ht.Add("proc_id", proc_id);
ds = sql_server_helper.GetDataSet(strSql, ht);
try
{
string code = Convert.ToString(ds.Tables[0].Rows[0][0]);
if (code.StartsWith("AN"))
{
int stage = Convert.ToInt32(code.Replace("AN", ""));
num = stage + 1;
strSql = string.Concat("SELECT case_status_id FROM i_case_status WHERE case_status_code = 'AN", num.ToString(), "'");
ds = sql_server_helper.GetDataSet(strSql);
if (ds.Tables[0].Rows.Count > 0)
{
review_stage = Convert.ToString(ds.Tables[0].Rows[0][0]);
}
num = stage;
}
else if (code.StartsWith("USAN"))
{
int stage = Convert.ToInt32(code.Replace("USAN", ""));
num1 = stage + 1;
strSql = string.Concat("SELECT case_status_id FROM i_case_status WHERE case_status_code = 'USAN", num1.ToString(), "'");
ds = sql_server_helper.GetDataSet(strSql);
if (ds.Tables[0].Rows.Count > 0)
{
review_stage = Convert.ToString(ds.Tables[0].Rows[0][0]);
}
num = stage;
}
else if (!(country_id == "US") || "AF".Equals(Convert.ToString(ds.Tables[0].Rows[0][1])))
{
num = -1;
}
else
{
int stage = 0;
num1 = stage + 1;
strSql = string.Concat("SELECT case_status_id FROM i_case_status WHERE case_status_code = 'USAN", num1.ToString(), "'");
ds = sql_server_helper.GetDataSet(strSql);
if (ds.Tables[0].Rows.Count > 0)
{
review_stage = Convert.ToString(ds.Tables[0].Rows[0][0]);
}
num = stage;
}
}
catch
{
num = -1;
}
return num;
}
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace WebAPI.Models
{
public class AnnualInfo
{
public string annual_fee_id
{
get;
set;
}
public double basic_fee
{
get;
set;
}
public double basic_fee_micro
{
get;
set;
}
public double basic_fee_small
{
get;
set;
}
public string begin_type
{
get;
set;
}
public string currency_id
{
get;
set;
}
public double item_fee
{
get;
set;
}
public int legal_due_day
{
get;
set;
}
public int legal_due_month
{
get;
set;
}
public int legal_due_year
{
get;
set;
}
public int proc_stage
{
get;
set;
}
public AnnualInfo()
{
}
}
}
\ No newline at end of file
......@@ -20,8 +20,8 @@ namespace WebAPI.Models
get { return this.msg; }
set { this.msg = value; }
}
private string extraInfo="";
public string ExtraInfo
private object extraInfo ="";
public object ExtraInfo
{
get { return this.extraInfo; }
set { this.extraInfo = value; }
......
......@@ -24,7 +24,7 @@ public class CorsHandle : Attribute, ICorsPolicyProvider
objProlicy.Origins.Add("https://ipeasy.essenptl.com");
//objProlicy.Origins.Add("http://127.0.0.1");
//objProlicy.Origins.Add("http://localhost");
//objProlicy.Origins.Add("https://dev.essenptl.com");
objProlicy.Origins.Add("https://dev.essenptl.com");
//objProlicy.Origins.Add("http://ite.essenptl.com");
//objProlicy.Origins.Add("https://ite.essenptl.com");
......
using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
namespace WebAPI.Tool
{
public class LogHelper
{
private static string m_logFile;
private static Dictionary<string, log4net.ILog> m_lstLog = new Dictionary<string, log4net.ILog>();
public static void InitLog4Net(string strLog4NetConfigFile)
{
log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo(strLog4NetConfigFile));
m_logFile = strLog4NetConfigFile;
m_lstLog["info_logo"] = log4net.LogManager.GetLogger("info_logo");
m_lstLog["error_logo"] = log4net.LogManager.GetLogger("error_logo");
}
/// <summary>
/// 功能描述:寫入常規日志
/// </summary>
/// <param name="strInfoLog">strInfoLog</param>
public static void WriteInfoLog(string strInfoLog, string class_name=null)
{
if (m_lstLog["info_logo"].IsInfoEnabled)
{
var disposable = ThreadContext.Stacks["NDC"].Push(class_name);
m_lstLog["info_logo"].Info(strInfoLog);
disposable.Dispose();
}
}
/// <summary>
/// 功能描述:寫入錯誤日志
/// </summary>
/// <param name="strErrLog">strErrLog</param>
/// <param name="ex">ex</param>
public static void WriteErrorLog(string strErrLog, Exception ex = null, string class_name = null)
{
if (m_lstLog["error_logo"].IsErrorEnabled)
{
var disposable = ThreadContext.Stacks["NDC"].Push(class_name);
m_lstLog["error_logo"].Error(strErrLog, ex);
disposable.Dispose();
}
}
/// <summary>
/// 功能描述:寫入日志
/// </summary>
/// <param name="strType">日志類型(對應log4net配置文件中logger.nama)</param>
/// <param name="strLog">strLog</param>
public static void WriteByLogType(string strType, string strLog)
{
if (!m_lstLog.ContainsKey(strType))
{
//判斷是否存在節點
if (!HasLogNode(strType))
{
WriteErrorLog("log4net配置文件不存在【" + strType + "】配置");
return;
}
m_lstLog[strType] = log4net.LogManager.GetLogger(strType);
}
m_lstLog[strType].Error(strLog);
}
/// <summary>
/// 功能描述:是否存在指定的配置
/// </summary>
/// <param name="strNodeName">strNodeName</param>
/// <returns>返回值</returns>
private static bool HasLogNode(string strNodeName)
{
XmlDocument doc = new XmlDocument();
doc.Load(m_logFile);
var lstNodes = doc.SelectNodes("//configuration/log4net/logger");
foreach (XmlNode item in lstNodes)
{
if (item.Attributes["name"].Value.ToLower() == strNodeName)
return true;
}
return false;
}
}
}
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Web;
using WebAPI.Models;
......@@ -120,6 +122,7 @@ namespace WebAPI.Tool
}
catch (Exception e)
{
LogHelper.WriteErrorLog(string.Format(@"{0}", sqlCmd), e, this.GetType().Name + ":" + MethodBase.GetCurrentMethod().Name);
throw new Exception("SQL语句存在错误:" + e);
}
}
......@@ -142,6 +145,7 @@ namespace WebAPI.Tool
}
catch (Exception e)
{
LogHelper.WriteErrorLog(string.Format(@"{0}", selectSqlCommand), e, this.GetType().Name + ":" + MethodBase.GetCurrentMethod().Name);
throw new Exception("select语句有错或者数据表不存在:" + e);
}
finally
......@@ -151,6 +155,44 @@ namespace WebAPI.Tool
return dataTable;
}
public DataSet GetDataSet(string selectSqlCommand, Hashtable ht = null)
{
if (string.IsNullOrEmpty(selectSqlCommand))
throw new Exception("要执行的select语句不能为空");
OpenConnection();
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(selectSqlCommand, SqlCnt);
DataSet ds = new DataSet();
try
{
using (SqlCommand cmd = new SqlCommand(selectSqlCommand, SqlCnt))
{
if (ht != null)
{
foreach (string key in ht.Keys)
{
cmd.Parameters.AddWithValue("@" + key, ht[key].ToString());
}
}
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
da.Fill(ds);
}
}
}
catch (Exception e)
{
LogHelper.WriteErrorLog(string.Format(@"{0}", selectSqlCommand), e, this.GetType().Name + ":" + MethodBase.GetCurrentMethod().Name);
throw new Exception("select语句有错或者数据表不存在:" + e);
}
finally
{
CloseConnection();
}
return ds;
}
/// <summary>
/// 通过表名获取数据表
/// </summary>
......
......@@ -14,6 +14,7 @@
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
-->
<system.web>
<!--
在下列範例中,"Replace" 轉換會取代
......
......@@ -18,7 +18,7 @@
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.6" />
<httpRuntime targetFramework="4.6" />
<httpRuntime targetFramework="4.6" maxRequestLength="102400" executionTimeout="6000"/>
</system.web>
<system.webServer>
<handlers>
......@@ -27,10 +27,7 @@
<remove name="TRACEVerbHandler" />
<remove name="WebDAV" />
<!--<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />-->
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*."
verb="GET,HEAD,POST,PUT,DELETE,OPTIONS"
type="System.Web.Handlers.TransferRequestHandler"
preCondition="integratedMode,runtimeVersionv4.0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,PUT,DELETE,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
<modules>
<add name="HelloWorldModule" type="HelloWorldModule" />
......
......@@ -78,6 +78,9 @@
<Reference Include="K4os.Hash.xxHash, Version=1.0.6.0, Culture=neutral, PublicKeyToken=32cd54395057cec3, processorArchitecture=MSIL">
<HintPath>packages\K4os.Hash.xxHash.1.0.6\lib\net46\K4os.Hash.xxHash.dll</HintPath>
</Reference>
<Reference Include="log4net, Version=2.0.12.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>packages\log4net.2.0.12\lib\net45\log4net.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Microsoft.VisualBasic" />
<Reference Include="MySql.Data, Version=8.0.22.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
......@@ -196,6 +199,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Controllers\AnnualInfoController.cs" />
<Compile Include="Controllers\Esn_Subitem\Esn_todos_SettleController.cs" />
<Compile Include="Controllers\Esn_Subitem\Esn_todosController.cs" />
<Compile Include="Controllers\DictionaryController.cs" />
......@@ -205,11 +209,13 @@
<Compile Include="Controllers\InventorController.cs" />
<Compile Include="Controllers\SubProcInfoController.cs" />
<Compile Include="Controllers\ProcInfoController.cs" />
<Compile Include="Dal\Dal.cs" />
<Compile Include="Dal\DalBaseInfo.cs" />
<Compile Include="Dal\DalFee.cs" />
<Compile Include="Dal\DalCaseInfo.cs" />
<Compile Include="Dal\DalProcInfo.cs" />
<Compile Include="Models\Esn_todos_SettleModel.cs" />
<Compile Include="Models\AnnualInfo.cs" />
<Compile Include="Models\Esn_Todos_FlowModel.cs" />
<Compile Include="Models\Esn_TodosModel.cs" />
<Compile Include="Models\ParamModel.cs" />
......@@ -217,6 +223,7 @@
<Compile Include="Tool\Common.cs" />
<Compile Include="Tool\CorsHandle.cs" />
<Compile Include="Tool\ExcelHelper.cs" />
<Compile Include="Tool\LogHelper.cs" />
<Compile Include="Tool\MySqlHelper.cs" />
<Compile Include="Tool\SqlServerHelper.cs" />
<Content Include="App_Code\HelloWorldModule.cs" />
......@@ -295,6 +302,9 @@
<Content Include="Areas\HelpPage\Views\Help\DisplayTemplates\CollectionModelDescription.cshtml" />
<Content Include="Areas\HelpPage\Views\Help\DisplayTemplates\ApiGroup.cshtml" />
<Content Include="Areas\HelpPage\Views\Help\Api.cshtml" />
<Content Include="log4net.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Include="Properties\PublishProfiles\FolderProfile.pubxml" />
<None Include="Scripts\jquery-3.4.1.intellisense.js" />
<Content Include="Scripts\jquery-3.4.1.js" />
......
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net>
<!--新增節點說明: -->
<!--1、復制一個appender節點,修改name,修改file,其他內容看情況修改-->
<!--2、復制一個logger節點,修改appender-ref為步驟2appendername,修改name(調用WriteByLogType函數,傳入的type),-->
<appender name="InfoAppender" type="log4net.Appender.RollingFileAppender">
<!--保存路徑:下面路徑項目啟動的時候自動在C盤中創建loglogError文件-->
<file value="log\\Info\\"/>
<!-- 如果想在本項目中添加路徑,那就直接去掉C:\\ 只設置log\\LogError 項目啟動中默認創建文件 -->
<appendToFile value="true"/>
<!--按照何種方式產生多個日志文件(日期[Date],文件大小[Size],混合[Composite])-->
<rollingStyle value="Composite"/>
<!--這是按日期產生文件夾-->
<datePattern value="yyyy-MM\\yyyy-MM-dd'.txt'"/>
<!--是否只寫到一個文件中-->
<staticLogFileName value="false"/>
<!--保留的log文件數量 超過此數量后 自動刪除之前的 好像只有在 按Size分割時有效 設定值value="-1"為不限文件數-->
<param name="MaxSizeRollBackups" value="100"/>
<!--每個文件的大小。只在混合方式與文件大小方式下使用。超出大小后在所有文件名后自動增加正整數重新命名,數字最大的最早寫入。可用的單位:KB|MB|GB。不要使用小數,否則會一直寫入當前日志-->
<maximumFileSize value="10240KB" />
<!-- layout 控制Appender的輸出格式,也可以是xml 一個Appender只能是一個layout-->
<layout type="log4net.Layout.PatternLayout">
<!--每條日志末尾的文字說明-->
<!--輸出格式 模板-->
<!-- <param name="ConversionPattern" value="記錄時間:%date 線程ID:[%thread] 日志級別:%-5level 記錄類:%logger
操作者ID:%property{Operator} 操作類型:%property{Action}%n 當前機器名:%property%n當前機器名及登錄用戶:%username %n
記錄位置:%location%n 消息描述:%property{Message}%n 異常:%exception%n 消息:%message%newline%n%n" />-->
<!--樣例:2008-03-26 13:42:32,111 [10] INFO Log4NetDemo.MainClass [(null)] - info-->
<!--<conversionPattern value="%newline %n記錄時間:%date %n線程ID:[%thread] %n日志級別: %-5level %n錯誤描述:%message%newline %n"/>-->
<conversionPattern value="%n==========
%n【記錄時間】%date
%n【記錄的類】%logger 屬性[%property{NDC}]
%n【內容描述】%message"/>
</layout>
</appender>
<appender name="ErrorAppender" type="log4net.Appender.RollingFileAppender">
<!--保存路徑:下面路徑項目啟動的時候自動在C盤中創建loglogError文件-->
<file value="log\\Error\\"/>
<!-- 如果想在本項目中添加路徑,那就直接去掉C:\\ 只設置log\\LogError 項目啟動中默認創建文件 -->
<appendToFile value="true"/>
<!--按照何種方式產生多個日志文件(日期[Date],文件大小[Size],混合[Composite])-->
<rollingStyle value="Composite"/>
<!--這是按日期產生文件夾-->
<datePattern value="yyyy-MM\\yyyy-MM-dd'.txt'"/>
<!--是否只寫到一個文件中-->
<staticLogFileName value="false"/>
<!--保留的log文件數量 超過此數量后 自動刪除之前的 好像只有在 按Size分割時有效 設定值value="-1"為不限文件數-->
<param name="MaxSizeRollBackups" value="100"/>
<!--每個文件的大小。只在混合方式與文件大小方式下使用。超出大小后在所有文件名后自動增加正整數重新命名,數字最大的最早寫入。可用的單位:KB|MB|GB。不要使用小數,否則會一直寫入當前日志-->
<maximumFileSize value="10240KB" />
<!-- layout 控制Appender的輸出格式,也可以是xml 一個Appender只能是一個layout-->
<layout type="log4net.Layout.PatternLayout">
<!--每條日志末尾的文字說明-->
<!--輸出格式 模板-->
<!-- <param name="ConversionPattern" value="記錄時間:%date 線程ID:[%thread] 日志級別:%-5level 記錄類:%logger
操作者ID:%property{Operator} 操作類型:%property{Action}%n 當前機器名:%property%n當前機器名及登錄用戶:%username %n
記錄位置:%location%n 消息描述:%property{Message}%n 異常:%exception%n 消息:%message%newline%n%n" />-->
<!--樣例:2008-03-26 13:42:32,111 [10] INFO Log4NetDemo.MainClass [(null)] - info-->
<!--<conversionPattern value="%newline %n記錄時間:%date %n線程ID:[%thread] %n日志級別: %-5level %n錯誤描述:%message%newline %n"/>-->
<conversionPattern value="%n==========
%n【日志級別】%-5level
%n【記錄時間】%date
%n【線程編號】[%thread]
%n【執行時間】[%r]毫秒
%n【出錯文件】%F
%n【出錯行號】%L
%n【出錯的類】%logger 屬性[%property{NDC}]
%n【錯誤描述】%message
%n【錯誤詳情】%newline"/>
</layout>
</appender>
<logger name="info_logo">
<level value="ALL" />
<appender-ref ref="InfoAppender" />
</logger>
<logger name="error_logo">
<level value="ALL" />
<appender-ref ref="ErrorAppender" />
</logger>
</log4net>
</configuration>
\ No newline at end of file
......@@ -14,6 +14,7 @@
<package id="K4os.Compression.LZ4" version="1.1.11" targetFramework="net46" />
<package id="K4os.Compression.LZ4.Streams" version="1.1.11" targetFramework="net46" />
<package id="K4os.Hash.xxHash" version="1.0.6" targetFramework="net46" />
<package id="log4net" version="2.0.12" targetFramework="net46" />
<package id="Microsoft.AspNet.Cors" version="5.2.7" targetFramework="net46" />
<package id="Microsoft.AspNet.Mvc" version="5.2.7" targetFramework="net46" />
<package id="Microsoft.AspNet.Mvc.zh-Hant" version="5.2.7" targetFramework="net46" />
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment