/EQT_V2/EQT/EQTWebApp/TestItem.aspx.cs

http://sgsoft-las.googlecode.com/ · C# · 356 lines · 302 code · 35 blank · 19 comment · 34 complexity · 9b7d2a4a0a2197d35d46bb70a2b8d14e MD5 · raw file

  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11. using EQT.Model;
  12. using EQT.Dal;
  13. using System.Collections.Generic;
  14. using Common.Logging;
  15. /// <summary>
  16. /// ?????????
  17. /// </summary>
  18. public partial class TestItem : System.Web.UI.Page
  19. {
  20. private DaProductCheckAbility daProduct = DevFuture.Common.WorkContext.AppCtx.GetObject("DaProductCheckAbility") as DaProductCheckAbility;
  21. private static readonly ILog log = LogManager.GetCurrentClassLogger();
  22. private UserContext context;
  23. protected void Page_Load(object sender, EventArgs e)
  24. {
  25. context = Session["USER_CONTEXT"] as UserContext;
  26. divResult.Visible = false;
  27. OperationResult.Text = "";
  28. if (!Page.IsPostBack)
  29. {
  30. this.SetPanelVisiable(mainPanel);
  31. this.BindProductTree();
  32. }
  33. }
  34. protected void btnCreateItem_Click(object sender, EventArgs e)
  35. {
  36. ddlCreatePName.DataSource = daProduct.GetDistinctProduct();
  37. ddlCreatePName.DataBind();
  38. if (ddlCreatePName.Items.Count > 0)
  39. {
  40. this.ddlCreatePName_SelectedIndexChanged(null, null);
  41. }
  42. this.SetPanelVisiable(createPanel);
  43. }
  44. protected void SetPanelVisiable(Panel panel)
  45. {
  46. mainPanel.Visible = false;
  47. createPanel.Visible = false;
  48. editPanel.Visible = false;
  49. panel.Visible = true;
  50. }
  51. protected void btnCreateCancel_Click(object sender, EventArgs e)
  52. {
  53. this.SetPanelVisiable(mainPanel);
  54. }
  55. protected void btnEditCancel_Click(object sender, EventArgs e)
  56. {
  57. this.SetPanelVisiable(mainPanel);
  58. }
  59. /// <summary>
  60. /// ?????
  61. /// </summary>
  62. protected void BindProductTree()
  63. {
  64. productTreeView.Nodes.Clear();
  65. DataSet dsProduct = daProduct.GetDistinctProduct();
  66. if (dsProduct != null)
  67. {
  68. for (int i = 0; i < dsProduct.Tables[0].Rows.Count; i++)
  69. {
  70. TreeNode tnRoot = new TreeNode(dsProduct.Tables[0].Rows[i]["PName"].ToString(), dsProduct.Tables[0].Rows[i]["PName"].ToString());
  71. this.BindModelNode(tnRoot, dsProduct.Tables[0].Rows[i]["PName"].ToString());
  72. productTreeView.Nodes.Add(tnRoot);
  73. }
  74. }
  75. productTreeView.ExpandAll();
  76. }
  77. /// <summary>
  78. /// ??????
  79. /// </summary>
  80. protected void BindModelNode(TreeNode tnParent, string pname)
  81. {
  82. DataSet ds = daProduct.GetDistinctModel(pname);
  83. if (ds.Tables[0].Rows.Count == 0)
  84. return;
  85. for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
  86. {
  87. TreeNode tn = new TreeNode(ds.Tables[0].Rows[i]["PModel"].ToString(), ds.Tables[0].Rows[i]["PModel"].ToString());
  88. tnParent.ChildNodes.Add(tn);
  89. }
  90. }
  91. /// <summary>
  92. /// ?????
  93. /// </summary>
  94. protected void BindTypeList(string pname,string pmodel)
  95. {
  96. repProductType.DataSource = daProduct.GetProductType(pname,pmodel);
  97. repProductType.DataBind();
  98. }
  99. protected void productTreeView_SelectedNodeChanged(object sender, EventArgs e)
  100. {
  101. switch (productTreeView.SelectedNode.Depth)
  102. {
  103. case 0:
  104. repProductType.DataSource = null;
  105. repProductType.DataBind();
  106. labNowProduct.Text = productTreeView.SelectedNode.Text;
  107. break;
  108. case 1:
  109. repProductType.DataSource = daProduct.GetProductType(productTreeView.SelectedNode.Parent.Value,productTreeView.SelectedNode.Value);
  110. repProductType.DataBind();
  111. labNowProduct.Text =productTreeView.SelectedNode.Parent.Value+" > "+ productTreeView.SelectedNode.Text;
  112. break;
  113. default:
  114. return;
  115. }
  116. }
  117. /// <summary>
  118. /// ?????
  119. /// </summary>
  120. protected void btnCreateSave_Click(object sender, EventArgs e)
  121. {
  122. if (string.IsNullOrEmpty(txtCreatePType.Text.Trim()))
  123. {
  124. OperationResult.Text = "????????"; divResult.Visible = true; return;
  125. }
  126. if (string.IsNullOrEmpty(txtCreateGuidePrice.Text.Trim()))
  127. {
  128. OperationResult.Text = "????????"; divResult.Visible = true; return;
  129. }
  130. else
  131. {
  132. decimal decOut;
  133. if (!decimal.TryParse(txtCreateGuidePrice.Text.Trim(),out decOut))
  134. {
  135. OperationResult.Text = "???????????"; divResult.Visible = true; return;
  136. }
  137. }
  138. if (ckbIsNewPName.Checked&&string.IsNullOrEmpty(txtCreatePName.Text.Trim()))
  139. {
  140. OperationResult.Text = "????????"; divResult.Visible = true; return;
  141. }
  142. if (ckbIsNewPModel.Checked && string.IsNullOrEmpty(txtCreatePModel.Text.Trim()))
  143. {
  144. OperationResult.Text = "????????"; divResult.Visible = true; return;
  145. }
  146. if (!ckbIsNewPName.Checked && string.IsNullOrEmpty(ddlCreatePName.SelectedValue))
  147. {
  148. OperationResult.Text = "????????"; divResult.Visible = true; return;
  149. }
  150. if (!ckbIsNewPModel.Checked && string.IsNullOrEmpty(ddlCreatePModel.SelectedValue))
  151. {
  152. OperationResult.Text = "????????"; divResult.Visible = true; return;
  153. }
  154. MoProductCheckAbility mod = new MoProductCheckAbility();
  155. mod.PcaId = SequenceKeys.GenerateProductCheckAbility();
  156. mod.PcaState = 0;
  157. mod.Pmodel =ckbIsNewPModel.Checked? txtCreatePModel.Text.Trim():ddlCreatePModel.SelectedValue;
  158. mod.Pname =ckbIsNewPName.Checked? txtCreatePName.Text.Trim():ddlCreatePName.SelectedValue;
  159. mod.Ptype = txtCreatePType.Text.Trim();
  160. mod.Rem = txtCreateRem.Text.Trim();
  161. mod.TltDocDdl = "";
  162. mod.TltDocDrl = "";
  163. mod.TltDocReport = "";
  164. mod.TltXlsDdl = "";
  165. mod.TltXlsDrl = "";
  166. mod.TltXlsPtype = "";
  167. mod.Class1 = "";
  168. mod.CreateTime = DateTime.Now;
  169. mod.GuidePrice = decimal.Parse(txtCreateGuidePrice.Text.Trim());
  170. try
  171. {
  172. int rtn=daProduct.Add(mod);
  173. if (rtn == 1)
  174. {
  175. this.BindProductTree();
  176. this.BindTypeList(mod.Pname,mod.Ptype);
  177. OperationResult.Text = "????????????"; divResult.Visible = true;
  178. }
  179. else
  180. {
  181. OperationResult.Text = "????????????"; divResult.Visible = true;
  182. }
  183. }
  184. catch (Exception ex)
  185. {
  186. log.Error("???????????", ex);
  187. OperationResult.Text = "????????????"; divResult.Visible = true;
  188. }
  189. }
  190. /// <summary>
  191. /// ?????
  192. /// </summary>
  193. protected void btnEditSave_Click(object sender, EventArgs e)
  194. {
  195. if (string.IsNullOrEmpty(txtEditPType.Text.Trim()))
  196. {
  197. OperationResult.Text = "????????"; divResult.Visible = true; return;
  198. }
  199. if (string.IsNullOrEmpty(txtEditGuidePrice.Text.Trim()))
  200. {
  201. OperationResult.Text = "????????"; divResult.Visible = true; return;
  202. }
  203. else
  204. {
  205. decimal decOut;
  206. if (!decimal.TryParse(txtEditGuidePrice.Text.Trim(),out decOut))
  207. {
  208. OperationResult.Text = "???????????"; divResult.Visible = true; return;
  209. }
  210. }
  211. MoProductCheckAbility mod = daProduct.GetEntities("")[0];
  212. mod.Ptype = txtEditPType.Text.Trim();
  213. mod.Rem = txtEditRem.Text.Trim();
  214. mod.GuidePrice = decimal.Parse(txtEditGuidePrice.Text.Trim());
  215. try
  216. {
  217. int rtn = daProduct.Update(mod);
  218. if (rtn == 1)
  219. {
  220. this.BindTypeList(mod.Pname, mod.Ptype);
  221. OperationResult.Text = "????????????"; divResult.Visible = true;
  222. }
  223. else
  224. {
  225. OperationResult.Text = "????????????"; divResult.Visible = true;
  226. }
  227. }
  228. catch (Exception ex)
  229. {
  230. log.Error("???????????", ex);
  231. OperationResult.Text = "????????????"; divResult.Visible = true;
  232. }
  233. }
  234. protected void repProductType_ItemCommand(object source, RepeaterCommandEventArgs e)
  235. {
  236. if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
  237. {
  238. switch (e.CommandName)
  239. {
  240. case "Edit":
  241. #region ??
  242. MoProductCheckAbility mod = daProduct.GetEntities(" where PCA_ID='"+e.CommandArgument.ToString()+"'")[0];
  243. txtEditRem.Text= mod.Rem;
  244. txtEditGuidePrice.Text=mod.GuidePrice.ToString();
  245. labEditID.Text = mod.PcaId;
  246. labEditPModel.Text = mod.Pmodel;
  247. labEditPName.Text = mod.Pname;
  248. txtEditPType.Text = mod.Ptype;
  249. this.SetPanelVisiable(editPanel);
  250. #endregion
  251. break;
  252. case "Delete":
  253. #region ??
  254. try
  255. {
  256. if (daProduct.DeleteByWhereClause(" where pca_id='" + e.CommandArgument.ToString() + "'") == 1)
  257. {
  258. this.BindTypeList(productTreeView.SelectedNode.Parent.Value, productTreeView.SelectedNode.Value);
  259. OperationResult.Text = "????????????"; divResult.Visible = true;
  260. }
  261. else
  262. {
  263. OperationResult.Text = "????????????"; divResult.Visible = true;
  264. }
  265. }
  266. catch (Exception ex)
  267. {
  268. log.Error("???????????", ex);
  269. OperationResult.Text = "????????????"; divResult.Visible = true;
  270. }
  271. #endregion
  272. break;
  273. case "cmd1":
  274. daProduct.RemoveTemplateFile(e.CommandArgument.ToString(), 1);
  275. btnRefresh_Click(null, null);
  276. break;
  277. case "cmd2":
  278. daProduct.RemoveTemplateFile(e.CommandArgument.ToString(), 2);
  279. btnRefresh_Click(null, null);
  280. break;
  281. case "cmd3":
  282. daProduct.RemoveTemplateFile(e.CommandArgument.ToString(), 3);
  283. btnRefresh_Click(null, null);
  284. break;
  285. case "cmd4":
  286. daProduct.RemoveTemplateFile(e.CommandArgument.ToString(), 4);
  287. btnRefresh_Click(null, null);
  288. break;
  289. case "cmd5":
  290. daProduct.RemoveTemplateFile(e.CommandArgument.ToString(), 5);
  291. btnRefresh_Click(null, null);
  292. break;
  293. case "cmd6":
  294. daProduct.RemoveTemplateFile(e.CommandArgument.ToString(), 6);
  295. btnRefresh_Click(null, null);
  296. break;
  297. default:
  298. return;
  299. }
  300. }
  301. }
  302. protected void btnRefresh_Click(object sender, EventArgs e)
  303. {
  304. //???????
  305. this.BindTypeList(productTreeView.SelectedNode.Parent.Value, productTreeView.SelectedNode.Value);
  306. }
  307. protected void ddlCreatePName_SelectedIndexChanged(object sender, EventArgs e)
  308. {
  309. if (!ckbIsNewPModel.Checked)
  310. {
  311. ddlCreatePModel.Items.Clear();
  312. ddlCreatePModel.DataSource = daProduct.GetDistinctModel(ddlCreatePName.SelectedValue);
  313. ddlCreatePModel.DataBind();
  314. }
  315. else
  316. {
  317. ddlCreatePModel.Attributes.Add("style", "display:none;");
  318. txtCreatePModel.Attributes.Add("style", "display:;");
  319. }
  320. }
  321. }