1
wtt
3 天以前 b371b604a464e7249634bbdb45cda85dd5bd1f3a
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
 
namespace BLL
{
    public partial class Xt_SystemParameterForOrg : Form
    {
        public Xt_SystemParameterForOrg()
        {
            InitializeComponent();
        }
 
        public const int HInterIDCol = 0;
        public const int HKeyCol = 1;
        public const int HOrgIDCol = 2;
        public const int HOrgNumberCol = 3;
        public const int HOrgNameCol = 4;
        public const int HValueCol = 5;
        public string sHKey;
 
        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            initGrid();
            Display();
        }
 
        private void initGrid()
        {
            //
            grdMain.ColumnCount = 6;                       //总列数
            DBUtility.Xt_BaseBillFun.initGridFst(grdMain, this.Name);
            //=
            grdMain.Columns[HOrgNumberCol].HeaderText = "组织代码";
            grdMain.Columns[HOrgNameCol].HeaderText = "组织名称";
            grdMain.Columns[HValueCol].HeaderText = "参数值";
            ////固定赋值=====================================================
            //=============================================================================
            //格式化 
 
            //设置 手工隐藏
            DBUtility.ClsPub.HideGridView(grdMain, Name, DBUtility.ClsPub.AppPath);//设置隐藏列
            ////隐藏列
            grdMain.Columns[HInterIDCol].Visible = false;
            grdMain.Columns[HKeyCol].Visible = false;
            grdMain.Columns[HOrgIDCol].Visible = false; 
            //隐藏源单信息 
            //设置可编辑列
            string sAllowCol = HValueCol.ToString() ;
            //设置合计列
            string sTotalCol = "";
            //格式化网格
            //DBUtility.Xt_BaseBillFun.initGridLast(sAllowCol, sTotalCol, oSumGrid);
            DBUtility.Xt_BaseBillFun.GetGrid(grdMain, this.Name);
        }
 
        private void Display()
        {
            SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
            try
            {
                //根据 HKEY 来获取 现有信息
                DataSet ds = oCn.RunProcReturn("exec h_p_Xt_SystemParameter_GetValue '" + sHKey + "'", "h_p_Xt_SystemParameter_GetValue");
                if(ds==null)
                {
                    MessageBox.Show("读取失败1!没有返回任何数据!");
                    return;
                }
                if (ds.Tables[0].Rows.Count != 0)
                {
                    //显示到 表头 
                    txtHKey.Text = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HKey"]);
                    txtHCaption.Text = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HCaption"]);
                    txtHValue.Text = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HMainValue"]);
                    txtHExplanation.Text = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HExplanation"]);
                    txtHFarmat.Text = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HFarmat"]);
                }
                else
                {
                    MessageBox.Show("读取失败2!没有返回任何数据!");
                    return;
                }
                //显示到 表体  
                grdMain.RowCount = ds.Tables[0].Rows.Count;
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    if (i >= grdMain.RowCount - 1)
                        grdMain.Rows.Add();
                    //单据固定赋值
                    grdMain.Rows[i].Cells[HInterIDCol].Value = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[i]["HInterID"]);
                    grdMain.Rows[i].Cells[HKeyCol].Value = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i]["HKey"]);
                    grdMain.Rows[i].Cells[HOrgIDCol].Value = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[i]["HOrgID"]);
                    grdMain.Rows[i].Cells[HOrgNumberCol].Value = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i]["HOrgNumber"]);
                    grdMain.Rows[i].Cells[HOrgNameCol].Value = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i]["HOrgName"]);
                    grdMain.Rows[i].Cells[HValueCol].Value = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i]["HValue"]);
                }
            }
            catch(Exception e1)
            {
                MessageBox.Show("读取失败!" + e1.Message);
 
            }
 
        }
 
        private void cmdCancel_Click(object sender, EventArgs e)
        {
            DBUtility.Xt_BaseBillFun.SaveGrid(grdMain, this.Name);
            this.Close();
        }
 
        private void cmdOK_Click(object sender, EventArgs e)
        {
            //保存前判断
            SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
 
            try
            {
                //清除 子表信息
                oCn.RunProc(" delete from Xt_SystemParameterSub Where HKey= '" + sHKey + "'");
                //循环写入子表
                for (int i = 0; i < grdMain.Rows.Count; i++)
                {
                    if (DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[HValueCol].Value).ToString() !="" &&
                         DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[HKeyCol].Value).ToString() !="")
                    {
                        oCn.RunProc(" insert into  Xt_SystemParameterSub (HInterID,HValue,HKey,HOrgID) " +
                            " values(  " +
                            "  " + DBUtility.ClsPub.isLong(grdMain.Rows[i].Cells[HInterIDCol].Value).ToString() + " " +
                            ",  '" + DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[HValueCol].Value).ToString() + "' " +
                            ",  '" + DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[HKeyCol].Value).ToString() + "' " +
                            ",  " + DBUtility.ClsPub.isLong(grdMain.Rows[i].Cells[HOrgIDCol].Value).ToString() + " " +
                            ") ");
                    }
                }
                MessageBox.Show("保存完毕!");
            }
            catch(Exception e1)
            {
                MessageBox.Show("保存失败!"+ e1.Message);
 
            }
        }
 
        private void grdMain_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
        {
            int i = grdMain.CurrentCell.ColumnIndex;
            if (i == HKeyCol || i == HOrgNumberCol || i == HOrgNameCol)
            {
                e.Cancel = true;
            }
        }
    }
}