コード例 #1
0
        public static string DeleteNode(string GUID, string NodeType)
        {
            UpdateDBResult res = new UpdateDBResult();

            try
            {
                CategoryTypes type = CategoryTypes.Root;
                if (Enum.TryParse <CategoryTypes>(NodeType, out type) == true)
                {
                    switch (type)
                    {
                    case CategoryTypes.Category:
                    case CategoryTypes.Component:
                        SqlProvider.dbExecuteNoQuery("CBOMV2", "delete from CBOM_CATALOG_V2 where ID = '" + GUID + "'");
                        break;

                    case CategoryTypes.Root:
                    default:
                        break;
                    }
                }
                res.IsUpdated = true;
            }
            catch (Exception ex)
            {
                res.IsUpdated     = false;
                res.ServerMessage = ex.Message;
            }
            return(Newtonsoft.Json.JsonConvert.SerializeObject(res));
        }
コード例 #2
0
        public static string ReOrderBySeq(string GUID)
        {
            UpdateDBResult res        = new UpdateDBResult();
            String         select_str = String.Empty;

            try
            {
                select_str = " DECLARE @Child hierarchyid " +
                             " SELECT @Child = HIE_ID FROM CBOM_CATALOG_V2 " +
                             " WHERE ID = '" + GUID + "' " +
                             " SELECT * FROM CBOM_CATALOG_V2 " +
                             " WHERE HIE_ID.GetAncestor(1) = @Child " +
                             " ORDER BY SEQ_NO ";
                DataTable dt = SqlProvider.dbGetDataTable("CBOMV2", select_str);

                if (dt != null && dt.Rows.Count > 0)
                {
                    int           seq  = 0;
                    String        str1 = String.Empty;
                    List <String> str2 = new List <string>();

                    foreach (DataRow d in dt.Rows)
                    {
                        str1 += " WHEN '" + d["CATALOG_NAME"].ToString() + "' THEN '" + seq.ToString() + "' ";
                        str2.Add("'" + d["CATALOG_NAME"].ToString() + "'");
                        seq++;
                    }

                    String update_str = " UPDATE CBOM_CATALOG_V2 " +
                                        " SET SEQ_NO = CASE CATALOG_NAME " +
                                        str1 +
                                        " ELSE SEQ_NO " +
                                        " END " +
                                        " WHERE CATALOG_NAME IN " + "(" + String.Join(", ", str2.ToArray()) + ")" + "; ";
                    SqlProvider.dbExecuteNoQuery("CBOMV2", update_str);

                    res.IsUpdated = true;
                }
                else
                {
                    res.IsUpdated     = false;
                    res.ServerMessage = "Children nodes not found.";
                }
            }
            catch (Exception ex)
            {
                res.IsUpdated     = false;
                res.ServerMessage = ex.Message;
            }
            return(Newtonsoft.Json.JsonConvert.SerializeObject(res));
        }
