duheng
2025-01-13 e7df5d1ece7ecabaa7a3943f24a6621649fdc455
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using DevExpress.XtraCharts.Designer;
using Yw;
 
namespace HStation.WinFrmUI
{
    public partial class ImportTranslationExcel : DevExpress.XtraEditors.XtraForm
    {
        public ImportTranslationExcel()
        {
            InitializeComponent();
            this.IconOptions.Icon = Yw.WinFrmUI.GlobalParas.AppIcon;
            this.generalOkAndCancelCtrl1.OkEvent += GeneralOkAndCancelCtrl1_OkEvent;
        }
 
        private List<Vmo.AssetsTranslationMainVmo> _Translations;
 
        private long _seriesId;
 
        public void SetBindingData(long seriesId)
        {
            _seriesId = seriesId;
        }
 
        public event Action ReloadDataEvent;
 
        private void btnExcelFilePath_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            if (e.Button.Tag.ToString() == "Import")
            {
                var dlg = new System.Windows.Forms.OpenFileDialog();
                dlg.Filter = "EXCEL 文件(*.xls;*.xlsx)|*.xls;*.xlsx";
                dlg.CheckFileExists = true;
                if (dlg.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                    return;
                this.btnExcelFilePath.Text = dlg.FileName;
                _Translations = new List<Vmo.AssetsTranslationMainVmo>();
                var TranslationExcelHelper = new TranslationExcelHelper();
                var result = TranslationExcelHelper.ParseTranslationExcel(dlg.FileName, out _Translations);
                if (result != null && !string.IsNullOrEmpty(result))
                {
                    TipFormHelper.ShowWarn(result);
                    return;
                }
                _Translations.ForEach(x => x.SeriesID = _seriesId);
                this.gridControl1.DataSource = _Translations;
            }
            else if (e.Button.Tag.ToString() == "Download")
            {
                var dlg = new SaveFileDialog();
                dlg.Title = "模板导出路径";
                dlg.Filter = "Excel文件|*.xls";
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    var fileName = dlg.FileName;
                    TranslationExcelHelper.ExportTranslationTemplate(fileName);
                    TipFormHelper.ShowSucceed("导出成功!");
                }
            }
        }
 
        //验证
        private bool Valid()
        {
            this.dxErrorProvider1.ClearErrors();
            if (string.IsNullOrEmpty(this.btnExcelFilePath.Text.Trim()))
            {
                this.dxErrorProvider1.SetError(this.btnExcelFilePath, "必填项");
                return false;
            }
            return true;
        }
 
        //确定
        private async void GeneralOkAndCancelCtrl1_OkEvent()
        {
            if (!Valid())
            {
                return;
            }
            if (_Translations.Count < 0 || _Translations == null)
            {
                TipFormHelper.ShowError("导入信息为空!");
                return;
            }
            var bol = await BLLFactory<HStation.BLL.AssetsTranslationMain>.Instance.Inserts(_Translations);
            if (bol)
            {
                this.ReloadDataEvent?.Invoke();
                TipFormHelper.ShowSucceed("导入成功!");
            }
            else
            {
                TipFormHelper.ShowError("导入失败!");
            }
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
    }
}