GetUpdateSQL() public static method

转换为更新语句
public static GetUpdateSQL ( Card c ) : string
c Card 卡片数据
return string
Example #1
0
            public bool Excute(params object[] args)
            {
                if (!dataform.CheckOpen())
                {
                    return(false);
                }
                bool modfiles = (bool)args[0];

                Card c       = dataform.GetCard();
                Card oldCard = dataform.GetOldCard();

                if (c.Equals(oldCard))                //没有修改
                {
                    MyMsg.Show(LMSG.ItIsNotChanged);
                    return(false);
                }
                if (c.id <= 0)
                {
                    MyMsg.Error(LMSG.CodeCanNotIsZero);
                    return(false);
                }
                string sql;

                if (c.id != oldCard.id)                    //修改了id
                {
                    sql = DataBase.GetInsertSQL(c, false); //插入
                    bool delold = MyMsg.Question(LMSG.IfDeleteCard);
                    if (delold)                            //是否删除旧卡片
                    {
                        if (DataBase.Command(dataform.GetOpenFile(),
                                             DataBase.GetDeleteSQL(oldCard)) < 2)
                        {
                            //删除失败
                            MyMsg.Error(LMSG.DeleteFail);
                            delold = false;
                        }
                        else
                        {                        //删除成功,添加还原sql
                            _undoSQL = DataBase.GetDeleteSQL(c) + DataBase.GetInsertSQL(oldCard, false);
                        }
                    }
                    else
                    {
                        _undoSQL = DataBase.GetDeleteSQL(c);                        //还原就是删除
                    }
                    //如果删除旧卡片,则把资源修改名字,否则复制资源
                    if (modfiles)
                    {
                        if (delold)
                        {
                            YGOUtil.CardRename(c.id, oldCard.id, dataform.GetPath());
                        }
                        else
                        {
                            YGOUtil.CardCopy(c.id, oldCard.id, dataform.GetPath());
                        }
                        this.modifiled = true;
                        this.oldid     = oldCard.id;
                        this.newid     = c.id;
                        this.delold    = delold;
                    }
                }
                else
                {                //更新数据
                    sql      = DataBase.GetUpdateSQL(c);
                    _undoSQL = DataBase.GetUpdateSQL(oldCard);
                }
                if (DataBase.Command(dataform.GetOpenFile(), sql) > 0)
                {
                    MyMsg.Show(LMSG.ModifySucceed);
                    dataform.Search(true);
                    dataform.SetCard(c);
                    return(true);
                }
                else
                {
                    MyMsg.Error(LMSG.ModifyFail);
                }
                return(false);
            }
Example #2
0
        //修改
        public bool ModCard(bool modfiles)
        {
            if (!dataform.CheckOpen())
            {
                return(false);
            }
            Card c       = dataform.GetCard();
            Card oldCard = dataform.GetOldCard();

            if (c.Equals(oldCard))//没有修改
            {
                MyMsg.Show(LMSG.ItIsNotChanged);
                return(false);
            }
            if (c.id <= 0)
            {
                MyMsg.Error(LMSG.CodeCanNotIsZero);
                return(false);
            }
            string sql;

            if (c.id != oldCard.id)                    //修改了id
            {
                sql = DataBase.GetInsertSQL(c, false); //插入
                bool delold = MyMsg.Question(LMSG.IfDeleteCard);
                if (delold)                            //是否删除旧卡片
                {
                    if (DataBase.Command(dataform.GetOpenFile(),
                                         DataBase.GetDeleteSQL(oldCard)) < 2)
                    {
                        //删除失败
                        MyMsg.Error(LMSG.DeleteFail);
                    }
                    else
                    {//删除成功,添加还原sql
                        undoSQL.Add(DataBase.GetDeleteSQL(c) + DataBase.GetInsertSQL(oldCard, false));
                    }
                }
                else
                {
                    undoSQL.Add(DataBase.GetDeleteSQL(c));                    //还原就是删除
                }
                //如果删除旧卡片,则把资源修改名字,否则复制资源
                if (modfiles)
                {
                    YGOUtil.CardRename(c.id, oldCard.id, dataform.GetPath(), delold);
                    FileModified modify = new FileModified();
                    modify.modifiled = true;
                    modify.oldid     = oldCard.id;
                    modify.newid     = c.id;
                    modify.delold    = delold;
                    undoModified.Add(modify);
                    undoDeleted.Add(new FileDeleted());
                    undoCopied.Add(new DBcopied());
                }
                else
                {
                    undoModified.Add(new FileModified());
                    undoDeleted.Add(new FileDeleted());
                    undoCopied.Add(new DBcopied());
                }
            }
            else
            {//更新数据
                sql = DataBase.GetUpdateSQL(c);
                undoSQL.Add(DataBase.GetUpdateSQL(oldCard));
                undoModified.Add(new FileModified());
                undoDeleted.Add(new FileDeleted());
                undoCopied.Add(new DBcopied());
            }
            if (DataBase.Command(dataform.GetOpenFile(), sql) > 0)
            {
                MyMsg.Show(LMSG.ModifySucceed);
                dataform.Search(true);
                dataform.SetCard(c);
                return(true);
            }
            else
            {
                MyMsg.Error(LMSG.ModifyFail);
            }
            return(false);
        }