/// <summary> /// 创建楼层房间 /// </summary> private void TaskProcess(object state) { int iSuccNum = 0; int iFaultNum = 0; SetButtonEnabled(false); try { Model.BuidingBatchCondition objCondition = (Model.BuidingBatchCondition)state; if (objCondition != null) { if (!(objCondition.UnitID <= 0 || objCondition.BeginCode >= objCondition.EndCode)) { string strBegin = FormatRoomCode(objCondition.BeginCode); string strEnd = FormatRoomCode(objCondition.EndCode); int iBeginFLoor = Convert.ToInt32(strBegin.Substring(0, 2)); int iEndFLoor = Convert.ToInt32(strEnd.Substring(0, 2)); int iBeginRoom = Convert.ToInt32(strBegin.Substring(2, 2)); int iEndRoom = Convert.ToInt32(strEnd.Substring(2, 2)); IList <Model.Building> listRoom = new List <Model.Building>(); if (iBeginFLoor < iEndFLoor) { for (int f = iBeginFLoor; f <= iEndFLoor; f++) { for (int r = iBeginRoom; r <= iEndRoom; r++) { Model.Building objModel = new Model.Building() { Flag = 3, FID = objCondition.UnitID, ID = 0, BName = BQ2(f) + BQ2(r), Code = f * 100 + r, Contact = "", Tel = "", BuildingSerialNo = "" }; listRoom.Add(objModel); } } } else { for (int r = iBeginRoom; r <= iEndRoom; r++) { Model.Building objModel = new Model.Building() { Flag = 3, FID = objCondition.UnitID, ID = 0, Code = iBeginFLoor * 100 + r }; objModel.BName = FormatRoomCode(objModel.Code); objModel.Contact = ""; objModel.Tel = ""; objModel.BuildingSerialNo = ""; listRoom.Add(objModel); } } string strErrorInfo = ""; if (!(listRoom == null || listRoom.Count == 0)) { IDAL.IBuilding objDAL = DALFactory.DALFactory.Building(); foreach (Model.Building objModel in listRoom) { if (this._FormIfClose) { return; } int iNewID = objDAL.Add(objModel, out strErrorInfo); if (iNewID <= 0) { iFaultNum++; ShowNotice(string.Format("创建楼层房间{0}数据失败,(原因:{1})!", objModel.BName, strErrorInfo)); } else { iSuccNum++; ShowNotice(string.Format("创建楼层房间{0}数据成功!", objModel.BName)); } } } ShowNotice(string.Format("\r\n生成报告:成功数{0},失败数{1},总计:{2}!\r\n\r\n", iSuccNum, iFaultNum, (iSuccNum + iFaultNum))); } } } catch (Exception err) { ShowNotice(string.Format("创建房间数据失败,(原因:{0})!", err.Message)); } SetButtonEnabled(true); if (iSuccNum > 0) { Manager.GetInstance().BuildingDataChangeNotice(); } CMessageBox.ShowSucc("生成结束!", Config.DialogTitle); }
protected override void BtnOK_Click(object sender, EventArgs e) { int iNewAreaID = 0; int iNewBuildID = 0; int iNewUnitID = 0; int iCode = 0; int iFatherID = 0; string strBName = txtName.Text.Trim(); string strCode = txtCode.Text.Trim(); string strContact = txtContact.Text.Trim(); string strTel = txtTel.Text.Trim(); string strSerialNo = txtSerialNo.Text.Trim(); int iSelectID = 0; if (cbArea.Visible) { iSelectID = Convert.ToInt32(((Model.ComboBoxItem)cbArea.SelectedItem).Value); if (iSelectID <= 0) { CMessageBox.ShowError("请选择一个小区!", Config.DialogTitle); return; } if (this._DataType.Equals(1)) { iFatherID = iSelectID; } iNewAreaID = iSelectID; } if (cbBuild.Visible) { iSelectID = Convert.ToInt32(((Model.ComboBoxItem)cbBuild.SelectedItem).Value); if (iSelectID <= 0) { CMessageBox.ShowError("请选择一个楼栋!", Config.DialogTitle); return; } if (this._DataType.Equals(2)) { iFatherID = iSelectID; } iNewBuildID = iSelectID; } if (cbUnit.Visible) { iSelectID = Convert.ToInt32(((Model.ComboBoxItem)cbUnit.SelectedItem).Value); if (iSelectID <= 0) { CMessageBox.ShowError("请选择一个单元!", Config.DialogTitle); return; } if (this._DataType.Equals(3)) { iFatherID = iSelectID; } iNewUnitID = iSelectID; } if (strBName.Equals("")) { txtName.Focus(); CMessageBox.ShowError(string.Format("请输入{0}名称!", this._DataTypeName), Config.DialogTitle); return; } if (strCode.Equals("") || !Functions.IsInt(strCode)) { txtCode.Focus(); CMessageBox.ShowError(string.Format("{0}编码不能为空,且范围必须是{1}之间的整数!", this._DataTypeName, (this._DataType.Equals(3) ? "0~9999" : "0~99")), Config.DialogTitle); return; } iCode = Functions.FormatInt(strCode); if (cbUnit.Visible) { //是房间 if (!(iCode >= 0 && iCode <= 9999)) { txtCode.Focus(); CMessageBox.ShowError(string.Format("输入的{0}编码超出范围,取值范围是0~9999之间的整数!", this._DataTypeName), Config.DialogTitle); return; } } else { if (!(iCode >= 0 && iCode <= 99)) { txtCode.Focus(); CMessageBox.ShowError(string.Format("输入的{0}编码超出范围,取值范围是0~99之间的整数!", this._DataTypeName), Config.DialogTitle); return; } } if (this._DataType.Equals(0) && !CheckSerialNo(strSerialNo)) { txtSerialNo.Focus(); CMessageBox.ShowError(string.Format("序列号必须填写,且必须是16字节的16进制字符!"), Config.DialogTitle); return; } if (MessageBox.Show("确定要保存吗?", Config.DialogTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } Model.Building objModel = new Model.Building() { Flag = _DataType, FID = iFatherID, ID = this._CurrentID, BName = strBName, Code = iCode, Contact = strContact, Tel = strTel, BuildingSerialNo = strSerialNo }; string strErrorInfo = ""; IDAL.IBuilding objDAL = DALFactory.DALFactory.Building(); if (this._CurrentAction.Equals(EAction.Create)) { int iNewID = objDAL.Add(objModel, out strErrorInfo); if (iNewID <= 0) { CMessageBox.ShowError(string.Format("创建{0}数据失败,错误如下:\r\n{1}!", this._DataTypeName, strErrorInfo), Config.DialogTitle); return; } } else { bool bIfSucc = objDAL.Update(objModel, out strErrorInfo); if (!bIfSucc) { CMessageBox.ShowError(string.Format("修改{0}数据失败,错误如下:\r\n{1}!", this._DataTypeName, strErrorInfo), Config.DialogTitle); return; } } //是否通知建筑数据已经改变 bool bIfNotice = false; if (this._CurrentAction == EAction.Create) { //新增必通知 bIfNotice = true; } else { if (string.Compare(this._OldName, strBName) != 0 || !this._OldCode.Equals(iCode) || !this._OldAreaID.Equals(iNewAreaID) || !this._OldBuildID.Equals(iNewBuildID) || !this._OldUnitID.Equals(iNewUnitID)) { //条件满足通知 bIfNotice = true; } } if (bIfNotice) { Manager.GetInstance().BuildingDataChangeNotice(); } this.DialogResult = DialogResult.OK; }