Example #1
0
        void EmitGenerateProvodkaDbKrPartToTempTable(StringBuilder sql, string indent, SchemaTableProvodka prov, DbKrSaldo dbKr, SchemaTable registr, ObservableCollection<SchemaTableProvodkaField> registrFields)
        {
            var masterTable = this;
            var detailTable = prov.OwnerTableOper.TableDetail.GetDetailTable();
            var operID = prov.OwnerTableOper.ID;

            sql.AppendLine(indent + "-- " + dbKr + ", регистр: " + registr.Name.AsSQL() + ",  деталь: " + prov.OwnerTableOper.TableDetail.Name.AsSQL() + ",  операция: '[" + prov.OwnerTableOper.Num + "]  " + prov.OwnerTableOper.Name + "',  проводка: " + prov.Name.AsSQL());
            sql.AppendLine(indent + "INSERT " + registr.GetRegistrTempTableName() + "(");

            sql.AppendLine(indent + "  [" + registr.GetColumnByRole(RoleConst.Таблица_Ключ).Name + "],");
            sql.AppendLine(indent + "  [" + registr.GetColumnByRole(RoleConst.Регистр_ДбКр).Name + "],");
            sql.AppendLine(indent + "  [" + registr.GetColumnByRole(RoleConst.Регистр_КонфигДеталь).Name + "],");
            sql.AppendLine(indent + "  [" + registr.GetColumnByRole(RoleConst.Регистр_КонфигБизнесОперация).Name + "],");
            sql.AppendLine(indent + "  [" + registr.GetColumnByRole(RoleConst.Регистр_КонфигПроводка).Name + "],");

            sql.AppendLine(indent + "  [" + registr.GetColumnByRole(RoleConst.Регистр_Мастер).Name + "],");
            sql.AppendLine(indent + "  [" + registr.GetColumnByRole(RoleConst.Регистр_Деталь).Name + "],");

            foreach (var field in registrFields.Where(field => registr.GetColumnByName(field.RegistrFieldName) != null))
            {
                sql.AppendLine(indent + "  [" + field.RegistrFieldName + "],");
            }

            sql.RemoveLastChar(3);
            sql.AppendLine();

            sql.AppendLine(indent + ")");
            sql.AppendLine(indent + "SELECT");

            sql.AppendLine(indent + "  NewID(),");
            sql.AppendLine(indent + "  '" + dbKr.ToString()[0] + "',");
            sql.AppendLine(indent + "  " + prov.OwnerTableOper.TableDetail.ID.AsSQL() + ",  -- деталь: " + prov.OwnerTableOper.TableDetail.Name);
            sql.AppendLine(indent + "  " + prov.OwnerTableOper.ID.AsSQL() + ",  -- бизнес-операция: " + prov.OwnerTableOper.Name);
            sql.AppendLine(indent + "  " + prov.ID.AsSQL() + ",  -- проводка: " + prov.Name);

            sql.AppendLine(indent + "  @masterID,");
            sql.AppendLine(indent + "  " + detailTable.Get4PartsTableName() + ".[" + detailTable.GetColumnByRole(RoleConst.Таблица_Ключ).Name + "],");

            foreach (var field in registrFields.Where(field => registr.GetColumnByName(field.RegistrFieldName) != null))
            {
                if (field.DataFieldName == "<пусто>")
                    sql.AppendLine(indent + "  NULL,");
                else
                {
                    if (dbKr == DbKrSaldo.Кредит && registr.GetColumnByName(field.RegistrFieldName).ColumnRoles.Contains(RoleConst.Регистр_Мера))
                        sql.AppendLine(indent + "  -" + detailTable.Get4PartsTableName() + ".[" + field.DataFieldName + "],");
                    else
                        sql.AppendLine(indent + "  " + detailTable.Get4PartsTableName() + ".[" + field.DataFieldName + "],");
                }
            }

            sql.RemoveLastChar(3);
            sql.AppendLine();

            sql.AppendLine(indent + "FROM " + detailTable.Get4PartsTableName());
            sql.AppendLine(indent + "WHERE " + detailTable.Get4PartsTableName() + ".[" + detailTable.GetColumnByRole(RoleConst.ВложеннаяТаблица_БизнесОперация).Name + "]=" + operID.AsSQL() + " AND ");
            sql.AppendLine(indent + "      " + detailTable.Get4PartsTableName() + ".[" + detailTable.GetColumnByRole(RoleConst.ВложеннаяТаблица_Мастер).Name + "]=@masterID");
        }
Example #2
0
        void EmitSaveRegistrFromTempTable(StringBuilder sql, string indent, SchemaTable registrTable)
        {
            sql.Append(indent + "INSERT " + registrTable.Get4PartsTableName() + "(");
            foreach (var col in registrTable.Columns)
                sql.Append("[" + col.Name + "],");
            sql.RemoveLastChar(1);
            sql.Append(") SELECT ");
            foreach (var col in registrTable.Columns)
                sql.Append("[" + col.Name + "],");
            sql.RemoveLastChar(1);
            sql.AppendLine(" FROM " + registrTable.GetRegistrTempTableName());

            sql.Append(indent + "INSERT " + GetProvodkasTable().Get4PartsTableName() + "(tableRecordID,provodkaRecordID,registrID)");
            sql.AppendLine(" SELECT @masterID,[" + registrTable.GetPrimaryKeyColumn().Name + "]," + registrTable.ID.AsSQL() + " FROM " + registrTable.GetRegistrTempTableName());
        }
Example #3
0
 void EmitCreateRegisterTempTable(StringBuilder sql, string indent, SchemaTable registrTable)
 {
     sql.AppendLine(indent + "CREATE TABLE " + registrTable.GetRegistrTempTableName() + "(");
     foreach (var col in registrTable.Columns)
     {
         sql.AppendLine(indent + "  [" + col.Name + "] " + col.DataType.GetDeclareSql() + ",");
     }
     sql.RemoveLastChar(3);
     sql.AppendLine();
     sql.AppendLine(indent + ")");
 }