Exemplo n.º 1
0
        private void FillDataGrid()
        {
            dt_columns = DBFunctions.ReadFromDB("SELECT FALSE AS Checked,ColumnName,ColumnDBName FROM tableconfig WHERE TableDBName = '" + table_db_names[cbTables.SelectedIndex] + "'");

            dgColumns.Columns.Clear();
            dgColumns.DataSource = dt_columns;

            dgColumns.Columns["ColumnName"].HeaderText = "Имя колонки";
            dgColumns.Columns["ColumnName"].ReadOnly   = true;
            dgColumns.Columns["ColumnName"].FillWeight = 150;


            dgColumns.Columns["ColumnDBName"].HeaderText = "Имя колонки в базе данных";
            dgColumns.Columns["ColumnDBName"].ReadOnly   = true;
            dgColumns.Columns["ColumnDBName"].FillWeight = 50;


            DataGridViewCheckBoxColumn column_checked = new DataGridViewCheckBoxColumn();

            column_checked.TrueValue        = true;
            column_checked.FalseValue       = false;
            column_checked.Name             = "Копировать";
            column_checked.DataPropertyName = "Checked";
            column_checked.FillWeight       = 50;
            dgColumns.Columns.Remove("Checked");
            dgColumns.Columns.Insert(0, column_checked);

            dgColumns.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;


            dt_table = DBFunctions.ReadFromDB("SELECT FALSE AS Source, FALSE AS Destination, ID, " + data_field_names[cbTables.SelectedIndex] +
                                              " AS data_field FROM table_" + table_db_names[cbTables.SelectedIndex]);


            dgTableData.Columns.Clear();
            dgTableData.DataSource = dt_table;

            dgTableData.Columns["data_field"].HeaderText = "Данные строки";
            dgTableData.Columns["data_field"].ReadOnly   = true;
            dgTableData.Columns["data_field"].FillWeight = 300;

            dgTableData.Columns["ID"].ReadOnly   = true;
            dgTableData.Columns["ID"].FillWeight = 50;

            DataGridViewCheckBoxColumn column_source = new DataGridViewCheckBoxColumn();

            column_source.TrueValue        = true;
            column_source.FalseValue       = false;
            column_source.Name             = "Источник";
            column_source.DataPropertyName = "Source";
            column_source.FillWeight       = 30;
            dgTableData.Columns.Remove("Source");
            dgTableData.Columns.Insert(0, column_source);

            DataGridViewCheckBoxColumn column_destination = new DataGridViewCheckBoxColumn();

            column_destination.TrueValue        = true;
            column_destination.FalseValue       = false;
            column_destination.Name             = "Приемники";
            column_destination.DataPropertyName = "Destination";
            column_destination.FillWeight       = 30;
            dgTableData.Columns.Remove("Destination");
            dgTableData.Columns.Insert(1, column_destination);

            dgTableData.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
        }
Exemplo n.º 2
0
 public static string GetRefName(string ref_db_name, int id)
 {
     return((string)DBFunctions.ReadScalarFromDB("SELECT RefName FROM ref_data_" + ref_db_name + " WHERE ID = " + Convert.ToString(id)));
 }
