using System; using System.Collections.Generic; using System.Text; using System.Data; namespace DAL { public class ClsGy_WorkShift_Ctl : DBUtility.ClsGy_Base_Ctl { SQLHelper.ClsCN oCn = new SQLHelper.ClsCN(); //原代码 用于 替换子项目 public Model.ClsGy_WorkShiftMain omodel = new Model.ClsGy_WorkShiftMain(); public List DetailColl = new List(); //删除子表 public void DeleteBillSub(Int64 lngBillKey) { oCn.RunProc("Delete From Gy_WorkShiftSub where HInterID=" + lngBillKey.ToString()); } //删除主表 public void DeleteBillMain(Int64 lngBillKey) { oCn.RunProc("Delete From Gy_WorkShift where HInterID=" + lngBillKey.ToString()); } //删除单据 public bool DeleteBill(Int64 lngBillKey, ref string sReturn) { try { oCn.BeginTran(); //删除关联 DeleteRelation(ref sReturn, lngBillKey); //删除明细表 DeleteBillSub(lngBillKey); //删除主表 DeleteBillMain(lngBillKey); sReturn = "删除单据成功!"; oCn.Commit(); return true; } catch (Exception e) { sReturn = e.Message; oCn.RollBack(); return false; } } //是否被关联 public bool isUse(Int64 lngBillKey, ref string sReturn) { try { //查询主表 DataSet Ds ; Ds = oCn.RunProcReturn("Select HinterID from Gy_WorkShiftSub Where HInterID=" + lngBillKey.ToString() + " and isnull(HRelationQty,0)<>0 ", "Gy_WorkShift"); if (Ds.Tables[0].Rows.Count != 0) { sReturn = "单据已被关联,不能操作!"; return true; } sReturn = ""; return false; } catch (Exception e) { sReturn = e.Message; return false; } } //读取下张单据 //修改单据 public bool ModifyBill(Int64 lngBillKey, ref string sReturn) { try { // oCn.BeginTran(); //更新主表 oCn.RunProc("UpDate Gy_WorkShift set " + "HNumber='" + omodel.HNumber + "'" + ",HName='" + omodel.HName + "'" + ",HNote='" + omodel.HNote + "'" + ",HDeptID=" + omodel.HDeptID.ToString() + ",HWorkTimes=" + omodel.HWorkTimes.ToString() + ",HStopflag='" + DBUtility.ClsPub.BoolToString(omodel.HStopflag) + "'" + ",HRemark='" + omodel.HRemark + "'" + " where HInterID=" + lngBillKey.ToString()); //删除关联 DeleteRelation(ref sReturn, lngBillKey); //删除子表 DeleteBillSub(lngBillKey); //插入子表 foreach(Model.ClsGy_WorkShiftSub oSub in DetailColl) { oCn.RunProc("Insert into Gy_WorkShiftSub " + " (HInterID,HEntryID,HSno" + ",HStartDate,HEndDate,HOverDay" + " )values(" + omodel.HInterID.ToString() + "," + oSub.HEntryID.ToString() + "," + oSub.HSno.ToString() + ",'" + oSub.HStartDate.ToShortTimeString() + "','" + oSub.HEndDate.ToShortTimeString() + "'," + Convert.ToString(oSub.HOverDay ? 1 : 0) + ") "); } sReturn = "修改单据成功!"; oCn.Commit(); return true; } catch (Exception e) { sReturn = e.Message; oCn.RollBack(); return false; } } //新增单据 public bool AddBill( ref string sReturn) { try { //得到mainid omodel.HInterID = DBUtility.ClsPub.CreateBillID(MvarItemKey, ref DBUtility.ClsPub.sExeReturnInfo); //若MAINDI重复则重新获取 oCn.BeginTran(); //主表 oCn.RunProc("Insert Into Gy_WorkShift " + "(HInterID,HNumber,HName,HNote" + ",HDeptID,HWorkTimes,HStopflag,HRemark" + ") " + " values(" + omodel.HInterID.ToString() + ",'" + omodel.HNumber + "','" + omodel.HName + "','" + omodel.HNote + "'" + "," + omodel.HDeptID.ToString() + "," + omodel.HWorkTimes.ToString() + "," + Convert.ToString(omodel.HStopflag ? 1 : 0) + ",'" + omodel.HRemark + "'" + ") "); //插入子表 foreach (Model.ClsGy_WorkShiftSub oSub in DetailColl) { oCn.RunProc("Insert into Gy_WorkShiftSub " + " (HInterID,HEntryID,HSno" + ",HStartDate,HEndDate,HOverDay" + " )values(" + omodel.HInterID.ToString() + "," + oSub.HEntryID.ToString() + "," + oSub.HSno.ToString() + ",'" + oSub.HStartDate.ToShortTimeString() + "','" + oSub.HEndDate.ToShortTimeString() + "'," + Convert.ToString(oSub.HOverDay ? 1 : 0) + ") "); } sReturn = "新增单据成功!"; oCn.Commit(); return true; } catch (Exception e) { sReturn = e.Message; oCn.RollBack(); return false; } } //显示单据 public bool ShowBill(Int64 lngBillKey, ref string sReturn) { try { //查询主表 DataSet Ds ; Ds = oCn.RunProcReturn("Select * from Gy_WorkShift Where HInterID=" + lngBillKey.ToString(), "Gy_WorkShift"); if(Ds.Tables[0].Rows.Count==0) { sReturn = "单据未找到!"; return false; } //赋值 omodel.HInterID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HInterID"].ToString()); omodel.HNumber = Ds.Tables[0].Rows[0]["HNumber"].ToString().Trim(); omodel.HName = Ds.Tables[0].Rows[0]["HName"].ToString().Trim(); omodel.HNote = Ds.Tables[0].Rows[0]["HNote"].ToString().Trim(); omodel.HDeptID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HDeptID"].ToString()); omodel.HWorkTimes = DBUtility.ClsPub.isDoule(Ds.Tables[0].Rows[0]["HWorkTimes"]); omodel.HStopflag = DBUtility.ClsPub.isBool(Ds.Tables[0].Rows[0]["HStopflag"]); omodel.HRemark = Ds.Tables[0].Rows[0]["HRemark"].ToString().Trim(); // //循环 DataSet DsSub ; DsSub = oCn.RunProcReturn("Select * from Gy_WorkShiftSub Where HInterID=" + lngBillKey.ToString(), "Gy_WorkShiftSub"); DetailColl.Clear();//清空 for (int i = 0; i < DsSub.Tables[0].Rows.Count; i++) { Model.ClsGy_WorkShiftSub oSub = new Model.ClsGy_WorkShiftSub(); oSub.HInterID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HInterID"].ToString()); oSub.HEntryID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HEntryID"].ToString()); oSub.HSno = DBUtility.ClsPub.isInt(DsSub.Tables[0].Rows[i]["HSno"].ToString()); oSub.HStartDate = DBUtility.ClsPub.isDate(DsSub.Tables[0].Rows[i]["HStartDate"].ToString()); oSub.HEndDate = DBUtility.ClsPub.isDate(DsSub.Tables[0].Rows[i]["HEndDate"].ToString()); oSub.HOverDay = DBUtility.ClsPub.isBool(DsSub.Tables[0].Rows[i]["HOverDay"].ToString()); DetailColl.Add(oSub); } sReturn = "显示单据成功!"; return true; } catch (Exception e) { sReturn = e.Message; return false; } } //MAINID是否重复 public bool IsExistMainID(ref string sReturn, Int64 lngBillKey) { sReturn = ""; return false; } //删除关联 public void DeleteRelation(ref string sReturn, Int64 lngBillKey) { sReturn = ""; return; } //构造函数 public ClsGy_WorkShift_Ctl() { MvarItemKey = "3701"; MvarReportTitle = "班次表"; } } }