Commit 50d04487 authored by solho's avatar solho

Merge branch 'master' of http://gitlab.epurplevineip.com/sol/code

parents f53a5a46 91a9f41b
...@@ -14,6 +14,7 @@ using System.Text; ...@@ -14,6 +14,7 @@ using System.Text;
using System.Web; using System.Web;
using System.Web.Http; using System.Web.Http;
using System.Web.Http.Cors; using System.Web.Http.Cors;
using WebAPI.Dal;
using WebAPI.Models; using WebAPI.Models;
using WebAPI.Tool; using WebAPI.Tool;
using static WebAPI.Models.CommonModel; using static WebAPI.Models.CommonModel;
...@@ -202,6 +203,159 @@ namespace WebAPI.Controllers ...@@ -202,6 +203,159 @@ namespace WebAPI.Controllers
} }
#endregion #endregion
#region 導入費用
[Route("ProcInfo/Fee/Import")]
[CorsHandle]
[HttpPost]
public HttpResponseMessage ProcInfoFeeImport()
{
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
CommonResponseMsg response = new CommonResponseMsg();
try
{
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)
{
DataTable dt_excel = ds_excel.Tables[0];
dt_excel.Columns.Add("check_status", 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");
CommonResponseMsg result_fee_cate_workitem = dal_base_info.GetDictionaryByName("*", "fee_cate_workitem");//科目
CommonResponseMsg result_fc_cate = dal_base_info.GetFcCategory();//程序名稱
//CommonResponseMsg result_case_type = dal_base_info.GetDataByTable("*", "i_case_type");//案件類型
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;
foreach (DataRow dr_proc in dt_excel.Rows)
{
CommonResponseMsg result_check = new CommonResponseMsg();
result_check.Code = "1";
result_check.Msg = "OK";
CommonResponseMsg result_case_info = dal_case_info.GetCaseInfoByCaseVolume("*", dr_proc["我方文号"].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_proc["处理事项ID"].ToString();
if (string.IsNullOrEmpty(proc_id))
{
string case_volume = dr_proc["我方文号"].ToString();
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)
{
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_proc["处理事项ID"].ToString());
if (result_proc_info.Code == "0" || ((DataTable)result_proc_info.Msg).Rows.Count != 1)
{
result_check.Code = "0";
result_check.Msg = "此ID无法找到唯一的处理事项";
}
}
}
//檢查工作項目是否存在
if (result_check.Code == "1")
{
if (result_fee_cate_workitem.Code == "1" && result_fc_cate.Code == "1" && result_case_info.Code == "1")
{
DataTable dt_fee_cate_workitem = (DataTable)result_fee_cate_workitem.Msg;
DataTable dt_fc_cate = (DataTable)result_fc_cate.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)
{
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)
{
result_check.Msg = "无法找到唯一的工作项目";
}
}
else
{
result_check.Code = "0";
result_check.Msg = "科目或程序名称不正确";
}
}
else
{
result_check.Code = "0";
result_check.Msg = "需要有我方文号、科目、程序名称以及费用名称";
}
}
dr_proc["check_status"] = result_check.Msg;
}
response.Code = "1";
response.Msg = dt_excel;
}
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";
}
//DataSet ds = excel_helper.LoadFromStream();
}
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
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 DalBaseInfo
{
SqlServerHelper sql_server_helper = new SqlServerHelper();
public CommonResponseMsg GetDictionaryByName(string field = "*", string dictionary_name = null)
{
CommonResponseMsg result = new CommonResponseMsg();
try
{
string sql = string.Format(@"SELECT {0} FROM dbo.s_dictionary", field);
if (!string.IsNullOrEmpty(dictionary_name))
{
sql += string.Format(@" where dictionary_name = '{0}'", dictionary_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 GetFcCategory(string field = "*", string fc_cate_id = null)
{
CommonResponseMsg result = new CommonResponseMsg();
try
{
string sql = string.Format(@"SELECT {0} FROM dbo.i_fc_category", field);
sql += " where is_enabled = 1";
if (!string.IsNullOrEmpty(fc_cate_id))
{
sql += string.Format(@" and fc_cate_id = '{0}'", fc_cate_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;
}
public CommonResponseMsg GetDataByTable(string field, string table_name, string primary_key = null, string id = null)
{
CommonResponseMsg result = new CommonResponseMsg();
try
{
string sql = string.Format(@"SELECT {0} FROM dbo.{1}", field, table_name);
if (!string.IsNullOrEmpty(id))
{
sql += string.Format(@" where {0} = '{1}'", primary_key, 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.Generic;
using System.Data;
using System.Linq;
using System.Web;
using WebAPI.Models;
using WebAPI.Tool;
namespace WebAPI.Dal
{
public class DalCaseInfo
{
SqlServerHelper sql_server_helper = new SqlServerHelper();
public CommonResponseMsg GetCaseInfoByCaseVolume(string field = "*", string case_volume = null)
{
CommonResponseMsg result = new CommonResponseMsg();
try
{
string sql = string.Format(@"SELECT {0} FROM dbo.p_case_info", field);
sql += " where is_enabled = 1";
if (!string.IsNullOrEmpty(case_volume))
{
sql += string.Format(@" and case_volume = '{0}'", case_volume);
}
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.Generic;
using System.Data;
using System.Linq;
using System.Web;
using WebAPI.Models;
using WebAPI.Tool;
namespace WebAPI.Dal
{
public class DalFee
{
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();
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))
{
sql += string.Format(@" and case_type_id = '{0}'", case_type_id);
}
if (!string.IsNullOrEmpty(business_type_id))
{
sql += string.Format(@" and business_type_id = '{0}'", business_type_id);
}
if (!string.IsNullOrEmpty(apply_type_id))
{
sql += string.Format(@" and apply_type_id = '{0}'", apply_type_id);
}
if (!string.IsNullOrEmpty(country_id))
{
sql += string.Format(@" and country_id = '{0}'", 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;
}
}
}
\ 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 DalProcInfo
{
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();
try
{
string sql = string.Format(@"SELECT {0} FROM dbo.i_ctrl_proc", field);
if(string.IsNullOrEmpty(ctrl_proc_id))
{
if(!string.IsNullOrEmpty(ctrl_proc_name))
{
sql += string.Format(@" where (ctrl_proc_zh_cn = '{0}' or ctrl_proc_zh_tw = '{0}') and is_enabled = 1", ctrl_proc_name);
}
}
else
{
sql += string.Format(@" where ctrl_proc_id = '{0}' and is_enabled = 1", ctrl_proc_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;
}
public CommonResponseMsg GetCaseStatus(string field = "*", string case_status_id = null, string case_status_name = null)
{
CommonResponseMsg result = new CommonResponseMsg();
try
{
string sql = string.Format(@"SELECT {0} FROM dbo.i_case_status", field);
if (string.IsNullOrEmpty(case_status_id))
{
if (!string.IsNullOrEmpty(case_status_name))
{
sql += string.Format(@" where (case_status_zh_cn = '{0}' or case_status_zh_tw = '{0}')", case_status_name);
}
}
else
{
sql += string.Format(@" where case_status_id = '{0}'", case_status_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;
}
public CommonResponseMsg GetProcInfo(string field, string proc_id = null)
{
CommonResponseMsg result = new CommonResponseMsg();
try
{
string sql = string.Format(@"SELECT {0} FROM dbo.p_proc_info ppi
LEFT JOIN dbo.p_case_info pci ON ppi.case_id = pci.case_id
LEFT 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", field);
sql += " where ppi.is_enabled = 1";
if (!string.IsNullOrEmpty(proc_id))
{
sql += string.Format(@" and proc_id = '{0}'", proc_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;
}
public CommonResponseMsg GetProcInfoByName(string field = "*", string case_volume = null, string proc_name = null, string case_status_name = null)
{
CommonResponseMsg result = new CommonResponseMsg();
try
{
string sql = string.Format(@"SELECT {0} FROM dbo.p_proc_info ppi
LEFT JOIN dbo.p_case_info pci ON ppi.case_id = pci.case_id
LEFT 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", field);
sql += " where ppi.is_enabled = 1";
if (!string.IsNullOrEmpty(case_volume))
{
sql += string.Format(@" and case_volume = '{0}'", case_volume);
}
if (!string.IsNullOrEmpty(proc_name))
{
sql += string.Format(@" and (ctrl_proc_zh_cn = '{0}' or ctrl_proc_zh_cn = '{0}')", proc_name);
}
if (!string.IsNullOrEmpty(case_status_name))
{
sql += string.Format(@" and (case_status_zh_cn = '{0}' or case_status_zh_tw = '{0}')", case_status_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;
}
}
}
\ No newline at end of file
...@@ -14,5 +14,12 @@ namespace WebAPI.Models ...@@ -14,5 +14,12 @@ namespace WebAPI.Models
get { return this.input; } get { return this.input; }
set { this.input = value; } set { this.input = value; }
} }
private object file = "";
public object File
{
get { return this.file; }
set { this.file = value; }
}
} }
} }
\ No newline at end of file
using ExcelDataReader;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using WebAPI.Models;
namespace WebAPI.Tool
{
public class ExcelHelper
{
public CommonResponseMsg LoadFromStream(Stream stream, string file_name, bool use_column_data_type = false , bool use_header_row = true)
{
CommonResponseMsg result = new CommonResponseMsg();
DataSet ds;
string extension = Path.GetExtension(file_name);
//判斷格式套用讀取方法
IExcelDataReader reader = null;
if (extension == ".xls")
{
Console.WriteLine(" => XLS格式");
reader = ExcelReaderFactory.CreateBinaryReader(stream, new ExcelReaderConfiguration()
{
FallbackEncoding = Encoding.GetEncoding("big5")
});
}
else if (extension == ".xlsx")
{
Console.WriteLine(" => XLSX格式");
reader = ExcelReaderFactory.CreateOpenXmlReader(stream);
}
else if (extension == ".csv")
{
Console.WriteLine(" => CSV格式");
reader = ExcelReaderFactory.CreateCsvReader(stream, new ExcelReaderConfiguration()
{
FallbackEncoding = Encoding.GetEncoding("big5")
});
}
else if (extension == ".txt")
{
Console.WriteLine(" => Text(Tab Separated)格式");
reader = ExcelReaderFactory.CreateCsvReader(stream, new ExcelReaderConfiguration()
{
FallbackEncoding = Encoding.GetEncoding("big5"),
AutodetectSeparators = new char[] { '\t' }
});
}
//沒有對應產生任何格式
if (reader == null)
{
result.Code = "-1";
result.Msg = "Format Not Support";
}
using (reader)
{
ds = reader.AsDataSet(new ExcelDataSetConfiguration()
{
UseColumnDataType = use_column_data_type,
ConfigureDataTable = (tableReader) => new ExcelDataTableConfiguration()
{
//設定讀取資料時是否忽略標題
UseHeaderRow = use_header_row
}
});
result.Code = "1";
result.Msg = ds;
}
return result;
}
}
}
\ No newline at end of file
...@@ -177,9 +177,6 @@ ...@@ -177,9 +177,6 @@
<Reference Include="Ubiety.Dns.Core, Version=2.2.1.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL"> <Reference Include="Ubiety.Dns.Core, Version=2.2.1.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
<HintPath>packages\MySql.Data.8.0.22\lib\net452\Ubiety.Dns.Core.dll</HintPath> <HintPath>packages\MySql.Data.8.0.22\lib\net452\Ubiety.Dns.Core.dll</HintPath>
</Reference> </Reference>
<Reference Include="WebActivator, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\WebActivator.1.0.0.0\lib\WebActivator.dll</HintPath>
</Reference>
<Reference Include="WebGrease"> <Reference Include="WebGrease">
<Private>True</Private> <Private>True</Private>
<HintPath>.\packages\WebGrease.1.6.0\lib\WebGrease.dll</HintPath> <HintPath>.\packages\WebGrease.1.6.0\lib\WebGrease.dll</HintPath>
...@@ -206,12 +203,17 @@ ...@@ -206,12 +203,17 @@
<Compile Include="Controllers\InventorController.cs" /> <Compile Include="Controllers\InventorController.cs" />
<Compile Include="Controllers\SubProcInfoController.cs" /> <Compile Include="Controllers\SubProcInfoController.cs" />
<Compile Include="Controllers\ProcInfoController.cs" /> <Compile Include="Controllers\ProcInfoController.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_FlowModel.cs" /> <Compile Include="Models\Esn_Todos_FlowModel.cs" />
<Compile Include="Models\Esn_TodosModel.cs" /> <Compile Include="Models\Esn_TodosModel.cs" />
<Compile Include="Models\ParamModel.cs" /> <Compile Include="Models\ParamModel.cs" />
<Compile Include="Models\CommonResponseMsg.cs" /> <Compile Include="Models\CommonResponseMsg.cs" />
<Compile Include="Tool\Common.cs" /> <Compile Include="Tool\Common.cs" />
<Compile Include="Tool\CorsHandle.cs" /> <Compile Include="Tool\CorsHandle.cs" />
<Compile Include="Tool\ExcelHelper.cs" />
<Compile Include="Tool\MySqlHelper.cs" /> <Compile Include="Tool\MySqlHelper.cs" />
<Compile Include="Tool\SqlServerHelper.cs" /> <Compile Include="Tool\SqlServerHelper.cs" />
<Content Include="App_Code\HelloWorldModule.cs" /> <Content Include="App_Code\HelloWorldModule.cs" />
......
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