Пример #1
0
    protected void RadDataForm1_ItemCreated(object sender, Telerik.Web.UI.RadDataFormItemEventArgs e)
    {
        if (e.Item is RadDataFormDataItem && !(e.Item.IsInEditMode))
        {
            RadDataFormDataItem item            = e.Item as RadDataFormDataItem;
            RadComboBox         RadItemDpdBrch1 = (RadComboBox)item.FindControl("RadItemDpdBrch1");
            qry  = "Execute PROC_GET_BRANCH";
            Cn   = new SqlConnection(constsql);
            myda = new SqlDataAdapter(qry, Cn);
            ds   = new DataSet();
            myda.Fill(ds);
            RadItemDpdBrch1.DataSource     = ds.Tables[0];
            RadItemDpdBrch1.DataTextField  = ds.Tables[0].Columns["BranchName"].ColumnName.ToString();
            RadItemDpdBrch1.DataValueField = ds.Tables[0].Columns["BRANCHID"].ColumnName.ToString();
            RadItemDpdBrch1.DataBind();

            RadDataFormDataItem items          = e.Item as RadDataFormDataItem;
            RadComboBox         RadItemDpdDpt1 = (RadComboBox)items.FindControl("RadItemDpdDpt1");
            qry2  = "SELECT DepartmentID,DepartmentName FROM Department";
            myda2 = new SqlDataAdapter(qry2, Cn);
            ds2   = new DataSet();
            myda2.Fill(ds2);
            RadItemDpdDpt1.DataSource     = ds2.Tables[0];
            RadItemDpdDpt1.DataTextField  = ds2.Tables[0].Columns["DepartmentName"].ColumnName.ToString();
            RadItemDpdDpt1.DataValueField = ds2.Tables[0].Columns["DepartmentID"].ColumnName.ToString();
            RadItemDpdDpt1.DataBind();
        }

        else if (e.Item.IsInEditMode || (e.Item is RadDataFormEditableItem))
        {
            // edit template control

            RadDataFormEditableItem item            = e.Item as RadDataFormEditableItem;
            RadComboBox             RadItemDpdBrch2 = (RadComboBox)item.FindControl("RadItemDpdBrch2");
            qry  = "Execute PROC_GET_BRANCH";
            Cn   = new SqlConnection(constsql);
            myda = new SqlDataAdapter(qry, Cn);
            ds   = new DataSet();
            myda.Fill(ds);
            RadItemDpdBrch2.DataSource     = ds.Tables[0];
            RadItemDpdBrch2.DataTextField  = ds.Tables[0].Columns["BranchName"].ColumnName.ToString();
            RadItemDpdBrch2.DataValueField = ds.Tables[0].Columns["BRANCHID"].ColumnName.ToString();
            RadItemDpdBrch2.DataBind();

            RadDataFormDataItem items          = e.Item as RadDataFormDataItem;
            RadComboBox         RadItemDpdDpt2 = (RadComboBox)items.FindControl("RadItemDpdDpt2");
            qry2  = "SELECT DepartmentID,DepartmentName FROM Department";
            myda2 = new SqlDataAdapter(qry2, Cn);
            ds2   = new DataSet();
            myda2.Fill(ds2);
            RadItemDpdDpt2.DataSource     = ds2.Tables[0];
            RadItemDpdDpt2.DataTextField  = ds2.Tables[0].Columns["DepartmentName"].ColumnName.ToString();
            RadItemDpdDpt2.DataValueField = ds2.Tables[0].Columns["DepartmentID"].ColumnName.ToString();
            RadItemDpdDpt2.DataBind();
        }
    }
Пример #2
0
    protected void RadDataForm1_ItemInserting(object sender, Telerik.Web.UI.RadDataFormCommandEventArgs e)
    {
        RadDataFormEditableItem insertedItem = e.DataFormItem as RadDataFormEditableItem;
        Hashtable newValues = new Hashtable();

        insertedItem.ExtractValues(newValues);


        try
        {
            RadComboBox RadItemDpdDpt3     = (RadComboBox)insertedItem.FindControl("RadItemDpdDpt3");
            RadComboBox RadItemDpdBrch3    = (RadComboBox)insertedItem.FindControl("RadItemDpdBrch3");
            CheckBox    IsActionOwnerChk2s = (CheckBox)insertedItem.FindControl("IsActionOwnerChk2");
            string      email     = newValues["EMAIL"].ToString();
            string      lastname  = PropCase(newValues["LastName"].ToString());
            string      username  = newValues["USER_NAME"].ToString();
            string      FirstName = PropCase(newValues["FirstName"].ToString());

            int  deptid            = Convert.ToInt32(RadItemDpdDpt3.SelectedValue);
            int  brchid            = Convert.ToInt32(RadItemDpdBrch3.SelectedValue);
            bool IsActionOwnerChk2 = IsActionOwnerChk2s.Checked;
            if (IsActionOwnerChk2 == true)
            {
                IsActionOwnerChkss = "Yes";
            }
            else
            {
                IsActionOwnerChkss = "No";
            }

            qry = "INSERT INTO USERS(DEPARTMENTID,BRANCHID,USER_NAME,EMAIL,LASTNAME,FIRSTNAME,IsActionOwner)VALUES(" + Convert.ToInt32(RadItemDpdDpt3.SelectedValue) + ", " + Convert.ToInt32(RadItemDpdBrch3.SelectedValue) + ",'" + newValues["USER_NAME"].ToString() + "','" + newValues["EMAIL"].ToString() + "','" + PropCase(newValues["LastName"].ToString()) + "','" + PropCase(newValues["FirstName"].ToString()) + "','" + IsActionOwnerChkss + "')";
            con.SqlDs(qry, 1);
        }
        catch (Exception ex)
        {
            con.insertError(ex.Message);
            e.Canceled = true;
        }
        LoadDataForRadGrid1();
        RadGrid1.DataBind();
    }
