GetInsertSQL() public static method

转换为插入语句
public static GetInsertSQL ( Card c, bool ignore, bool hex = false ) : string
c Card 卡片数据
ignore bool
hex bool
return string
Beispiel #1
0
        /// <summary>
        /// 复制数据库
        /// </summary>
        /// <param name="DB">复制到的数据库</param>
        /// <param name="cards">卡片集合</param>
        /// <param name="ignore">是否忽略存在</param>
        /// <returns>更新数x2</returns>
        public static int CopyDB(string DB, bool ignore, params Card[] cards)
        {
            int result = 0;

            if (File.Exists(DB) && cards != null)
            {
                using (SQLiteConnection con = new SQLiteConnection(@"Data Source=" + DB))
                {
                    con.Open();
                    using (SQLiteTransaction trans = con.BeginTransaction())
                    {
                        using (SQLiteCommand cmd = new SQLiteCommand(con))
                        {
                            foreach (Card c in cards)
                            {
                                cmd.CommandText = DataBase.GetInsertSQL(c, ignore);
                                result         += cmd.ExecuteNonQuery();
                            }
                        }
                        trans.Commit();
                    }
                    con.Close();
                }
            }
            return(result);
        }
Beispiel #2
0
            public bool Excute(params object[] args)
            {
                if (!dataform.CheckOpen())
                {
                    return(false);
                }
                Card c = dataform.GetCard();

                if (c.id <= 0)                //卡片密码不能小于等于0
                {
                    MyMsg.Error(LMSG.CodeCanNotIsZero);
                    return(false);
                }
                Card[] cards = dataform.GetCardList(false);
                foreach (Card ckey in cards)                //卡片id存在
                {
                    if (c.id == ckey.id)
                    {
                        MyMsg.Warning(LMSG.ItIsExists);
                        return(false);
                    }
                }
                if (DataBase.Command(dataform.GetOpenFile(),
                                     DataBase.GetInsertSQL(c, true)) >= 2)
                {
                    MyMsg.Show(LMSG.AddSucceed);
                    _undoSQL = DataBase.GetDeleteSQL(c);
                    dataform.Search(true);
                    dataform.SetCard(c);
                    return(true);
                }
                MyMsg.Error(LMSG.AddFail);
                return(false);
            }
Beispiel #3
0
        //删除
        public bool DelCards(bool deletefiles)
        {
            if (!dataform.CheckOpen())
            {
                return(false);
            }
            Card[] cards = dataform.GetCardList(true);
            if (cards == null || cards.Length == 0)
            {
                return(false);
            }
            string undo = "";

            if (!MyMsg.Question(LMSG.IfDeleteCard))
            {
                return(false);
            }
            List <string> sql    = new List <string>();
            FileDeleted   delete = new FileDeleted();

            foreach (Card c in cards)
            {
                sql.Add(DataBase.GetDeleteSQL(c));//删除
                undo += DataBase.GetInsertSQL(c, true);
                //删除资源
                if (deletefiles)
                {
                    YGOUtil.CardDelete(c.id, dataform.GetPath(), YGOUtil.DeleteOption.BACKUP);
                    delete.deleted = true;
                    delete.ids.Add(c.id);
                }
            }
            if (DataBase.Command(dataform.GetOpenFile(), sql.ToArray()) >= (sql.Count * 2))
            {
                MyMsg.Show(LMSG.DeleteSucceed);
                dataform.Search(true);
                undoSQL.Add(undo);
                undoDeleted.Add(delete);
                undoModified.Add(new FileModified());
                undoCopied.Add(new DBcopied());
                return(true);
            }
            else
            {
                MyMsg.Error(LMSG.DeleteFail);
                dataform.Search(true);
            }
            return(false);
        }
Beispiel #4
0
            public bool Excute(params object[] args)
            {
                if (!this.dataform.CheckOpen())
                {
                    return(false);
                }

                bool deletefiles = (bool)args[0];

                Card[] cards = this.dataform.GetCardList(true);
                if (cards == null || cards.Length == 0)
                {
                    return(false);
                }

                string undo = "";

                if (!MyMsg.Question(LMSG.IfDeleteCard))
                {
                    return(false);
                }

                List <string> sql = new List <string>();

                foreach (Card c in cards)
                {
                    sql.Add(DataBase.GetDeleteSQL(c));                    //删除
                    undo += DataBase.GetInsertSQL(c, true);
                    //删除资源
                    if (deletefiles)
                    {
                        YGOUtil.CardDelete(c.id, this.dataform.GetPath());
                    }
                }
                if (DataBase.Command(this.dataform.GetOpenFile(), sql.ToArray()) >= (sql.Count * 2))
                {
                    MyMsg.Show(LMSG.DeleteSucceed);
                    this.dataform.Search(true);
                    this.undoSQL = undo;
                    return(true);
                }
                else
                {
                    MyMsg.Error(LMSG.DeleteFail);
                    this.dataform.Search(true);
                }
                return(false);
            }
