目的: 編輯畫面 RadioGroup 欄位存回資料庫, PK=MAX(PK)+1
處理說明: 1> PK=MAX(PK)+1
1>>*.js np["ASPNO"] = "ASP" + DatetoStr(now, "Ymd");
1>>*.js np["ASPNO"] = "ASP" + DatetoStr(now, "Ymd");
2>>*.cs Tmp_NEXT_ASPNO = Tmp_ASPNO + (int.Parse(Tmp_MAX_ASPNO.Substring(11, 3))+1).ToString("000");
2> RadioGroup欄位值
1>>每一Radio.id均不同, 傳回後端每一Radio均有一值(true/false)
2>>RadioGroup欄位值由 np["STAT"]=Ext.getCmp("name").getValue(); 取得送至後端
var buttonModel = Ext.create('G_buttonModel');
//存檔時,自動設定欄位值 : PK,
Ext.getCmp('btn_save').setFormValue = function () {
//1>取得 PK= MAX(PK)+1 , 新增時,才設定 PK 欄位值, 編輯時 , 不設定欄位值
var modelType = buttonModel.getModelType();
if (!(modelType == 1))
return true;
var Tmp_NEXT_ASPNO = get_NEXT_ASPNO();
Ext.getCmp("ASPNO").setValue(Tmp_NEXT_ASPNO);
//2>設定 RadioGroup 欄位值 , 由 S_DB.add_np 設定特別的欄位值
S_DB.add_np = {};
S_DB.add_np["WTLV"] = Ext.getCmp("WTLV").getValue();
S_DB.add_np["ITPR"] = Ext.getCmp("ITPR").getValue();
return true;}
var np=s_JSON('myform');
--> Template 先執行 setFormValue() , 再執行 np 取欄位值,
所以 setFormValue() 的欄位值, 會存入 np 參數
2>*.cs
1>>取得 MAX(PK)+1
[HttpPost]
public HttpResponseMessage GET_NEXT_ASPNO()
{
var c = HttpContext.Current;
NameValueCollection nvc = c.Request.Form;
var response = this.Request.CreateResponse();
string Tmp_ASPNO = nvc["ASPNO"];
string Tmp_Str = "";
OracleConnection conn = new OracleConnection(DBService.ConnectionString(DBLINK));//
OracleCommand cmd = new OracleCommand();
OracleDataReader reader;
conn.Open();
conn.ClientInfo = User.Identity.Name;
conn.ModuleName = BaseSYS + "_" + BaseMODID;
conn.ActionName = ActionName;
cmd.Connection = conn;
string Tmp_MAX_ASPNO = "", Tmp_NEXT_ASPNO = "";
try
{
string Tmp_Sql = " SELECT MAX(ASPNO) as MAX_ASPNO "
+ " FROM AMM_ASP "
+ " WHERE ASPNO LIKE " + myfunc.AA(Tmp_ASPNO+"%");
cmd.CommandText = Tmp_Sql;
reader = cmd.ExecuteReader();
if (reader.Read())
{
Tmp_MAX_ASPNO = reader["MAX_ASPNO"].ToString();
if (myfunc.checkisnull(Tmp_MAX_ASPNO))
Tmp_NEXT_ASPNO = Tmp_ASPNO + "001";
else
{
Tmp_NEXT_ASPNO = Tmp_ASPNO + (int.Parse(Tmp_MAX_ASPNO.Substring(11, 3))+1).ToString("000");
}
}
Tmp_Str = "{success: true , NEXT_ASPNO:" + myfunc.AA(Tmp_NEXT_ASPNO) + ","
+ " }";
response.Content = new StringContent(Tmp_Str); // 回應內容
return response;
}// end of try
catch (Exception e)
{
Tmp_Str = "{success: false , NEXT_ASPNO:" + myfunc.AA(Tmp_NEXT_ASPNO) + ","
+ " }";
response.Content = new StringContent(Tmp_Str); // 回應內容
return response;
}
finally
{
conn.Close();
}
} // end of get_NEXT_ASPNO
//移除 nvc 由 RadioGroup 的每一Radio欄位值(true/false)
2>>
[HttpPost]
public void Insert()
{
var c = System.Web.HttpContext.Current;
NameValueCollection nvc = c.Request.Form;
NameValueCollection nvc1= new NameValueCollection();
//nvc 移除 radio開頭的 key , 以免加入 Insert Sql
var Tmp_key = "";
foreach(string key in nvc.Keys)
{
if (!key.Contains("radio"))
nvc1[key] = nvc[key];
}
excuteInsert(nvc1, DBTable);
}
沒有留言:
張貼留言