jt
2021-06-10 5d0d028456874576560552f5a5c4e8b801786f11
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using System.IO;
using HH.WMS.Client.Common;
using Newtonsoft.Json;
 
namespace HH.WMS.Client.frm
{
    public partial class frmAddTemplet : DevComponents.DotNetBar.Metro.MetroForm
    {
        public frmAddTemplet()
        {
            InitializeComponent();
        }
 
        public delegate void DesignDelegate(string path);
        public event DesignDelegate DesignEvent;
 
        private void btnCreate_Click(object sender, EventArgs e)
        {
            string type = this.cmbType.Text;
            if (string.IsNullOrEmpty(type))
            {
                MessageBox.Show("ÇëÑ¡ÔñÄ£°åÀàÐÍ", "ºÏ·ÊºººÍ");
                return;
            }
            string name = this.txtName.Text;
            if (string.IsNullOrEmpty(name))
            {
                MessageBox.Show("ÇëÊäÈëÄ£°æÃû³Æ", "ºÏ·ÊºººÍ");
                return;
            }
            //»ñÈ¡¿½±´±¨±íÃû³Æ
            OperateResult or = CreateTemplate(this.cmbType.Text);
            if (or.Status == ResultStatus.Success)
            {
                string path = @"ActionReport/Template/" + name + ".rdlx";
                EndUserDesigner designer = new EndUserDesigner();//µ÷Óñ༭ģ°æ
                DesignEvent += designer.OnDesign;//×¢²áʼþ
                DesignEvent(path);
 
                string sr = WebApiManager.HttpWMS_Get("/api/PrintTemplet/CreateTemplet?mac=" + StaticUtil.Mac + "&ip="+StaticUtil.Ip+"&stockCode=" + StaticUtil.StockCode + "&type=" + type + "&name=" + name + ".rdlx");
                or = JsonConvert.DeserializeObject<OperateResult>(sr);
 
 
                if (or.Status == ResultStatus.Success)
                {
                    this.Close();
 
                    designer.ShowDialog();
                    this.DialogResult = System.Windows.Forms.DialogResult.OK;
                }
                else
                {
                    MessageBoxEx.Show(or.Msg);
                }
            }
            else
            {
                MessageBox.Show(or.Msg);
            }
        }
 
        #region ¿½±´¸´ÖÆ
        /// <summary>
        /// ¿½±´oldlabµÄÎļþµ½newlabÏÂÃæ
        /// </summary>
        /// <param name="sourcePath">labÎļþËùÔÚĿ¼(@"~\labs\oldlab")</param>
        /// <param name="savePath">±£´æµÄÄ¿±êĿ¼(@"~\labs\newlab")</param>
        /// <param name="ArName">±¨±íÃû³Æ</param>
        /// <returns>·µ»Ø:true-¿½±´³É¹¦;false:¿½±´Ê§°Ü</returns>
        public OperateResult CreateTemplate(string type)
        {
            string fileName = txtName.Text.Trim();
            string rootTemplatePath = Application.StartupPath + @"\ActionReport\RootTemplate\" + type + "¸ùÄ£°å.rdlx";
            if (!File.Exists(rootTemplatePath))
            {
                return OperateResult.Error("ÕÒ²»µ½¸ùÄ£°å£¡");
            }
 
            string templatePath = Application.StartupPath + @"\ActionReport\Template\";
            if (!Directory.Exists(templatePath))
            {
                Directory.CreateDirectory(templatePath);
            }
 
            try
            {
 
                string[] labFiles = Directory.GetFiles(templatePath);//Îļþ
                foreach (string m in labFiles)
                {
                    if (m.Equals(fileName))
                    {
                        return OperateResult.Error("ÒÑ´æÔÚ¸ÃÄ£°å£¡");
                    }
                }
                File.Copy(rootTemplatePath, templatePath + "\\" + fileName + ".rdlx", false);
            }
            catch (Exception ex)
            {
                return OperateResult.Error(ex.Message);
            }
            return OperateResult.Succeed();
        }
        #endregion
 
        private void cmbType_SelectedIndexChanged(object sender, EventArgs e)
        {
 
        }
    }
}