Ejemplo n.º 1
0
        protected void lbtnSave_Click(object sender, EventArgs e)
        {
            try
            {
                string CustomField = string.Empty;
                bool IsSuccess = false;
                DataTable dt = ManageFieldsBase.SelectCustomFields(ConnectionString);

                //Convert DataTable to ArrayList.
                string[] fieldNames = dt.AsEnumerable().Select(row => row.Field<string>("Fieldname").ToLower()).ToArray();

                int flag = 0;
                foreach (var Text in TableTextFields)
                {
                    if (Text.ToString().ToLower() == txtFieldName.Text.ToLower())
                        flag = 2;
                }
                if (fieldNames.Contains(txtFieldName.Text.ToString().ToLower().Trim()))
                    flag = 1;
                if (flag == 0 && dt.Rows.Count < 50)
                {
                    ManageFieldsBase objManageFields = new ManageFieldsBase(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 <= 50)
                        {
                            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.Trim();
                            dr["value"] = box3.Text.Trim();
                            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, "ManageFieldsProperty", ref IsSuccess);
                    }
                    //ManageFieldsPropertyBase objManageFieldsProp = new ManageFieldsPropertyBase(ConnectionString);
                    bindGrid("", 0);
                    lblmsg.Style.Add("color", "green");
                    lblmsg.Text = txtFieldName.Text + " inserted successfully.";
                    ddlFieldType.SelectedIndex = 0;
                }
                else if (flag == 1)
                {
                    lblmsg.Style.Add("color", "red");
                    lblmsg.Text = txtFieldName.Text + " Field already exist, Please enter some other Name.";
                }
                else if (flag == 2)
                {
                    lblmsg.Style.Add("color", "red");
                    lblmsg.Text = txtFieldName.Text + " is default, Please enter some other Name.";
                }
                else
                {
                    lblmsg.Style.Add("color", "red");
                    lblmsg.Text = "Your account have reached the maximum limit (50) for the custom fields creation. Please delete the unused existing custome field then try to add a new field!!!";
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 2
0
        protected void lbtnSaveField_Click(object sender, EventArgs e)
        {
            try
            {
                string CustomField = string.Empty;
                lblFieldMsg.Text = "";

                DataTable dt = ManageFieldsBase.SelectCustomFields(Connectionstring);
                int flag = 0;
                foreach (DataRow dr in dt.Rows)
                {
                    if (dr["Fieldname"].ToString().ToLower() == txtFieldName.Text.ToLower())
                        flag = 1;
                }
                foreach (var Text in TableTextFields)
                {
                    if (Text.ToString().ToLower() == txtFieldName.Text.ToLower())
                        flag = 1;
                }
                if (flag == 0)
                {
                    ManageFieldsBase objManageFields = new ManageFieldsBase(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 <= 50)
                        {
                            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
                    {
                        CustomField = "CustomField1";
                    }
                    objManageFields.ContactFieldName = CustomField;
                    int id = objManageFields.Insert(Connectionstring);
                    lblmessage.Text = "Field '" + txtFieldName.Text + "' created successfully";
                    BindDropdowns(TableFields, TableTextFields);
                    NewFieldModalPopup.Hide();
                    upnlmsg.Update();
                }
                else
                {
                    lblFieldMsg.Style.Add("color", "red");
                    lblFieldMsg.Text = txtFieldName.Text + " Field already exist, Please enter some other Name.";
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }