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("保存完毕!"); } } }