市长热线演示版

attributeedit.aspx.cs 9.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.Data;
  8. namespace HySoft.BaseCallCenter.Web.formmanage
  9. {
  10. public partial class attributeedit : System.Web.UI.Page
  11. {
  12. protected void Page_Load(object sender, EventArgs e)
  13. {
  14. if (!Page.IsPostBack)
  15. {
  16. if (!string.IsNullOrEmpty(Request.QueryString["action"]))
  17. {
  18. txtotype.Value = Request.QueryString["action"].Trim();
  19. }
  20. if (!string.IsNullOrEmpty(Request.QueryString["entityid"]))
  21. {
  22. txtentityid.Value = Request.QueryString["entityid"].Trim();
  23. GetEntityInfo(Request.QueryString["entityid"].Trim());
  24. }
  25. if (!string.IsNullOrEmpty(Request.QueryString["id"]))
  26. {
  27. txtid.Value = Request.QueryString["id"].Trim();
  28. //GetEntityInfo(Request.QueryString["entityid"].Trim());
  29. }
  30. BindList();
  31. }
  32. }
  33. private void GetEntityInfo(string entityid)
  34. {
  35. Model.T_Form_EntityInfo model = new Model.T_Form_EntityInfo();
  36. try
  37. {
  38. model = new BLL.T_Form_EntityInfo().GetModel(Convert.ToInt32(entityid));
  39. if (model != null)
  40. {
  41. txtF_DBTableName.Text = model.F_DBTableName.Trim();
  42. }
  43. }
  44. catch(Exception ex){
  45. }
  46. }
  47. private void BindList()
  48. {
  49. selectF_ColumnNumber.Items.Clear();
  50. DataTable dt = new DataTable();
  51. try
  52. {
  53. if (txtentityid.Value != "")
  54. {
  55. dt = new BLL.T_Form_EntityAttribute().GetList("F_EntityId=" + txtentityid.Value.Trim() + " order by F_ColumnNumber ").Tables[0];
  56. int max = 0;
  57. for (int i = 0; i < dt.Rows.Count; i++)
  58. {
  59. selectF_ColumnNumber.Items.Add(new ListItem(dt.Rows[i]["F_ColumnNumber"].ToString() + "-" + dt.Rows[i]["F_Name"].ToString(), dt.Rows[i]["F_ColumnNumber"].ToString()));
  60. if (i == (dt.Rows.Count - 1))
  61. {
  62. max = Convert.ToInt32(dt.Rows[i]["F_ColumnNumber"].ToString());
  63. }
  64. }
  65. if (Request.QueryString["action"].Trim() == "add")
  66. {
  67. selectF_ColumnNumber.Items.Add(new ListItem((max + 1).ToString(), (max + 1).ToString()));
  68. selectF_ColumnNumber.Value = (max + 1).ToString();
  69. }
  70. }
  71. else
  72. {
  73. selectF_ColumnNumber.Items.Add(new ListItem("0", "0"));
  74. }
  75. }
  76. catch
  77. {
  78. }
  79. finally
  80. {
  81. dt.Clear();
  82. dt.Dispose();
  83. }
  84. selecttype.Items.Clear();
  85. try
  86. {
  87. selecttype.Items.Add(new ListItem("选择数据类型", ""));
  88. dt = new BLL.T_Form_AttributeTypes().GetList("F_IsShow=1").Tables[0];
  89. for (int i = 0; i < dt.Rows.Count; i++)
  90. {
  91. selecttype.Items.Add(new ListItem(dt.Rows[i]["F_DBTypeName"].ToString() + "[" + dt.Rows[i]["F_TypeName"].ToString() + "]", dt.Rows[i]["F_TypeId"].ToString()));
  92. }
  93. }
  94. catch
  95. {
  96. }
  97. finally
  98. {
  99. dt.Clear();
  100. dt.Dispose();
  101. }
  102. }
  103. protected void btnSubmit_Click(object sender, EventArgs e)
  104. {
  105. string res = "";
  106. try
  107. {
  108. string name = txtF_Name.Text.Trim();
  109. string field = txtF_DBFieldlName.Value.Trim();
  110. string basetable = txtF_DBTableName.Text.Trim();
  111. string fieldtype = selecttype.Value.Trim();
  112. string attributeid = txtid.Value.Trim();
  113. string opttype = txtotype.Value.Trim();
  114. DateTime dat = DateTime.Now;
  115. if (string.IsNullOrEmpty(name.Trim()))
  116. {
  117. res = "属性名称不能为空";
  118. }
  119. if (string.IsNullOrEmpty(field.Trim()))
  120. {
  121. res = "属性数据字段名不能为空";
  122. }
  123. if (string.IsNullOrEmpty(basetable.Trim()))
  124. {
  125. res = "未获取属性的数据表名";
  126. }
  127. if (string.IsNullOrEmpty(fieldtype.Trim()))
  128. {
  129. res = "请选择属性的数据类型";
  130. }
  131. Model.T_Form_EntityAttribute attributemodel = new Model.T_Form_EntityAttribute();
  132. #region 属性
  133. if (string.IsNullOrEmpty(attributeid.Trim()))
  134. {
  135. }
  136. else
  137. {
  138. attributemodel.F_AttributeId = Convert.ToInt32(attributeid);
  139. }
  140. if(!string.IsNullOrEmpty(fieldtype.Trim()))
  141. {
  142. attributemodel.F_TypeId = Convert.ToInt32(fieldtype);
  143. attributemodel.F_DBTypeName = new BLL.T_Form_AttributeTypes().GetModel(Convert.ToInt32(fieldtype)).F_DBTypeName;
  144. }
  145. attributemodel.F_Name = name;
  146. attributemodel.F_DBFieldlName = "F_"+field;
  147. if (string.IsNullOrEmpty(txtF_MaxLength.Text.Trim()))
  148. {
  149. attributemodel.F_Length = null;
  150. attributemodel.F_MaxLength = null;
  151. }
  152. else
  153. {
  154. try
  155. {
  156. attributemodel.F_Length = Convert.ToInt32(txtF_MaxLength.Text.Trim());
  157. attributemodel.F_MaxLength = Convert.ToInt32(txtF_MaxLength.Text.Trim());
  158. }
  159. catch
  160. {
  161. res= "属性最大长度格式不正确";
  162. }
  163. }
  164. attributemodel.F_IsNullable = true;
  165. attributemodel.F_EntityId = Convert.ToInt32(txtentityid.Value.Trim());
  166. attributemodel.F_DBTableName = basetable;
  167. attributemodel.F_DefaultValue = txtF_DefaultValue.Text.Trim();
  168. attributemodel.F_ColumnNumber = Convert.ToInt32(selectF_ColumnNumber.Value.Trim());
  169. attributemodel.F_ValidForUpdateAPI = true;
  170. attributemodel.F_ValidForReadAPI = true;
  171. attributemodel.F_ValidForCreateAPI = true;
  172. if (chkF_VisibleToPlatform.Checked)
  173. {
  174. attributemodel.F_VisibleToPlatform = true;
  175. }
  176. else
  177. {
  178. attributemodel.F_VisibleToPlatform = false;
  179. }
  180. attributemodel.F_IsPKAttribute = chkF_IsPKAttribute.Checked;
  181. attributemodel.F_IsCustomField = chkF_IsCustomField.Checked;
  182. attributemodel.F_DisplayMask = 1;
  183. attributemodel.F_IsSortAttribute = true;
  184. attributemodel.F_PrecisionValue = 0;
  185. attributemodel.F_IsIdentity = false;
  186. attributemodel.F_AppDefaultValue = 0;
  187. attributemodel.F_Locked = false;
  188. attributemodel.F_MinValue = 0;
  189. attributemodel.F_MaxValue = 0;
  190. if (chkIsList.Checked)
  191. {
  192. attributemodel.F_LookupKey = txtF_LookupKey.Text.Trim();
  193. attributemodel.F_LookupStyle = "";
  194. attributemodel.F_IsLookup = true;
  195. }
  196. else
  197. {
  198. attributemodel.F_LookupKey = "";
  199. attributemodel.F_LookupStyle = "";
  200. attributemodel.F_IsLookup = false;
  201. }
  202. attributemodel.F_Des = txtF_Remark.Text.Trim();
  203. #endregion
  204. int r = -4;
  205. if (opttype == "add")
  206. {
  207. r = new BLL.T_Form_EntityAttribute().AddTran(attributemodel);
  208. }
  209. else if (opttype == "modify")
  210. {
  211. //r = new BLL.T_Form_EntityAttribute().UpdateAttribute(attributemodel);
  212. }
  213. if (r == 0)
  214. {
  215. res = "success";
  216. }
  217. else
  218. {
  219. if (r == -2)
  220. {
  221. res = "实体属性数据表名称已存在";
  222. }
  223. else if (r == -3)
  224. {
  225. res = "实体属性名称已存在";
  226. }
  227. else if (r == -1)
  228. {
  229. res = "-1";
  230. }
  231. else
  232. {
  233. res = "" + r.ToString();
  234. }
  235. }
  236. }
  237. catch
  238. {
  239. res = "创建属性异常";
  240. }
  241. }
  242. }
  243. }