Exemplo n.º 3
0
        private void tsbCopy_Click(object sender, EventArgs e)
        {
            dgColumns.EndEdit();
            dgTableData.EndEdit();
            string query_text = "UPDATE ";

            query_text += "table_" + table_db_names[cbTables.SelectedIndex] + " AS dest, ";
            query_text += "table_" + table_db_names[cbTables.SelectedIndex] + " AS src SET ";

            bool first = true;

            foreach (DataRow column_row in dt_columns.Rows)
            {
                if (Convert.ToBoolean(column_row["Checked"]))
                {
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        query_text += " , ";
                    }

                    query_text += "dest.`" + column_row["ColumnDBName"] + "` = src.`" + column_row["ColumnDBName"] + "`";
                }
            }

            int source_id = -1;

            foreach (DataRow row in dt_table.Rows)
            {
                if (Convert.ToBoolean(row["Source"]))
                {
                    if (source_id == -1)
                    {
                        source_id = (int)row["ID"];
                    }
                    else
                    {
                        System.Windows.Forms.MessageBox.Show("Выбрано больше одного источника", "Ошибка", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                        return;
                    }
                }
            }

            if (source_id == -1)
            {
                System.Windows.Forms.MessageBox.Show("Не выбрано ни одного источника", "Ошибка", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                return;
            }

            query_text += " WHERE dest.id = [d_id] AND src.id = " + Convert.ToString(source_id);

            foreach (DataRow row in dt_table.Rows)
            {
                if (Convert.ToBoolean(row["Destination"]))
                {
                    DBFunctions.ExecuteCommand(query_text.Replace("[d_id]", Convert.ToString(row["ID"])));
                }
            }

            System.Windows.Forms.MessageBox.Show("Копирование завершено.", "Успешное завершение", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
        }
        private void StringReplaseSettings_Load(object sender, EventArgs e)
        {
            //Получим наименование ключевого поля
            try
            {
                key_field_db_name = DBFunctions.GetGlobalParameter("StringReplaceKeyField");
            }
            catch (Exception err)
            {
                System.Windows.Forms.MessageBox.Show(err.Message, "Ошибка", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                Close();
            }

            //Теперь пользовательское наименование для размещения в label на тулстрипе
            Dictionary <string, object> parameters = new Dictionary <string, object>();

            parameters.Add("coldbname", key_field_db_name);
            tslKeyFieldName.Text = (string)DBFunctions.ReadScalarFromDB("SELECT ColumnName FROM tableconfig WHERE ColumnDBName = @coldbname", parameters);

            //Получим все возможные значения ключевого поля
            cbKeyFieldValues.Items.Clear();
            key_field_values = new ArrayList();
            DataTable dt_key_field_values = DBFunctions.ReadFromDB("SELECT DISTINCT " + key_field_db_name + " AS key_field FROM table_credprogr ORDER BY " + key_field_db_name);

            foreach (DataRow kf_row in dt_key_field_values.Rows)
            {
                cbKeyFieldValues.Items.Add(kf_row["key_field"]);
                key_field_values.Add(kf_row["key_field"]);
            }

            //Заполним справочники
            reference_db_names = new ArrayList();

            DataTable dt_references = DBFunctions.ReadFromDB("SELECT referencesconfig.ReferenceDBName,referencesconfig.ReferenceName FROM referencesconfig ORDER BY referencename");

            foreach (DataRow ref_row in dt_references.Rows)
            {
                cbReferenceNames.Items.Add(ref_row["ReferenceName"]);
                reference_db_names.Add(ref_row["ReferenceDBName"]);
            }

            dgReplaceStrings.AutoGenerateColumns = false;
            dgReplaceStrings.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;

            DataGridViewTextBoxColumn ref_id_column = new DataGridViewTextBoxColumn();

            ref_id_column.Name             = "ref_id";
            ref_id_column.HeaderText       = "ID элемента справочника";
            ref_id_column.DataPropertyName = "table_reference_id";
            ref_id_column.Visible          = false;
            dgReplaceStrings.Columns.Add(ref_id_column);

            DataGridViewComboBoxColumn ref_name_column = new DataGridViewComboBoxColumn();

            ref_name_column.Name             = "ref_name";
            ref_name_column.HeaderText       = "Элемент справочника";
            ref_name_column.DataPropertyName = "table_reference_value";
            dgReplaceStrings.Columns.Add(ref_name_column);

            DataGridViewTextBoxColumn replace_string_column = new DataGridViewTextBoxColumn();

            replace_string_column.Name             = "replace_string";
            replace_string_column.HeaderText       = "Строка для замены";
            replace_string_column.DataPropertyName = "replace_string";
            dgReplaceStrings.Columns.Add(replace_string_column);

            dt_replaces = new DataTable();

            dgReplaceStrings.DataSource = dt_replaces;

            cbReferenceNames.SelectedIndex = 0;
            cbKeyFieldValues.SelectedIndex = 0;

            TestRights();
        }