コード例 #3
0
        public static string DropTreeNode(string parentid, string currentid, string currentseq, string targetid, string targetseq, string point)
        {
            UpdateDBResult res      = new UpdateDBResult();
            int            FinalSeq = 0;

            try
            {
                if (Convert.ToInt32(targetseq) < Convert.ToInt32(currentseq))
                {
                    FinalSeq = point.Equals("top", StringComparison.OrdinalIgnoreCase) ? Convert.ToInt32(targetseq) : Convert.ToInt32(targetseq) + 1;
                }
                else if (Convert.ToInt32(targetseq) > Convert.ToInt32(currentseq))
                {
                    FinalSeq = point.Equals("top", StringComparison.OrdinalIgnoreCase) ? Convert.ToInt32(targetseq) - 1 : Convert.ToInt32(targetseq);
                }
                else
                {
                    res.IsUpdated     = false;
                    res.ServerMessage = "Invalid operation, please try again.";
                    return(Newtonsoft.Json.JsonConvert.SerializeObject(res));
                }

                // final seq = itself, no need to do anything, return false.
                if (FinalSeq == Convert.ToInt32(currentseq))
                {
                    res.IsUpdated     = false;
                    res.ServerMessage = "Invalid operation - moving to current sequence.";
                    return(Newtonsoft.Json.JsonConvert.SerializeObject(res));
                }

                String str = " DECLARE @ID hierarchyid " +
                             " SELECT @ID  = HIE_ID " +
                             " FROM CBOM_CATALOG_V2 WHERE ID = '" + parentid + "' " +
                             " update CBOM_CATALOG_V2 SET SEQ_NO = SEQ_NO " + (FinalSeq > Convert.ToInt32(currentseq) ? " -1 " : " +1 ") +
                             " WHERE HIE_ID.GetAncestor(1) = @ID " +
                             " AND SEQ_NO >= '" + (FinalSeq > Convert.ToInt32(currentseq) ? Convert.ToInt32(currentseq) : FinalSeq) + "'" +
                             " AND SEQ_NO <= '" + (FinalSeq > Convert.ToInt32(currentseq) ? FinalSeq : Convert.ToInt32(currentseq)) + "' ";
                SqlProvider.dbExecuteNoQuery("CBOMV2", str);
                SqlProvider.dbExecuteNoQuery("CBOMV2", String.Format(" update  CBOM_CATALOG_V2 SET SEQ_NO = " + FinalSeq + " where ID = '" + currentid + "' "));

                res.IsUpdated = true;
            }
            catch (Exception ex)
            {
                res.IsUpdated     = false;
                res.ServerMessage = ex.Message;
            }
            return(Newtonsoft.Json.JsonConvert.SerializeObject(res));
        }
コード例 #4
0
        public static string UpdateSelectedNode(string GUID, string CategoryID, string Desc)
        {
            UpdateDBResult res = new UpdateDBResult();

            try
            {
                String str = "update CBOM_CATALOG_V2 set CATALOG_NAME = N'" + CategoryID + "', CATALOG_DESC = N'" + Desc + "' where ID = N'" + GUID + "'";
                SqlProvider.dbExecuteNoQuery("CBOMV2", str);
                res.IsUpdated = true;
            }
            catch (Exception ex)
            {
                res.IsUpdated     = false;
                res.ServerMessage = ex.Message;
            }
            return(Newtonsoft.Json.JsonConvert.SerializeObject(res));
        }
コード例 #5
0
        public static string AddNew(string ParentGUID, string CategoryID, string CategoryNote, string OrgID, CategoryTypes CategoryType, string Creator, string CategoryGUID)
        {
            UpdateDBResult res = new UpdateDBResult();

            try
            {
                string guid = System.Guid.NewGuid().ToString().Replace("-", "").Substring(0, 30);
                int    seq  = 0;

                if (!HasRepeatBrother(ParentGUID, CategoryID))
                {
                    seq = GetSeqNo(ParentGUID);
                    Tuple <bool, string> result = CreateNewCatalog(ParentGUID, guid, OrgID, CategoryID, CategoryNote, (int)CategoryType, seq, "", Creator, DateTime.Now, CategoryGUID);

                    //// if create new node to database failed, return false
                    if (!result.Item1)
                    {
                        res.IsUpdated     = false;
                        res.ServerMessage = "Error occurs while creating data to database.";
                        return(Newtonsoft.Json.JsonConvert.SerializeObject(res));
                    }
                }
                else
                {
                    res.IsUpdated     = false;
                    res.ServerMessage = "Same name is already existed in same level.";
                    return(Newtonsoft.Json.JsonConvert.SerializeObject(res));
                }
            }
            catch (Exception ex)
            {
                res.IsUpdated     = false;
                res.ServerMessage = ex.Message;
            }
            return(Newtonsoft.Json.JsonConvert.SerializeObject(res));
        }