Ejemplo n.º 1
0
    }//end InsertCancelButton_Click


    /// <summary>
    /// 由新增模式,確認新增
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void InsertButton_Click(object sender, EventArgs e)
    {
        try
        {
            ErrorMsgLabel.Text = "";
            int AddRecord = 0;

            #region 取得畫面元件的值

            string v_Code = ""; //string v_Code = ((WUI.SLP.SLPUnique)FormView1.FindControl("TextBoxCode")).Text.Trim();
            //string v_Name = ((TextBox)FormView1.FindControl("SLP_RoleCode")).Text.Trim();
            DateTime processtime = DateTime.Now;
            string v_RoleCode = ((WUI.SLP.Role)this.FormView1.FindControl("SLP_RoleCode")).Text;
            string v_SystemCode = "VDS2G"; //string v_SystemCode = ((TextBox)FormView1.FindControl("SLP_SystemCode")).Text;
            string v_ProgramCode = ((WUI.SLP.Program)this.FormView1.FindControl("SLP_ProgramCode")).Text;
            string v_CanCreate = ((WUI.SLP.SLP_Boolean)FormView1.FindControl("SLP_CanCreate")).Text.Trim();
            string v_CanRead = ((WUI.SLP.SLP_Boolean)FormView1.FindControl("SLP_CanRead")).Text.Trim();
            string v_CanUpdate = ((WUI.SLP.SLP_Boolean)FormView1.FindControl("SLP_CanUpdate")).Text.Trim();
            string v_CanDelete = ((WUI.SLP.SLP_Boolean)FormView1.FindControl("SLP_CanDelete")).Text.Trim();

            SYSModel.MaintainRole BCO2 = new SYSModel.MaintainRole(ConnectionDB);
            ParameterList.Clear();
            ParameterList.Add(v_RoleCode);
            DataTable Chkrole = BCO2.QueryRoleByCode(ParameterList);
            if (Chkrole.Rows.Count != 1)
            {
                ErrorMsgLabel.Text = "請輸入正確角色代號";
                return;
            }

            SYSModel.MaintainRoleprogauthrel Uniq = new SYSModel.MaintainRoleprogauthrel(ConnectionDB);
            ParameterList.Clear();
            ParameterList.Add(v_RoleCode);
            ParameterList.Add(v_ProgramCode);
            DataTable Dup = Uniq.QueryDup(ParameterList);

            if (Dup.Rows.Count > 0)
            {
                if (Dup.Rows[0]["ENABLE"].ToString() == "1")
                {
                    throw new Exception("資料重覆!");
                }
            }

            ParameterList.Clear();
            ParameterList.Add(v_RoleCode);
            DataTable role_name = BCO2.QueryRoleByCode(ParameterList);
            string v_Name = role_name.Rows[0]["NAME"].ToString();
            #endregion

            #region 加入輸入條件

            ParameterList.Clear();

            ParameterList.Add(v_Code);
            ParameterList.Add(v_Name);
            ParameterList.Add(processtime);               //vCreateDate
            ParameterList.Add(Session["UID"].ToString()); //vCreateUID
            ParameterList.Add(processtime);               //vUpdateDate
            ParameterList.Add(Session["UID"].ToString()); //vUpdateUID
            ParameterList.Add(v_RoleCode);
            ParameterList.Add(v_SystemCode);
            ParameterList.Add(v_ProgramCode);
            ParameterList.Add(v_CanCreate);
            ParameterList.Add(v_CanRead);
            ParameterList.Add(v_CanUpdate);
            ParameterList.Add(v_CanDelete);

            #endregion

            SYSModel.MaintainRoleprogauthrel BCO = new SYSModel.MaintainRoleprogauthrel(ConnectionDB);
            AddRecord = BCO.CreateRoleprogauthrel(ParameterList, null);

            if (AddRecord == 0)
            {
                throw new Exception("新增0筆資料!");
            }
            else
            {
                Response.Write("<script>alert('新增完成');location.replace('SYS172.aspx?ID=" + AddRecord + "');</script>");
            }
        }
        catch (Exception ex)
        {
            ErrorMsgLabel.Text = ex.Message;
        }

    }