118 lines
4.0 KiB
C#
118 lines
4.0 KiB
C#
using Dapper;
|
|
using Dapper.Contrib.Extensions;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
using System.Data.SqlClient;
|
|
using static DbTableClass;
|
|
|
|
|
|
public class kolCooperateTypeDetail : kolCooperateType {
|
|
|
|
DbConn dbConn = new DbConn();
|
|
SqlConnection conn = new SqlConnection(GlobalClass.appsettings("ConnectionStrings:SQLConnectionString"));
|
|
|
|
public string option_name { get; set; } = "";
|
|
public string optionItem_name { get; set; } = "";
|
|
|
|
public string updateResult { get; set; } = "";
|
|
|
|
private kolCooperateType _kolCooperateType;
|
|
|
|
public kolCooperateTypeDetail() {
|
|
_kolCooperateType = new kolCooperateType();
|
|
}
|
|
|
|
public kolCooperateTypeDetail(string kolCooperateType_uid) {
|
|
_kolCooperateType = conn.QueryFirstOrDefault<kolCooperateType>("select * from kolCooperateType where kolCooperateType_uid = @kolCooperateType_uid", new { kolCooperateType_uid = kolCooperateType_uid});
|
|
|
|
if (_kolCooperateType != null)
|
|
{
|
|
Type dataType = _kolCooperateType.GetType();
|
|
|
|
foreach (var prop in dataType.GetProperties())
|
|
{
|
|
string propName = prop.Name;
|
|
var valueProperty = dataType.GetProperty(propName);
|
|
object propValue = valueProperty.GetValue(_kolCooperateType, null);
|
|
|
|
this.GetType().GetProperty(propName).SetValue(this, propValue);
|
|
}
|
|
|
|
var result = conn.QueryFirstOrDefault("select A.option_name, B.optionItem_name from from option A, optionItem B where A.option_uid = B.option_uid and B.option_uid = @option_uid and B.optionItem_uid = @optionItem_uid ", new { option_uid = this.option_uid, optionItem_uid = this.optionItem_uid });
|
|
|
|
if (result != null)
|
|
{
|
|
this.option_name = result.option_name;
|
|
this.optionItem_name = result.optionItem_name;
|
|
}
|
|
}
|
|
else {
|
|
_kolCooperateType = new kolCooperateType();
|
|
}
|
|
}
|
|
|
|
public kolCooperateTypeDetail(kolCooperateType cooperateType)
|
|
{
|
|
this._kolCooperateType = cooperateType;
|
|
|
|
Type dataType = _kolCooperateType.GetType();
|
|
|
|
foreach (var prop in dataType.GetProperties())
|
|
{
|
|
string propName = prop.Name;
|
|
var valueProperty = dataType.GetProperty(propName);
|
|
object propValue = valueProperty.GetValue(_kolCooperateType, null);
|
|
|
|
this.GetType().GetProperty(propName).SetValue(this, propValue);
|
|
}
|
|
|
|
var result = conn.QueryFirstOrDefault("select A.option_name, B.optionItem_name from from option A, optionItem B where A.option_uid = B.option_uid and B.option_uid = @option_uid and B.optionItem_uid = @optionItem_uid ", new { option_uid = this.option_uid, optionItem_uid = this.optionItem_uid });
|
|
|
|
if (result != null)
|
|
{
|
|
this.option_name = result.option_name;
|
|
this.optionItem_name = result.optionItem_name;
|
|
}
|
|
}
|
|
|
|
public bool dataUpdate() {
|
|
if (this._kolCooperateType != null)
|
|
{
|
|
if (this._kolCooperateType.kolCooperateType_uid == "")
|
|
{
|
|
this._kolCooperateType.kolCooperateType_uid = "KCT_" + GlobalClass.CreateRandomCode(16);
|
|
|
|
try
|
|
{
|
|
conn.Insert(this._kolCooperateType);
|
|
updateResult = "success";
|
|
return true;
|
|
}
|
|
catch (Exception ex){
|
|
updateResult = ex.Message;
|
|
return false;
|
|
}
|
|
|
|
}
|
|
else {
|
|
try
|
|
{
|
|
conn.Update(this._kolCooperateType);
|
|
updateResult = "success";
|
|
return true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
updateResult = ex.Message;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
updateResult = "null 物件無法更新";
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
}
|