PageRenderTime 24ms CodeModel.GetById 10ms app.highlight 11ms RepoModel.GetById 0ms app.codeStats 0ms

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