lixiaojun
2024-12-20 a7c780692ab2d8072ad4cae0fecbf851c27231d9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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;
        }
         
    }
}