public Model.General.ReturnValueInfo Save(Model.IModel.IModelObject itemEntity, Common.DefineConstantValue.EditStateEnum EditMode) { Model.General.ReturnValueInfo returnValue = new Model.General.ReturnValueInfo(); StructureMaster_stt_Info info = new StructureMaster_stt_Info(); returnValue.messageText = ""; info = itemEntity as StructureMaster_stt_Info; try { switch (EditMode) { case Common.DefineConstantValue.EditStateEnum.OE_Insert: bool isExist = false; isExist = _structureMasterDA.IsExistRecord(info); if (!isExist) { returnValue.boolValue = _structureMasterDA.InsertRecord(info); } else { returnValue.boolValue = false; returnValue.messageText = "数据重复!"; } break; case Common.DefineConstantValue.EditStateEnum.OE_Update: returnValue.boolValue = _structureMasterDA.UpdateRecord(info); break; case Common.DefineConstantValue.EditStateEnum.OE_Delete: returnValue.boolValue = _structureMasterDA.DeleteRecord(info); break; default: break; } } catch (Exception Ex) { throw Ex; } return returnValue; }
List<StructureMaster_stt_Info> StructureGetSub(StructureMaster_stt_Info objInfo) { //return new List<StructureMaster_stt_Info>(); List<StructureMaster_stt_Info> list = new List<StructureMaster_stt_Info>(); string sqlString = string.Empty; string whereString = string.Empty; sqlString = "SELECT " + Environment.NewLine; sqlString += "*" + Environment.NewLine; sqlString += "FROM dbo.StructureMaster_stt" + Environment.NewLine; whereString = "WHERE 1=1" + Environment.NewLine; //if (objInfo.stt_cKey1 != new Guid()) //{ // whereString += "AND stt_cKey1='" + objInfo.stt_cKey1 + "' " + Environment.NewLine; //} if (objInfo.stt_cKey2 != new Guid()) { whereString += "AND stt_cKey2='" + objInfo.stt_cKey2 + "' " + Environment.NewLine; } if (objInfo.stt_cKey3 != new Guid()) { whereString += "AND stt_cKey3='" + objInfo.stt_cKey3 + "' " + Environment.NewLine; } IEnumerable<StructureMaster_stt_Info> infos = null; try { using (MainDBDataContext db = new MainDBDataContext()) { infos = db.ExecuteQuery<StructureMaster_stt_Info>(sqlString + whereString, new object[] { }); if (infos != null) { list = infos.ToList<StructureMaster_stt_Info>(); foreach (StructureMaster_stt_Info SubItem in list) { SubItem.objSubStructureList = StructureGetSub(SubItem); } } } } catch (Exception Ex) { throw Ex; } return list; }
public bool DeleteRecord(Model.IModel.IModelObject KeyObject) { bool isSuccess = false; StructureMaster_stt_Info info = new StructureMaster_stt_Info(); info = KeyObject as StructureMaster_stt_Info; try { using (MainDBDataContext db = new MainDBDataContext()) { if (info.stt_cKey3 != new Guid()) { int qty = db.RepairRequestReg_rrr.Where(d => d.rrr_cSubSubStruct == info.stt_cKey3.ToString()).Count(); if (qty > 0) { throw new Exception("此結構記錄已經有相關的維修記錄關連,不能刪除。"); } else { StructureMaster_stt delTab = db.StructureMaster_stt.SingleOrDefault(t => t.stt_iRecordID == info.stt_iRecordID); db.StructureMaster_stt.DeleteOnSubmit(delTab); isSuccess = true; } } else if (info.stt_cKey2 != new Guid()) { int qty = db.RepairRequestReg_rrr.Where(d => d.rrr_cSubStruct == info.stt_cKey2.ToString()).Count(); if (qty > 0) { throw new Exception("此結構記錄已經有相關的維修記錄關連,不能刪除。"); } else { var delTab = db.StructureMaster_stt.Where(t => t.stt_cKey1 == info.stt_cKey1 && t.stt_cKey2 == info.stt_cKey2); db.StructureMaster_stt.DeleteAllOnSubmit(delTab); isSuccess = true; } } else { int qty = db.RepairRequestReg_rrr.Where(d => d.rrr_cStruct == info.stt_cKey1.ToString()).Count(); if (qty > 0) { throw new Exception("此結構記錄已經有相關的維修記錄關連,不能刪除。"); } else { var delTab = db.StructureMaster_stt.Where(t => t.stt_cKey1 == info.stt_cKey1); db.StructureMaster_stt.DeleteAllOnSubmit(delTab); isSuccess = true; } } db.SubmitChanges(); } } catch (Exception Ex) { throw Ex; } return isSuccess; }
public bool UpdateRecord(StructureMaster_stt_Info infoObject) { bool isSuccess = false; try { using (MainDBDataContext db = new MainDBDataContext()) { StructureMaster_stt query = db.StructureMaster_stt.SingleOrDefault(t => t.stt_iRecordID == infoObject.stt_iRecordID); if (query != null) { query.stt_cDesc = infoObject.stt_cDesc; query.stt_cLast = infoObject.stt_cLast; query.stt_dLastDate = infoObject.stt_dLastDate; db.SubmitChanges(); isSuccess = true; } } } catch (Exception Ex) { throw Ex; } return isSuccess; }
public bool InsertRecord(StructureMaster_stt_Info infoObject) { bool isSuccess = false; //infoObject = GetNewKey(infoObject); try { using (MainDBDataContext db = new MainDBDataContext()) { StructureMaster_stt newTab = Common.General.CopyObjectValue<StructureMaster_stt_Info, StructureMaster_stt>(infoObject); db.StructureMaster_stt.InsertOnSubmit(newTab); db.SubmitChanges(); isSuccess = true; } } catch (Exception Ex) { throw Ex; } return isSuccess; }
public bool IsExistRecord(object KeyObject) { StructureMaster_stt_Info info = new StructureMaster_stt_Info(); info = KeyObject as StructureMaster_stt_Info; try { using (MainDBDataContext db = new MainDBDataContext()) { StructureMaster_stt query = db.StructureMaster_stt.SingleOrDefault(t => t.stt_cKey1 == info.stt_cKey1 && t.stt_cKey2 == info.stt_cKey2 && t.stt_cKey3 == info.stt_cKey3); if (query != null) { return true; } } } catch (Exception Ex) { throw Ex; } return false; }
void LoadSubSubStructure() { StructureMaster_stt_Info subItem = lbSubItem.SelectedItem as StructureMaster_stt_Info; this.lbSubSubItem.Items.Clear(); if (null != subItem) { List<StructureMaster_stt_Info> objList = subItem.objSubStructureList; if (objList != null && objList.Count > 0) { foreach (StructureMaster_stt_Info objItem in objList) { this.lbSubSubItem.Items.Add(objItem); } if (null != this.m_objSubSubItem) { StructureMaster_stt_Info selectedItem = objList.SingleOrDefault(d => d.stt_cKey1 == this.m_objSubSubItem.stt_cKey1 && d.stt_cKey2 == this.m_objSubSubItem.stt_cKey2 && d.stt_cKey3 == this.m_objSubSubItem.stt_cKey3); this.lbSubSubItem.SelectedItem = selectedItem; } } else { this.btnSubSubItemDel.Enabled = false; this.btnSubSubItemModify.Enabled = false; this.m_objSubSubItem = null; } } }
void SetDataObj(m_Type state, string strName) { this.m_objInfo = new StructureMaster_stt_Info(); this.m_objInfo.stt_cDesc = strName; switch (state) { case m_Type._One: if (this.EditState != Common.DefineConstantValue.EditStateEnum.OE_Insert) this.m_objInfo.stt_iRecordID = this.m_objItem.stt_iRecordID; this.m_objInfo.stt_cKey1 = Guid.NewGuid(); break; case m_Type._Two: if (this.EditState != Common.DefineConstantValue.EditStateEnum.OE_Insert) this.m_objInfo.stt_iRecordID = this.m_objSubItem.stt_iRecordID; this.m_objInfo.stt_cKey1 = this.m_objItem.stt_cKey1; this.m_objInfo.stt_cKey2 = Guid.NewGuid(); break; case m_Type._Three: if (this.EditState != Common.DefineConstantValue.EditStateEnum.OE_Insert) this.m_objInfo.stt_iRecordID = this.m_objSubSubItem.stt_iRecordID; this.m_objInfo.stt_cKey1 = this.m_objItem.stt_cKey1; this.m_objInfo.stt_cKey2 = this.m_objSubItem.stt_cKey2; this.m_objInfo.stt_cKey3 = Guid.NewGuid(); break; } this.m_objInfo.stt_cAdd = this.UserInformation.usm_cUserLoginID; this.m_objInfo.stt_dAddDate = DateTime.Now; this.m_objInfo.stt_cLast = this.UserInformation.usm_cUserLoginID; this.m_objInfo.stt_dLastDate = DateTime.Now; }
void lbSubSubItem_SelectedIndexChanged(object sender, EventArgs e) { if (lbSubSubItem.SelectedItem != null) { this.btnSubSubItemModify.Enabled = true; this.btnSubSubItemDel.Enabled = true; this.m_objInfo = this.m_objSubSubItem = lbSubSubItem.SelectedItem as StructureMaster_stt_Info; } else { this.btnSubSubItemModify.Enabled = false; this.btnSubSubItemDel.Enabled = false; } }
void LoadStructure() { List<StructureMaster_stt_Info> objList = this.m_objStructureList.Where(d => d.stt_cMachineType == cbxMachineType.SelectedValue.ToString()).ToList(); this.lbItem.Items.Clear(); if (objList != null && objList.Count > 0) { foreach (StructureMaster_stt_Info objItem in objList) { this.lbItem.Items.Add(objItem); } if (null != this.m_objInfo) { StructureMaster_stt_Info selectedItem = objList.SingleOrDefault(d => d.stt_cKey1 == this.m_objInfo.stt_cKey1); this.lbItem.SelectedItem = selectedItem; } } else { this.m_objItem = null; this.btnItemDel.Enabled = false; this.btnItemModify.Enabled = false; this.btnSubItemAdd.Enabled = false; } }
void btnSubSubItemDel_Click(object sender, EventArgs e) { if (this.m_objSubSubItem == null) { return; } DialogResult result = MessageBox.Show("將刪除所有子子結構?是否繼續", "確定", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { this.EditState = Common.DefineConstantValue.EditStateEnum.OE_Delete; this.m_objInfo = this.m_objSubSubItem; //刪除所有子節點 Save(); lbSubSubItem.Items.Clear(); LoadStructure(); LoadSubStructure(); LoadSubSubStructure(); } }
void btnSubSubItemAdd_Click(object sender, EventArgs e) { if (this.m_objSubItem == null) { return; } AddStructure addSubSub = new AddStructure("添加子子結構", null); DialogResult result = addSubSub.ShowDialog(); if (result == DialogResult.Yes) { string name = addSubSub.m_StructreName; this.EditState = Common.DefineConstantValue.EditStateEnum.OE_Insert; SetDataObj(m_Type._Three, name); Save(); this.m_objSubSubItem = this.m_objInfo; LoadStructure(); LoadSubStructure(); LoadSubSubStructure(); this.m_objInfo = null; } }
void btnItemAdd_Click(object sender, EventArgs e) { this.m_objItem = null; AddStructure add = new AddStructure("添加結構", null); DialogResult result = add.ShowDialog(); if (result == DialogResult.Yes) { string name = add.m_StructreName; this.EditState = Common.DefineConstantValue.EditStateEnum.OE_Insert; SetDataObj(m_Type._One, name); Save(); this.m_objItem = this.m_objInfo; LoadStructure(); this.m_objInfo = null; } }
/// <summary> /// 結構主檔 /// </summary> /// <returns></returns> public List<StructureMaster_stt_Info> GetStructureMaster() { try { List<StructureMaster_stt_Info> list = new List<StructureMaster_stt_Info>(); StringBuilder strSql = new StringBuilder(); strSql.AppendLine("select"); strSql.AppendLine("stt_iRecordID,stt_cKey1,stt_cKey2,stt_cKey3,stt_cMachineType,stt_cDesc,stt_cAdd,stt_dAddDate,stt_cLast,stt_dLastDate "); strSql.AppendLine("from StructureMaster_stt "); using (SqlDataReader sdr = DbHelperSQL.ExecuteReader(strSql.ToString())) { while (sdr.Read()) { StructureMaster_stt_Info model = new StructureMaster_stt_Info(); if (sdr["stt_iRecordID"] != null && sdr["stt_iRecordID"].ToString() != "") { model.stt_iRecordID = int.Parse(sdr["stt_iRecordID"].ToString()); } if (sdr["stt_cKey1"] != null && sdr["stt_cKey1"].ToString() != "") { model.stt_cKey1 = new Guid(sdr["stt_cKey1"].ToString()); } if (sdr["stt_cKey2"] != null && sdr["stt_cKey2"].ToString() != "") { model.stt_cKey2 = new Guid(sdr["stt_cKey2"].ToString()); } if (sdr["stt_cKey3"] != null && sdr["stt_cKey3"].ToString() != "") { model.stt_cKey3 = new Guid(sdr["stt_cKey3"].ToString()); } if (sdr["stt_cMachineType"] != null && sdr["stt_cMachineType"].ToString() != "") { model.stt_cMachineType = sdr["stt_cMachineType"].ToString(); } if (sdr["stt_cDesc"] != null && sdr["stt_cDesc"].ToString() != "") { model.stt_cDesc = sdr["stt_cDesc"].ToString(); } if (sdr["stt_cAdd"] != null && sdr["stt_cAdd"].ToString() != "") { model.stt_cAdd = sdr["stt_cAdd"].ToString(); } if (sdr["stt_dAddDate"] != null && sdr["stt_dAddDate"].ToString() != "") { model.stt_dAddDate = DateTime.Parse(sdr["stt_dAddDate"].ToString()); } if (sdr["stt_cLast"] != null && sdr["stt_cLast"].ToString() != "") { model.stt_cLast = sdr["stt_cLast"].ToString(); } if (sdr["stt_dLastDate"] != null && sdr["stt_dLastDate"].ToString() != "") { model.stt_dLastDate = DateTime.Parse(sdr["stt_dLastDate"].ToString()); } list.Add(model); } } return list; } catch (Exception ex) { throw ex; } }
private string GetStructureMasterSQL(StructureMaster_stt_Info model) { StringBuilder strSql = new StringBuilder(); StringBuilder strSql1 = new StringBuilder(); StringBuilder strSql2 = new StringBuilder(); if (model.stt_iRecordID != null) { strSql1.Append("stt_iRecordID,"); strSql2.Append("" + model.stt_iRecordID + ","); } if (model.stt_cKey1 != null) { strSql1.Append("stt_cKey1,"); strSql2.Append("'" + model.stt_cKey1 + "',"); } if (model.stt_cKey2 != null) { strSql1.Append("stt_cKey2,"); strSql2.Append("'" + model.stt_cKey2 + "',"); } if (model.stt_cKey3 != null) { strSql1.Append("stt_cKey3,"); strSql2.Append("'" + model.stt_cKey3 + "',"); } if (model.stt_cMachineType != null) { strSql1.Append("stt_cMachineType,"); strSql2.Append("'" + model.stt_cMachineType + "',"); } if (model.stt_cDesc != null) { strSql1.Append("stt_cDesc,"); strSql2.Append("'" + model.stt_cDesc + "',"); } if (model.stt_cAdd != null) { strSql1.Append("stt_cAdd,"); strSql2.Append("'" + model.stt_cAdd + "',"); } if (model.stt_dAddDate != null) { strSql1.Append("stt_dAddDate,"); strSql2.Append("'" + model.stt_dAddDate.ToString(this._sqlLiteDatetimeFormat) + "',"); } if (model.stt_cLast != null) { strSql1.Append("stt_cLast,"); strSql2.Append("'" + model.stt_cLast + "',"); } if (model.stt_dLastDate != null) { strSql1.Append("stt_dLastDate,"); strSql2.Append("'" + model.stt_dLastDate.ToString(this._sqlLiteDatetimeFormat) + "',"); } strSql.Append("insert into StructureMaster_stt("); strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1)); strSql.Append(")"); strSql.Append(" values ("); strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1)); strSql.Append(")"); return strSql.ToString(); }