public bool DeleteGroup(SignalStatusGroup_ssg_Info group)
        {
            if (group == null || group.ssg_cGroupID == null || group.ssg_cGroupID == Guid.Empty) return false;
            SqlConnection cn = null;
            SqlCommand cmd = null;
            SqlTransaction trans = null;
            try
            {
                cn = new SqlConnection(SQLHelper.ConnectionString);
                if (cn.State == ConnectionState.Closed) cn.Open();
                trans = cn.BeginTransaction();

                //更新机台信号组设置,将原先设置为本组的改为使用默认组(Id=Null)
                string strSQL = "UPDATE dbo.MachineSignalStatusGroup_msg SET msg_cGroupID=null where msg_cGroupID=@GroupId;";
                //删除本组下属信号状态信息
                strSQL += "DELETE a FROM SignalLightsStatus_sls a LEFT JOIN SignalStatusGroupItem_sgi b ON b.sgi_cRecordID = a.sls_cRecordID WHERE b.sgi_cGroupID=@GroupId;";
                //strSQL += "delete from SignalLightsStatus_sls where sls_cRecordID in (select sgi_cRecordID from SignalStatusGroupItem_sgi where sgi_cGroupID=@GroupId);";
                //删除本组下属信号状态关联
                strSQL += "DELETE FROM dbo.SignalStatusGroupItem_sgi WHERE sgi_cGroupID=@GroupId;";
                //删除组信息
                strSQL += "DELETE FROM dbo.SignalStatusGroup_ssg WHERE ssg_cGroupID=@GroupId;";
                List<SqlParameter> sqlparams = new List<SqlParameter>();
                sqlparams.Add(SQLHelper.MakeInParam("@GroupId", SqlDbType.UniqueIdentifier, 0, group.ssg_cGroupID));
                int rowsAffected = SQLHelper.ExecuteNonQuery(strSQL, sqlparams.ToArray());
                trans.Commit();
                return rowsAffected > 0;//当插入的行数小于等于0时,插入失败
            }
            catch (Exception e)
            {
                if (trans != null) trans.Rollback();
                return false;
            }
            finally
            {
                if (trans != null) trans.Dispose();
                if (cmd != null) cmd.Dispose();
                if (cn.State == ConnectionState.Open) cn.Close();
                if (cn != null) cn.Dispose();
            }
        }
 private bool SaveGroupData(SignalStatusGroup_ssg_Info group, bool update)
 {
     Common.DefineConstantValue.EditStateEnum EditMode = update?
         Common.DefineConstantValue.EditStateEnum.OE_Update:
         Common.DefineConstantValue.EditStateEnum.OE_Insert;
     ReturnValueInfo rv = ((SignalLightsStatusBL)this._signalLightsStatusBL).SaveGroup(group, EditMode);
     return rv.boolValue;
 }
 private void LoadStatusGroupData()
 {
     if (GroupInfos != null) GroupInfos.Clear();
     else GroupInfos = new List<SignalStatusGroup_ssg_Info>();
     SignalStatusGroup_ssg_Info defaultGroup = new SignalStatusGroup_ssg_Info();
     defaultGroup.ssg_cGroupID = Guid.Empty;
     defaultGroup.ssg_cGroupName = defaultGroupName;
     GroupInfos.Add(defaultGroup);
     GroupInfos.AddRange(((SignalLightsStatusBL)this._signalLightsStatusBL).SearchGroupRecords(null));
     SignalStatusInfos = new List<SignalLightsStatus_sls_Info>();
 }
 private bool DelGroupData(SignalStatusGroup_ssg_Info group)
 {
     ReturnValueInfo rv = ((SignalLightsStatusBL)this._signalLightsStatusBL).SaveGroup(group, Common.DefineConstantValue.EditStateEnum.OE_Delete);
     return rv.boolValue;
 }
 private bool CheckGroupInput(int srcPos)
 {
     SignalStatusGroup_ssg_Info group = new SignalStatusGroup_ssg_Info();
     group.ssg_cGroupName = txGroupName.Text;
     //group.ssg_cGroupID = Guid.NewGuid();
     string errmsg = null;
     if (group.ssg_cGroupName.Length < 4) errmsg += (errmsg != null ? "\n" : "") + "組名不能少於4個字符";
     if (group.ssg_cGroupName.Length > 32) errmsg += (errmsg != null ? "\n" : "") + "組名長度不能超過32個字符";
     if (srcPos < 0 || srcPos > GroupInfos.Count) errmsg += (errmsg != null ? "\n" : "") + "请选中要修改的内容";
     else
     {
         for (int i = 0; i < GroupInfos.Count; i++)
         {
             if (i != srcPos && GroupInfos[i].ssg_cGroupName == group.ssg_cGroupName)
             {
                 errmsg += (errmsg != null ? "\n" : "") + "輸入的組名已存在";
                 break;
             }
         }
     }
     if (errmsg != null)
     {
         MessageBox.Show(this, errmsg, "錯誤提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         return false;
     }
     return true;
 }
        private void LoadStatusGroupData()
        {
            if (GroupInfos != null) GroupInfos.Clear();
            else GroupInfos = new List<SignalStatusGroup_ssg_Info>();
            if (signalGroupTable != null) signalGroupTable.Clear();
            else signalGroupTable = new Hashtable();

            SignalStatusGroup_ssg_Info defaultGroup = new SignalStatusGroup_ssg_Info();
            defaultGroup.ssg_cGroupID = Guid.Empty;
            defaultGroup.ssg_cGroupName = defaultGroupName;
            GroupInfos.Add(defaultGroup);
            List<SignalStatusGroup_ssg_Info> glist = ((SignalLightsStatusBL)this._signalLightsStatusBL).SearchGroupRecords(null);
            GroupInfos.AddRange(glist);
            SignalStatusInfos = new List<SignalLightsStatus_sls_Info>();

            signalGroupTable.Add(defaultGroup.ssg_cGroupID, defaultGroup);
            foreach (SignalStatusGroup_ssg_Info ssg in glist)
            {
                signalGroupTable.Add(ssg.ssg_cGroupID, ssg);
            }
        }
        public bool UpdateGroup(SignalStatusGroup_ssg_Info group)
        {
            if (group == null || group.ssg_cGroupID==null ||group.ssg_cGroupID==Guid.Empty) return false;
            if (group.ssg_cGroupName.Length < 4 || group.ssg_cGroupName.Length > 32) return false;
            SqlConnection cn = null;
            SqlCommand cmd = null;
            SqlTransaction trans = null;
            try
            {
                cn = new SqlConnection(SQLHelper.ConnectionString);
                if (cn.State == ConnectionState.Closed) cn.Open();
                trans = cn.BeginTransaction();

                string strSQL = "UPDATE dbo.SignalStatusGroup_ssg set ssg_cGroupName=@GroupName WHERE ssg_cGroupID=@GroupId";
                List<SqlParameter> sqlparams = new List<SqlParameter>();
                sqlparams.Add(SQLHelper.MakeInParam("@GroupName", SqlDbType.NVarChar, 32, group.ssg_cGroupName));
                sqlparams.Add(SQLHelper.MakeInParam("@GroupId", SqlDbType.UniqueIdentifier, 0, group.ssg_cGroupID));
                int rowsAffected = SQLHelper.ExecuteNonQuery(strSQL, sqlparams.ToArray());
                trans.Commit();
                return rowsAffected>0;//当更新的行数小于等于0时,更新失败
            }
            catch (Exception e)
            {
                if (trans != null) trans.Rollback();
                return false;
            }
            finally
            {
                if (trans != null) trans.Dispose();
                if (cmd != null) cmd.Dispose();
                if (cn.State == ConnectionState.Open) cn.Close();
                if (cn != null) cn.Dispose();
            }
        }
        public List<SignalStatusGroup_ssg_Info> SearchGroupRecords(string name)
        {
            List<SignalStatusGroup_ssg_Info> list = new List<SignalStatusGroup_ssg_Info>();
            try
            {
                string strSQL = "SELECT * FROM SignalStatusGroup_ssg";
                List<SqlParameter> sqlparams = new List<SqlParameter>();
                if (name != null && name.Trim() != string.Empty)
                {
                    strSQL += " WHERE ssg_cGroupName like @name";
                    sqlparams.Add(SQLHelper.MakeInParam("@name", SqlDbType.NVarChar, 32, "%" + name + "%"));
                }
                DataSet data = SQLHelper.ExecuteDataset(strSQL, sqlparams.ToArray());
                if (data.Tables.Count > 0 && data.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow row in data.Tables[0].Rows)
                    {
                        SignalStatusGroup_ssg_Info ssg = new SignalStatusGroup_ssg_Info();
                        ssg.ssg_cGroupID = row.IsNull("ssg_cGroupID") ? Guid.Empty : (Guid)row["ssg_cGroupID"];
                        ssg.ssg_cGroupName = Convert.ToString(row["ssg_cGroupName"]);
                        list.Add(ssg);
                    }
                    data.Clear();
                }

            }
            catch (Exception e)
            {
            }
            return list;
        }