duheng
2024-12-20 828911bb8a1e71a3c6c28f70b5e9d9562451d7f4
WinFrmUI/HStation.WinFrmUI.Xhs.Core/03-simulation/04-scheme/00-core/CreateXhsSchemeHelper.cs
@@ -1,11 +1,48 @@
namespace HStation.WinFrmUI
using NPOI.Util;
namespace HStation.WinFrmUI
{
    /// <summary>
    ///
    /// </summary>
    public class CreateXhsSchemeHelper
    {
        public static async Task<bool> Create(CreateXhsSchemeViewModel vm)
        {
            if (vm == null)
                return false;
            var hydro_model_id = await Yw.BLLFactory<Yw.BLL.HydroModel>.Instance.Copy(vm.HydroInfo.ID);
            if (hydro_model_id > 0)
            {
                var xhs_scheme_id = await Yw.BLLFactory<HStation.BLL.XhsScheme>.Instance.Insert(vm.Scheme);
                if (xhs_scheme_id < 0)
                {
                    await Yw.BLLFactory<HStation.BLL.XhsScheme>.Instance.DeleteByID(hydro_model_id);
                    return false;
                }
                var hydro_relation = new Yw.Vmo.HydroModelRelationVmo();
                hydro_relation.ObjectType = HStation.Xhs.DataType.XhsScheme;
                hydro_relation.ObjectID = xhs_scheme_id;
                hydro_relation.ModelID = hydro_model_id;
                hydro_relation.Purpose = HStation.Xhs.Purpose.Simulation;
                hydro_relation.Content = null;
                hydro_relation.Description = vm.Scheme.Description;
                var hydro_relation_id = await BLLFactory<Yw.BLL.HydroModelRelation>.Instance.Insert(hydro_relation);
                if (hydro_relation_id < 1)
                {
                    await Yw.BLLFactory<Yw.BLL.HydroModel>.Instance.DeleteByID(hydro_model_id);
                    await Yw.BLLFactory<HStation.BLL.XhsScheme>.Instance.DeleteByID(xhs_scheme_id);
                    return false;
                }
                vm.Scheme = await BLLFactory<HStation.BLL.XhsScheme>.Instance.GetByID(xhs_scheme_id);
            }
            return true;
        }
         
    }
}