示例#1
0
        void EmitGenerateProvodkaToTempTable(StringBuilder sql, string indent, SchemaTableProvodka prov)
        {
            var masterTable = this;
            var detailTable = prov.OwnerTableOper.TableDetail.GetDetailTable();
            var operID = prov.OwnerTableOper.ID;

            if (prov.DbRegistrID != null)
            {
                var registr = App.Schema.GetSampleObject<SchemaTable>((Guid)prov.DbRegistrID);
                var registrFields = prov.DbRegistrFields;
                EmitGenerateProvodkaDbKrPartToTempTable(sql, indent, prov, DbKrSaldo.Дебет, registr, registrFields);
            }

            if (prov.KrRegistrID != null)
            {
                var registr = App.Schema.GetSampleObject<SchemaTable>((Guid)prov.KrRegistrID);
                var registrFields = prov.KrRegistrFields;
                EmitGenerateProvodkaDbKrPartToTempTable(sql, indent, prov, DbKrSaldo.Кредит, registr, registrFields);
            }
        }
示例#2
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");
        }