Ejemplo n.º 1
0
 protected void BindData()
 {
     foreach (Dictionary <int, Model.CCOM.User_subject_value> oldChildrenDic in oldDic.Values)
     {
         foreach (Model.CCOM.User_subject_value valueModel in oldChildrenDic.Values)
         {
             if (valueModel.Usv_children != null)
             {
                 DropDownList ddlTitle = (DropDownList)this.divControls.FindControl("title" + valueModel.Subject_id + "children" + valueModel.Usv_children);
                 ddlTitle.SelectedValue = valueModel.Usv_value;
                 visibleChange(ddlTitle);
                 TextBox tbValue = (TextBox)this.divControls.FindControl("value" + valueModel.Subject_id + "children" + valueModel.Usv_children);
                 if (tbValue != null && oldDic.ContainsKey(Convert.ToInt32(valueModel.Usv_value)))
                 {
                     Model.CCOM.User_subject_value cValueModel = oldDic[Convert.ToInt32(valueModel.Usv_value)][0];
                     tbValue.Text = cValueModel.Usv_value;
                 }
             }
             else
             {
                 TextBox tbValue = null;
                 if (subjectDic[valueModel.Subject_id].Value_type == 3)
                 {
                     tbValue = (TextBox)this.divControls.FindControl("value" + valueModel.Subject_id);
                     if (tbValue != null)
                     {
                         tbValue.Text = valueModel.Usv_value;
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (!Page.IsValid)
            {
                return;
            }
            if (DateTime.Now > period.Period_register_end)
            {
                JscriptMsg("已超过注册时间!", Utils.CombUrlTxt("../center.aspx", "fun_id={0}", DESEncrypt.Encrypt(this.fun_id)), "Error");
            }
            // 新值字典
            foreach (BaseValidator validator in this.Validators)
            {
                Panel subjectPanel = (Panel)validator.Parent;
                if (subjectPanel.Visible == true && validator.Enabled == true)
                {
                    int childrenIndex = subjectPanel.ID.IndexOf("children");
                    if (validator.ID.Contains("title"))
                    {
                        //下拉框
                        String       subjectString  = subjectPanel.ID.Substring(0, childrenIndex);
                        String       childrenString = subjectPanel.ID.Replace(subjectString, "");
                        int          fatherId       = Convert.ToInt32(subjectString.Replace("subjectPanel", ""));
                        int          childrenId     = Convert.ToInt32(childrenString.Replace("children", ""));
                        DropDownList ddlTitle       = (DropDownList)subjectPanel.FindControl("title" + fatherId + "children" + childrenId);
                        Model.CCOM.User_subject_value valueModel = new Model.CCOM.User_subject_value();
                        valueModel.User_id      = userId;
                        valueModel.Subject_id   = fatherId;
                        valueModel.Usv_children = childrenId;
                        valueModel.Usv_value    = ddlTitle.SelectedValue;
                        if (!newDic.ContainsKey(fatherId))
                        {
                            newDic.Add(fatherId, new Dictionary <int, Model.CCOM.User_subject_value>());
                        }
                        if (!newDic[fatherId].ContainsKey(childrenId))
                        {
                            newDic[fatherId].Add(childrenId, valueModel);
                        }
                    }
                    else
                    {
                        //文本
                        int     subjectId = 0;
                        TextBox tbValue   = null;
                        if (childrenIndex == -1)
                        {
                            //非子节点
                            subjectId = Convert.ToInt32(subjectPanel.ID.Replace("subjectPanel", ""));
                            tbValue   = (TextBox)subjectPanel.FindControl("value" + subjectId);
                        }
                        else
                        {
                            //子节点
                            String childrenString = subjectPanel.ID.Replace("subjectPanel", "");
                            //拿到下拉框取值
                            DropDownList ddltitle = (DropDownList)subjectPanel.FindControl("title" + childrenString);
                            subjectId = Convert.ToInt32(ddltitle.SelectedValue);
                            tbValue   = (TextBox)subjectPanel.FindControl("value" + childrenString);
                        }
                        if (!newDic.ContainsKey(subjectId))
                        {
                            Model.CCOM.User_subject_value valueModel = new Model.CCOM.User_subject_value();
                            valueModel.User_id    = userId;
                            valueModel.Subject_id = subjectId;
                            valueModel.Usv_value  = tbValue.Text;
                            newDic.Add(subjectId, new Dictionary <int, Model.CCOM.User_subject_value>());
                            newDic[subjectId].Add(0, valueModel);
                        }
                    }
                }
            }

            BLL.CCOM.User_subject_value vbll = new BLL.CCOM.User_subject_value();
            // 对比update
            foreach (Dictionary <int, Model.CCOM.User_subject_value> newChildrenDic in newDic.Values)
            {
                foreach (Model.CCOM.User_subject_value valueModel in newChildrenDic.Values)
                {
                    if (subjectDic[valueModel.Subject_id].Value_type == 3)
                    {
                        if (oldDic.ContainsKey(valueModel.Subject_id))
                        {
                            valueModel.Usv_id = oldDic[valueModel.Subject_id][0].Usv_id;
                            vbll.Update(valueModel);
                            oldDic.Remove(valueModel.Subject_id);
                        }
                        else
                        {
                            vbll.Add(valueModel);
                        }
                    }
                    else
                    {
                        if (oldDic.ContainsKey(valueModel.Subject_id) && oldDic[valueModel.Subject_id].ContainsKey((int)valueModel.Usv_children))
                        {
                            valueModel.Usv_id = oldDic[valueModel.Subject_id][(int)valueModel.Usv_children].Usv_id;
                            vbll.Update(valueModel);
                            oldDic[valueModel.Subject_id].Remove((int)valueModel.Usv_children);
                        }
                        else
                        {
                            vbll.Add(valueModel);
                        }
                    }
                }
            }
            // 批量删除
            String deleteList = "";
            bool   isFirst    = true;

            foreach (Dictionary <int, Model.CCOM.User_subject_value> oldChildrenDic in oldDic.Values)
            {
                foreach (Model.CCOM.User_subject_value valueModel in oldChildrenDic.Values)
                {
                    if (isFirst)
                    {
                        isFirst = false;
                    }
                    else
                    {
                        deleteList += ",";
                    }
                    deleteList += "'" + valueModel.Usv_id + "'";
                }
            }
            if (!isFirst)
            {
                vbll.DeleteList(deleteList);
            }
            JscriptMsg("报考成功!", Utils.CombUrlTxt("../center.aspx", "fun_id={0}", DESEncrypt.Encrypt(this.fun_id)), "Success");
        }