public static void BulkCopy(DataTable DTable, string TableName, string[] SourceColumn, string[] DestinationColumn, string ConnectionString)
 {
     DatabaseHelperExtension ObjDbaseExtension = new DatabaseHelperExtension(ConnectionString);
     bool ExecutionState = false;
     //to add columns to sqlbulkcopy object
     for (int index = 0; index < SourceColumn.Length && index < SourceColumn.Length; index++)
     {
         ObjDbaseExtension.AddColumn(SourceColumn.GetValue(index).ToString(), SourceColumn.GetValue(index).ToString());
     }
     ObjDbaseExtension.ExcuteSQLBulkCopy(DTable, TableName, ref ExecutionState);
 }
Example #2
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;
            }
        }
Example #3
0
        public void updateField()
        {
            bool IsSuccess = false;
            string CustomField = string.Empty;
            int fieldId = Convert.ToInt32(hdnfield.Value);
            ManageFieldsBase objManageFields = new ManageFieldsBase(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.Trim();
                    dr["value"] = box3.Text.Trim();
                    dr["FieldId"] = fieldId;
                    dtFields.Rows.Add(dr);
                }
                //removing all fields before updating values
                ManageFieldsPropertyBase objMFProp = new ManageFieldsPropertyBase(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, "ManageFieldsProperty", ref IsSuccess);
            }
            bindGrid("", 0);
            lblmsg.Style.Add("color", "green");
            lblmsg.Text = txtEditFieldName.Text + "  updated successfully";
        }