duhe
2023-06-13 bff338f3b532b0bf2a8f3f2d6b662adb9a222f13
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
 
namespace CostM
{
    public partial class CB_WorkTimePeriodAdd : Form
    {
        public CB_WorkTimePeriodAdd()
        {
            InitializeComponent();
        }
 
        public int HYear;
        public int HPeriod;
        long HMaterID;
        string HMaterNumber;
        long HDeptID;
        string HMESDeptName;
        double HRelWorkTimes;
        private void cmdHMaterID_Click(object sender, EventArgs e)
        {
 
            DAL.ClsK3_Material_View oMater = new DAL.ClsK3_Material_View();
            if (oMater.RefreshView())
            {
                txtHMaterID.Tag = oMater.omodel.HItemID;
                txtHMaterID.Text = oMater.omodel.HNumber;
                txtHMaterName.Text = oMater.omodel.HName;
            }
            else
            {
                txtHMaterID.Tag = 0;
                txtHMaterID.Text = "";
                txtHMaterName.Text = "";
            }
        }
 
        private void txtHMaterID_TextChanged(object sender, EventArgs e)
        {
            if (txtHMaterID.Text.Trim() == "")
                txtHMaterID.Tag = "0";
        }
 
        private void cmdHCostItemID_Click(object sender, EventArgs e)
        {
            DAL.ClsK3_Department_View oDept = new DAL.ClsK3_Department_View();
            if (oDept.RefreshView())
            {
                txtHDeptID.Text = oDept.oModel.HName;
                txtHDeptID.Tag = oDept.oModel.HItemID;
            }
            else
            {
                txtHDeptID.Text = "";
                txtHDeptID.Tag = 0;
            }
        }
 
        private void txtHCostItemID_TextChanged(object sender, EventArgs e)
        {
            if (txtHDeptID.Text.Trim() == "")
                txtHDeptID.Tag = "0";
        }
 
        private void CB_WorkTimePeriodAdd_Load(object sender, EventArgs e)
        {
 
            //获取本期成本会计期间
            if (DBUtility.ClsPub.Sub_CBGetCurPeriod() == false)
            {
                MessageBox.Show("获取成本会计期间失败!");
                return;
            }
            cmbHYear.Items.Add(DBUtility.ClsPub.CBCurYear);
            cmbHYear.Items.Add(DBUtility.ClsPub.CBCurYear - 1);
            cmbHYear.Items.Add(DBUtility.ClsPub.CBCurYear - 2);
            cmbHYear.Items.Add(DBUtility.ClsPub.CBCurYear - 3);
            //cmbHYear.SelectedIndex = 0;
            //cmdHPeriod.Text = DBUtility.ClsPub.CBCurPeriod.ToString();
            cmbHYear.Text = DBUtility.ClsPub.isStrNull(HYear);
            cmbHPeriod.Text = DBUtility.ClsPub.isStrNull(HPeriod);
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            //获取本期成本会计期间
            if (DBUtility.ClsPub.Sub_CBGetCurPeriod() == false)
            {
                MessageBox.Show("获取成本会计期间失败!");
                return;
            }
            //判断是否本期间
            if (Pub_Class.ClsPub.isInt(cmbHYear.Text) != DBUtility.ClsPub.CBCurYear || Pub_Class.ClsPub.isInt(cmbHPeriod.Text) != DBUtility.ClsPub.CBCurPeriod)
            {
                MessageBox.Show("只能保存本期数据!");
                return;
            }
            //
            SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
            DataSet Ds;
            HYear = DBUtility.ClsPub.isInt( cmbHYear.Text);
            HPeriod = DBUtility.ClsPub.isInt(cmbHPeriod.Text);
            HMaterID = DBUtility.ClsPub.isLong(txtHMaterID.Tag);
            HMaterNumber = DBUtility.ClsPub.isStrNull(txtHMaterID.Text);
            HDeptID = DBUtility.ClsPub.isLong(txtHDeptID.Tag);
            HMESDeptName = DBUtility.ClsPub.isStrNull(txtHMESDeptName.Text);
            HRelWorkTimes = DBUtility.ClsPub.isDoule(txtHRelWorkTimes.Text);
            Ds = oCn.RunProcReturn("select * from CB_WorkTimePeriod where HYear=" + HYear + " and HPeriod=" + HPeriod + " and HMaterID=" + HMaterID + " and HDeptID=" + HDeptID + " and HMESDeptName='" + HMESDeptName + "'", "CB_WorkTimePeriod");
            if (Ds.Tables[0].Rows.Count > 0)
            {
                if (MessageBox.Show("本期此产品在该部门已存在工时,是否覆盖?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                {
                    oCn.RunProc("delete CB_WorkTimePeriod where HYear=" + HYear + " and HPeriod=" + HPeriod + " and HMaterID=" + HMaterID + " and HDeptID=" + HDeptID + " and HMESDeptName='"+HMESDeptName+"'");
                }
                else
                {
                    return; 
                }
            }
 
            oCn.RunProc("insert into  CB_WorkTimePeriod (HYear,HPeriod" +
                                                        ",HDeptID,HMaterID,HMaterNumber,HMESDeptName,HRelWorkTimes" +
                                                        ")" +
                                                        "values('" + HYear + "','" + HPeriod + "'" +
                                                        "," + HDeptID + "," + HMaterID + ",'" + HMaterNumber + "','" + HMESDeptName + "'," + HRelWorkTimes + ")");
            MessageBox.Show("保存完毕!"); 
        } 
    }
}