Пример #1
0
        protected void lbtnSave_Click(object sender, EventArgs e)
        {
            try
            {
                string CustomField = string.Empty;
                bool IsSuccess = false;
                DataTable dt = AdvanceManageFieldBase.SelectCustomFields(ConnectionString);

                    string[] array = dt.AsEnumerable().Select(row => row.Field<string>("Fieldname").ToLower()).ToArray();
                    if (!array.Contains(txtFieldName.Text.ToLower()))
                    {
                        AdvanceManageFieldBase objManageFields = new AdvanceManageFieldBase(ConnectionString);
                        //User bellow Expression to Eleminate the Empty Spaces
                        objManageFields.FieldName = Regex.Replace(txtFieldName.Text, "^[ \t\r\n]+|[ \t\r\n]+$", "");
                        objManageFields.FieldType = ddlFieldType.SelectedValue.ToString();
                        if (txtMaxLength.Text != "")
                            objManageFields.MaxLength = Convert.ToInt32(txtMaxLength.Text);
                        if (ddlFieldType.SelectedItem.Value == "Text Box")
                            objManageFields.DefaultValue = txtDefaultValue.Text;
                        else if (ddlFieldType.SelectedItem.Value == "Check Box")
                            objManageFields.DefaultValue = chkDefault.Checked.ToString();
                        else if (ddlFieldType.SelectedItem.Value == "Date")
                            objManageFields.DefaultValue = txtdate.Text;
                        if (txtDisplayPosition.Text != "")
                            objManageFields.DisplayPosition = Convert.ToInt32(txtDisplayPosition.Text);
                        objManageFields.PrimaryField = chkPrimaryField.Checked;
                        objManageFields.RequiredField = chkRequiredField.Checked;
                        objManageFields.PersonalizedField = chkPersonalizedField.Checked;
                        objManageFields.Reserved = false;
                        string customFields = string.Empty;
                        string[] arrayCustomFields = null;
                        if (dt.Rows.Count > 0)
                        {
                            if (dt.Rows.Count <= 20)
                            {
                                dt.AsEnumerable().ToList().ForEach(delegate(DataRow row) { customFields += row["ContactFieldName"].ToString() + ","; });

                                arrayCustomFields = customFields.Split(',');

                                if (arrayCustomFields != null)
                                {
                                    string[] allCustomField = new string[50];
                                    for (int i = 0; i < allCustomField.Length; i++)
                                    {
                                        allCustomField[i] = "CustomField" + (i + 1);

                                    }
                                    foreach (string nextCustomField in allCustomField)
                                    {
                                        if (Array.IndexOf(arrayCustomFields, nextCustomField) == -1)
                                        {
                                            CustomField = nextCustomField;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        else// if no custom fields avail
                        {
                            CustomField = "CustomField1";
                        }

                        objManageFields.ContactFieldName = CustomField;

                        int id = objManageFields.Insert(ConnectionString);

                        //insert the dropdown and radion button items and values into manage field property table
                        if (ddlFieldType.SelectedItem.Value == "Drop Down List" || ddlFieldType.SelectedItem.Value == "Radio Button List")
                        {
                            DataTable dtFields = new DataTable("ManageFieldsProperty");
                            dtFields.Columns.Add("Item"); //or something similar
                            dtFields.Columns.Add("value");
                            dtFields.Columns.Add("FieldId");
                            for (int i = 0; i < Gridview1.Rows.Count; ++i)
                            {
                                DataRow dr = dtFields.NewRow();
                                TextBox box2 = (TextBox)Gridview1.Rows[i].Cells[0].FindControl("TextBox1");
                                TextBox box3 = (TextBox)Gridview1.Rows[i].Cells[0].FindControl("TextBox2");

                                dr["Item"] = box2.Text;
                                dr["value"] = box3.Text;
                                dr["FieldId"] = id;
                                dtFields.Rows.Add(dr);

                            }

                            DatabaseHelperExtension odbseHelper = new DatabaseHelperExtension(ConnectionString);
                            odbseHelper.AddColumn("Item", "Item");
                            odbseHelper.AddColumn("value", "value");
                            odbseHelper.AddColumn("FieldId", "FieldId");
                            odbseHelper.ExcuteSQLBulkCopy(dtFields, "AdvanceManageFieldsProperty", ref IsSuccess);
                        }
                        //ManageFieldsPropertyBase objManageFieldsProp = new ManageFieldsPropertyBase(ConnectionString);
                        bindGrid("");
                        lblmsg.Style.Add("color", "green");
                        lblmsg.Text = txtFieldName.Text + " inserted successfully.";
                        ddlFieldType.SelectedIndex = 0;
                    }
                    else
                    {
                        lblmsg.Style.Add("color", "red");
                        lblmsg.Text = txtFieldName.Text + " Field alredy exist, Please enter some other Name.";
                    }

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #2
0
        /// <summary>
        /// Populates the fields of a single objects from the columns found in an open reader.
        /// </summary>
        /// <param name="obj" type="AdvanceManageFields">Object of AdvanceManageFields to populate</param>
        /// <param name="rdr" type="IDataReader">An object that implements the IDataReader interface</param>
        ///
        /// <remarks>
        ///
        /// <RevisionHistory>
        /// Author				Date			Description
        /// DLGenerator			8/29/2012 03:30:46 PM		Created function
        /// 
        /// </RevisionHistory>
        ///
        /// </remarks>
        ///
        internal static void PopulateObjectFromReader(AdvanceManageFieldBase obj,IDataReader rdr)
        {
            obj.FieldId = rdr.GetInt64(rdr.GetOrdinal(AdvanceManageFieldFields.FieldId));
            if (!rdr.IsDBNull(rdr.GetOrdinal(AdvanceManageFieldFields.FieldName)))
            {
                obj.FieldName = rdr.GetString(rdr.GetOrdinal(AdvanceManageFieldFields.FieldName));
            }

            if (!rdr.IsDBNull(rdr.GetOrdinal(AdvanceManageFieldFields.FieldType)))
            {
                obj.FieldType = rdr.GetString(rdr.GetOrdinal(AdvanceManageFieldFields.FieldType));
            }

            if (!rdr.IsDBNull(rdr.GetOrdinal(AdvanceManageFieldFields.InputDataType)))
            {
                obj.InputDataType = rdr.GetString(rdr.GetOrdinal(AdvanceManageFieldFields.InputDataType));
            }

            if (!rdr.IsDBNull(rdr.GetOrdinal(AdvanceManageFieldFields.TextTransformation)))
            {
                obj.TextTransformation = rdr.GetString(rdr.GetOrdinal(AdvanceManageFieldFields.TextTransformation));
            }

            if (!rdr.IsDBNull(rdr.GetOrdinal(AdvanceManageFieldFields.DefaultValue)))
            {
                obj.DefaultValue = rdr.GetString(rdr.GetOrdinal(AdvanceManageFieldFields.DefaultValue));
            }

            if (!rdr.IsDBNull(rdr.GetOrdinal(AdvanceManageFieldFields.RequiredField)))
            {
                obj.RequiredField = rdr.GetBoolean(rdr.GetOrdinal(AdvanceManageFieldFields.RequiredField));
            }

            if (!rdr.IsDBNull(rdr.GetOrdinal(AdvanceManageFieldFields.PrimaryField)))
            {
                obj.PrimaryField = rdr.GetBoolean(rdr.GetOrdinal(AdvanceManageFieldFields.PrimaryField));
            }

            if (!rdr.IsDBNull(rdr.GetOrdinal(AdvanceManageFieldFields.PersonalizedField)))
            {
                obj.PersonalizedField = rdr.GetBoolean(rdr.GetOrdinal(AdvanceManageFieldFields.PersonalizedField));
            }

            if (!rdr.IsDBNull(rdr.GetOrdinal(AdvanceManageFieldFields.DisplayPosition)))
            {
                obj.DisplayPosition = rdr.GetInt32(rdr.GetOrdinal(AdvanceManageFieldFields.DisplayPosition));
            }

            if (!rdr.IsDBNull(rdr.GetOrdinal(AdvanceManageFieldFields.MaxLength)))
            {
                obj.MaxLength = rdr.GetInt32(rdr.GetOrdinal(AdvanceManageFieldFields.MaxLength));
            }

            if (!rdr.IsDBNull(rdr.GetOrdinal(AdvanceManageFieldFields.Reserved)))
            {
                obj.Reserved = rdr.GetBoolean(rdr.GetOrdinal(AdvanceManageFieldFields.Reserved));
            }

            if (!rdr.IsDBNull(rdr.GetOrdinal(AdvanceManageFieldFields.ContactFieldName)))
            {
                obj.ContactFieldName = rdr.GetString(rdr.GetOrdinal(AdvanceManageFieldFields.ContactFieldName));
            }
        }
Пример #3
0
        protected void lbtnEditSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (hdnfield.Value != "")
                {
                    string CustomField = string.Empty;
                    bool IsSuccess = false;
                    int fieldId = Convert.ToInt32(hdnfield.Value);

                    AdvanceManageFieldBase objManageFields = new AdvanceManageFieldBase(ConnectionString);
                    objManageFields.FieldId = fieldId;

                    objManageFields.FieldName = txtEditFieldName.Text;
                    objManageFields.FieldType = DropDownList1.SelectedValue.ToString();
                    if (txtEditMaxLen.Text != "")
                        objManageFields.MaxLength = Convert.ToInt32(txtEditMaxLen.Text);

                    if (DropDownList1.SelectedItem.Value == "Text Box")
                        objManageFields.DefaultValue = txtEditDefaultValue.Text;

                    if (DropDownList1.SelectedItem.Value == "Check Box")
                        objManageFields.DefaultValue = chkEditDefault.Checked.ToString();

                    if (DropDownList1.SelectedItem.Value == "Date")
                        objManageFields.DefaultValue = txtEditDate.Text;
                    if (txtEditDispPos.Text != "")
                        objManageFields.DisplayPosition = Convert.ToInt32(txtEditDispPos.Text);
                    objManageFields.PrimaryField = chkEditPrimaryField.Checked;
                    objManageFields.RequiredField = chkEditReqField.Checked;
                    objManageFields.PersonalizedField = chkEditPersonalizedField.Checked;
                    objManageFields.Reserved = false;

                    IsSuccess = objManageFields.Update(ConnectionString);

                    if (DropDownList1.SelectedItem.Value == "Drop Down List" || DropDownList1.SelectedItem.Value == "Radio Button List")
                    {
                        DataTable dtFields = new DataTable("ManageFieldsProperty");
                        dtFields.Columns.Add("Item"); //or something similar
                        dtFields.Columns.Add("value");
                        dtFields.Columns.Add("FieldId");
                        for (int i = 0; i < Gridview2.Rows.Count; ++i)
                        {
                            DataRow dr = dtFields.NewRow();
                            TextBox box2 = (TextBox)Gridview2.Rows[i].Cells[0].FindControl("TextBox1");
                            TextBox box3 = (TextBox)Gridview2.Rows[i].Cells[0].FindControl("TextBox2");

                            dr["Item"] = box2.Text;
                            dr["value"] = box3.Text;
                            dr["FieldId"] = fieldId;
                            dtFields.Rows.Add(dr);
                        }
                        //removing all fields before updating values
                        AdvanceManageFieldsPropertyBase objMFProp = new AdvanceManageFieldsPropertyBase(ConnectionString);
                        objMFProp.Item = "FieldId";
                        objMFProp.Value = fieldId.ToString();
                        IsSuccess = objMFProp.Delete(ConnectionString);

                        DatabaseHelperExtension odbseHelper = new DatabaseHelperExtension(ConnectionString);
                        odbseHelper.AddColumn("Item", "Item");
                        odbseHelper.AddColumn("value", "value");
                        odbseHelper.AddColumn("FieldId", "FieldId");
                        odbseHelper.ExcuteSQLBulkCopy(dtFields, "AdvanceManageFieldsProperty", ref IsSuccess);
                    }
                    lblmsg.Style.Add("color", "green");
                    lblmsg.Text = txtEditFieldName.Text + "  updated successfully";
                    bindGrid("");
                }
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }
Пример #4
0
        protected void lbtnSaveField_Click(object sender, EventArgs e)
        {
            try
            {
                string CustomField = string.Empty;

                DataTable dt = AdvanceManageFieldBase.SelectCustomFields(ConnectionString);
                DataTable tblFields = RecipientMaster.GetRecipientMasterFields(ConnectionString);

                string[] custFields = dt.AsEnumerable().Select(row => row.Field<string>("Fieldname").ToLower()).ToArray();
                string[] standFields = null;
                if (tblFields.Rows.Count > 0)
                    standFields = tblFields.Rows[0]["TableFields"].ToString().ToLower().Split(',');
                string[] FieldNames = new string[custFields.Length + standFields.Length];
                custFields.CopyTo(FieldNames, 0);
                standFields.CopyTo(FieldNames, custFields.Length);
                if (!FieldNames.Contains(txtFieldName.Text.ToLower()))
                {
                    AdvanceManageFieldBase objManageFields = new AdvanceManageFieldBase(ConnectionString);
                    objManageFields.FieldName = txtFieldName.Text;
                    objManageFields.FieldType = "Text Box";
                    if (txtMaxLength.Text != "")
                        objManageFields.MaxLength = Convert.ToInt32(txtMaxLength.Text);
                    objManageFields.DefaultValue = txtDefaultValue.Text;
                    if (txtDisplayPosition.Text != "")
                        objManageFields.DisplayPosition = Convert.ToInt32(txtDisplayPosition.Text);
                    objManageFields.RequiredField = chkRequiredField.Checked;
                    objManageFields.PersonalizedField = chkPersonalizedField.Checked;
                    objManageFields.Reserved = false;
                    string customFields = string.Empty;
                    string[] arrayCustomFields = null;
                    if (dt.Rows.Count > 0)
                    {
                        if (dt.Rows.Count <= 20)
                        {
                            dt.AsEnumerable().ToList().ForEach(delegate(DataRow row) { customFields += row["ContactFieldName"].ToString() + ","; });

                            arrayCustomFields = customFields.Split(',');

                            if (arrayCustomFields != null)
                            {
                                string[] allCustomField = new string[20];
                                for (int i = 0; i < allCustomField.Length; i++)
                                {
                                    allCustomField[i] = "CustomField" + (i + 1);

                                }
                                foreach (string nextCustomField in allCustomField)
                                {
                                    if (Array.IndexOf(arrayCustomFields, nextCustomField) == -1)
                                    {
                                        CustomField = nextCustomField;
                                        break;
                                    }
                                }
                            }
                        }
                        else
                        {

                        }
                    }
                    else
                    {
                        CustomField = "CustomField1";
                    }
                    objManageFields.ContactFieldName = CustomField;
                    int id = objManageFields.Insert(ConnectionString);
                    lblmessage.ForeColor = System.Drawing.Color.Green;
                    lblmessage.Text = "Field '" + txtFieldName.Text + "' created successfully";
                    if (tblFields != null && tblFields.Rows.Count > 0)
                    {
                        BindDropdowns(tblFields.Rows[0]["TableFields"].ToString().Split(','));
                    }

                    NewFieldModalPopup.Hide();
                    upnlmsg.Update();

                }
                else
                {
                    lblFieldMsg.Style.Add("color", "red");
                    lblFieldMsg.Text = txtFieldName.Text + " Field alredy exist, Please enter some other Name.";
                }
            }

            catch (Exception ex)
            {
                throw ex;
            }
        }