Пример #3
0
    protected void RadDataForm1_ItemUpdating(object sender, Telerik.Web.UI.RadDataFormCommandEventArgs e)
    {
        RadDataFormEditableItem editedItem = e.DataFormItem as RadDataFormEditableItem;
        Hashtable newValues = new Hashtable();

        editedItem.ExtractValues(newValues);

        DataTable productsTable = SourceDataTable;

        DataRow[] changedRows = productsTable.Select("USER_NAME = '" + editedItem.GetDataKeyValue("USER_NAME") + "'");

        if (changedRows.Length != 1)
        {
            e.Canceled = true;
            return;
        }
        try
        {
            RadComboBox RadItemDpdDpt2    = (RadComboBox)editedItem.FindControl("RadItemDpdDpt2");
            RadComboBox RadItemDpdBrch2   = (RadComboBox)editedItem.FindControl("RadItemDpdBrch2");
            CheckBox    ResetPassCheckBox = (CheckBox)editedItem.FindControl("ResetPassCheckBox1");
            CheckBox    IsActionOwnerChk  = (CheckBox)editedItem.FindControl("IsActionOwnerChk1");
            string      email             = newValues["EMAIL"].ToString();
            string      lastname          = newValues["LastName"].ToString();
            string      username          = newValues["USER_NAME"].ToString();
            string      FirstName         = newValues["FirstName"].ToString();
            int         id                = Convert.ToInt32(newValues["USERID"]);
            int         deptid            = Convert.ToInt32(RadItemDpdDpt2.SelectedValue);
            int         brchid            = Convert.ToInt32(RadItemDpdBrch2.SelectedValue);
            bool        chkedpass         = ResetPassCheckBox.Checked;
            bool        IsActionOwnerChks = IsActionOwnerChk.Checked;
            if (IsActionOwnerChks == true)
            {
                IsActionOwnerChkss = "Yes";
            }
            else
            {
                IsActionOwnerChkss = "No";
            }
            if (chkedpass == true)
            {
                passwords = Users.Users.Encrypt("123456", true);
                foreach (DictionaryEntry entry in newValues)
                {
                    qrys = "UPDATE USERS SET IsActionOwner='" + IsActionOwnerChkss + "',PASSWORD='******', DEPARTMENTID=" + Convert.ToInt32(RadItemDpdDpt2.SelectedValue) + ",  BRANCHID=" + Convert.ToInt32(RadItemDpdBrch2.SelectedValue) + ", USER_NAME=  '" + newValues["USER_NAME"].ToString() + "',EMAIL= '" + newValues["EMAIL"].ToString() + "',LASTNAME= '" + PropCase(newValues["LastName"].ToString()) + "',FIRSTNAME= '" + PropCase(newValues["FirstName"].ToString()) + "' WHERE USERID=" + Convert.ToInt32(newValues["USERID"]) + "";
                    con.SqlDs(qrys, 1);
                }
            }
            else
            {
                foreach (DictionaryEntry entry in newValues)
                {
                    qrys = "UPDATE USERS SET IsActionOwner='" + IsActionOwnerChkss + "',DEPARTMENTID=" + Convert.ToInt32(RadItemDpdDpt2.SelectedValue) + ",  BRANCHID=" + Convert.ToInt32(RadItemDpdBrch2.SelectedValue) + ", USER_NAME=  '" + newValues["USER_NAME"].ToString() + "',EMAIL= '" + newValues["EMAIL"].ToString() + "',LASTNAME= '" + PropCase(newValues["LastName"].ToString()) + "',FIRSTNAME= '" + PropCase(newValues["FirstName"].ToString()) + "' WHERE USERID=" + Convert.ToInt32(newValues["USERID"]) + "";
                    con.SqlDs(qrys, 1);
                }
            }
        }
        catch (Exception ex)
        {
            con.insertError(ex.Message);
            changedRows[0].CancelEdit();
            e.Canceled = true;
        }
        LoadDataForRadGrid1();
        RadGrid1.DataBind();
    }