Esempio n. 1
0
        public void ShowFieldsInTable()
        {
            Txt_TableName.Text = TableName;
            SQLiteDataAdapter da = new SQLiteDataAdapter("pragma table_info (" + TableName + ")", cnn);
            DataTable         dt = new DataTable();

            da.Fill(dt);
            _fieldlist.Clear();
            foreach (DataRow dr in dt.Rows)
            {
                Models.TableField _fld = new Models.TableField();
                _fld.FldName         = dr[1].ToString();
                _fld.FldType         = dr[2].ToString() == "INT" ? "INTEGER" : dr[2].ToString();
                _fld.FldIsNotNull    = Convert.ToInt16(dr[3]) == 0 ? "ALLOW NULL" : "NOT NULL";
                _fld.FldDefaultValue = dr[4].ToString();
                _fld.FldIsPrimary    = Convert.ToInt16(dr[5]) == 0?"NO":"YES"; ////YES, NO
                _fld.FldIsUpdated    = false;
                _fld.FldIsUnique     = FXS.IsFieldUnique(TableName, _fld.FldName);
                _fld.FldCollation    = FXS.GetFieldCollation(TableName, _fld.FldName);
                _fieldlist.Add(_fld);
                _origfieldlist.Add(_fld);
            }
            Dg_FieldList.DataSource = _fieldlist;
            for (int i = 0; i < Dg_FieldList.Rows.Count; i++)
            {
                Dg_FieldList.Rows[i].ReadOnly = true;
                foreach (DataGridViewCell cell in Dg_FieldList.Rows[i].Cells)
                {
                    cell.ReadOnly = true;
                }
            }
        }
Esempio n. 2
0
        private void EditTheTable()
        {
            cnn.Open();
            SQLiteCommand emir = new SQLiteCommand("", cnn);
            //SİLİNEN SÜTUN VAR MI
            bool _hasdele   = false;
            bool _haschange = false;

            foreach (Models.TableField fld in _origfieldlist)
            {
                if (!_fieldlist.Contains(fld))
                {
                    _hasdele = true;
                }
                if (fld.FldIsUpdated)
                {
                    _haschange = true;
                }
            }
            if (_hasdele || _haschange)
            {
                string _columnlist = "", _appendcolumn = "";
                foreach (Models.TableField fld in _fieldlist)
                {
                    _columnlist   = _columnlist + "," + fld.FldName;
                    _appendcolumn = _appendcolumn + "," + FXS.PrepareFieldString(fld);
                }
                _columnlist      = _columnlist.Substring(1);
                _appendcolumn    = _appendcolumn.Substring(1);
                emir.CommandText = "BEGIN TRANSACTION;" +
                                   "CREATE TEMPORARY TABLE t1_backup(" + _columnlist + ");" +
                                   "INSERT INTO t1_backup SELECT " + _columnlist + " FROM " + TableName + ";" +
                                   "DROP TABLE " + TableName + ";" +
                                   "CREATE TABLE " + TableName + " (" + _appendcolumn + ");" +
                                   "INSERT INTO " + TableName + " SELECT " + _columnlist + " FROM t1_backup;" +
                                   "DROP TABLE t1_backup;" +
                                   "COMMIT;";
                try
                {
                    emir.ExecuteNonQuery();
                }
                catch (Exception ex) { MessageBox.Show(ex.Message); }
            }
            //YENİ EKLENEN SÜTUN VAR MI
            foreach (Models.TableField fld in _fieldlist)
            {
                if (_origfieldlist.Contains(fld))
                {
                    continue;
                }
                try
                {
                    emir.CommandText = "ALTER TABLE " + TableName + " ADD COLUMN " + FXS.PrepareFieldString(fld);
                    emir.ExecuteNonQuery();
                }
                catch (Exception ex) { MessageBox.Show(ex.Message); }
            }
            cnn.Close();
            this.Close();
        }
Esempio n. 3
0
        private void CreateTheTable()
        {
            string _tblCODE = "CREATE TABLE [" + Txt_TableName.Text + "] (";

            foreach (Models.TableField fld in _fieldlist)
            {
                _tblCODE = _tblCODE + FXS.PrepareFieldString(fld) + ",";
            }
            _tblCODE = _tblCODE.Remove(_tblCODE.Length - 1) + ");";
            try
            {
                SQLiteCommand emir = new SQLiteCommand(_tblCODE, cnn);
                cnn.Open();
                emir.ExecuteNonQuery();
                MainForm frmp = (MainForm)Application.OpenForms["MainForm"];
                frmp.ShowDbStructure();
                this.Close();
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
        }