Beispiel #5
0
        //添加
        public bool AddCard()
        {
            if (!dataform.CheckOpen())
            {
                return(false);
            }
            Card c = dataform.GetCard();

            if (c.id <= 0)//卡片密码不能小于等于0
            {
                MyMsg.Error(LMSG.CodeCanNotIsZero);
                return(false);
            }
            Card[] cards = dataform.GetCardList(false);
            foreach (Card ckey in cards)//卡片id存在
            {
                if (c.id == ckey.id)
                {
                    MyMsg.Warning(LMSG.ItIsExists);
                    return(false);
                }
            }
            if (DataBase.Command(dataform.GetOpenFile(),
                                 DataBase.GetInsertSQL(c, true)) >= 2)
            {
                MyMsg.Show(LMSG.AddSucceed);
                undoSQL.Add(DataBase.GetDeleteSQL(c));
                undoModified.Add(new FileModified());
                undoDeleted.Add(new FileDeleted());
                undoCopied.Add(new DBcopied());
                dataform.Search(true);
                dataform.SetCard(c);
                return(true);
            }
            MyMsg.Error(LMSG.AddFail);
            return(false);
        }
Beispiel #6
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);
            }
Beispiel #7
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);
        }
Beispiel #8
0
            public bool Execute(params object[] args)
            {
                if (!dataform.CheckOpen())
                {
                    return(false);
                }

                Card c = dataform.GetCard();

                if (c.id <= 0)//卡片密码不能小于等于0
                {
                    MyMsg.Error(LMSG.CodeCanNotIsZero);
                    return(false);
                }
                else if (c.id > 268435455)
                {
                    MyMsg.Error(LMSG.AddFail);
                    return(false);
                }
                else if (c.omega[0] > 0)
                {
                    if (c.ot > 0x7)
                    {
                        MyMsg.Error(LMSG.AddFail);
                        return(false);
                    }
                    else if (c.id > 134217727)
                    {
                        MyMsg.Warning("Strings will fail to show up for this passcode.");
                    }
                }
                Card[] cards = dataform.GetCardList(false);
                foreach (Card ckey in cards)//卡片id存在
                {
                    if (c.id == ckey.id)
                    {
                        MyMsg.Warning(LMSG.ItIsExists);
                        return(false);
                    }
                }
                if (DataBase.Command(dataform.GetOpenFile(),
                                     (dataform.GetOpenFile().EndsWith(".db", StringComparison.OrdinalIgnoreCase) || dataform.GetOpenFile().EndsWith(".bytes", StringComparison.OrdinalIgnoreCase) ? DataBase.OmegaGetInsertSQL(c, true) : DataBase.GetInsertSQL(c, true))) >= 2)
                {
                    MyMsg.Show(LMSG.AddSucceed);
                    undoSQL = DataBase.GetDeleteSQL(c);
                    dataform.Search(true);
                    dataform.SetCard(c);
                    return(true);
                }
                MyMsg.Error(LMSG.AddFail);
                return(false);
            }
Beispiel #9
0
            public bool Execute(params object[] args)
            {
                if (!dataform.CheckOpen())
                {
                    return(false);
                }

                bool deletefiles = (bool)args[0];

                Card[] cards = dataform.GetCardList(true);
                if (cards == null || cards.Length == 0)
                {
                    return(false);
                }

                string undo = "";

                if (!MyMsg.Question(LMSG.IfDeleteCard))
                {
                    return(false);
                }

                List <string> sql = new();

                foreach (Card c in cards)
                {
                    sql.Add(DataBase.GetDeleteSQL(c));//删除
                    undo += (dataform.GetOpenFile().EndsWith(".db", StringComparison.OrdinalIgnoreCase) || dataform.GetOpenFile().EndsWith(".bytes", StringComparison.OrdinalIgnoreCase)) ? DataBase.OmegaGetInsertSQL(c, true) : DataBase.GetInsertSQL(c, true);
                    //删除资源
                    if (deletefiles)
                    {
                        YGOUtil.CardDelete(c.id, dataform.GetPath());
                    }
                }
                if (DataBase.Command(dataform.GetOpenFile(), sql.ToArray()) >= (sql.Count * 2))
                {
                    MyMsg.Show(LMSG.DeleteSucceed);
                    dataform.Search(true);
                    undoSQL = undo;
                    return(true);
                }
                else
                {
                    MyMsg.Error(LMSG.DeleteFail);
                    dataform.Search(true);
                }
                return(false);
            }