Example #1
0
            public FuncStatus DataBind(BindOperator _bp)
            {
                bool            _tf = true;
                int             i;
                OleDbConnection _conn = new OleDbConnection(Prument.Properties.Settings.Default.Properties["dataConnectionString"].DefaultValue.ToString());
                OleDbCommand    _cmd  = new OleDbCommand();
                OleDbDataReader _dr;

                _cmd.Connection = _conn;
                try
                {
                    _conn.Open();
                    if (_bp == BindOperator.Update)
                    {
                        _cmd.CommandText = "delete from Images where pID = " + this.pID;
                        _cmd.ExecuteNonQuery();
                    }
                    if (_bp == BindOperator.Insert || _bp == BindOperator.Update)
                    {
                        i = 0;
                        while (i < _max)
                        {
                            _cmd.CommandText = "insert into Images (Path,pID) values ('" + this.Path[i] + "'," + this.pID + ")";
                            _cmd.ExecuteNonQuery();
                            i++;
                        }
                    }
                    _cmd.CommandText = "select ID,Path,pID from Images where pID=" + this.pID;
                    _dr = _cmd.ExecuteReader();
                    i   = 0;
                    while (_dr.Read())
                    {
                        this.ID[i]   = _dr.GetInt32(0);
                        this.Path[i] = _dr.GetValue(1).ToString();
                        this.pID     = _dr.GetInt32(2);
                        i++;
                    }
                }
                catch (Exception ex) {
                    _tf = false;
                    Exception _ex = new Exception("ORM.Images:" + ex.Message);
                    throw _ex;
                }
                finally
                {
                    _conn.Close();
                }
                return(_tf == false ? FuncStatus.Fail : FuncStatus.Success);
            }
Example #2
0
            public FuncStatus DataBind(BindOperator _bo)
            {
                bool            _tf   = true;
                OleDbConnection _conn = new OleDbConnection(Prument.Properties.Settings.Default.Properties["dataConnectionString"].DefaultValue.ToString());
                OleDbCommand    _cmd  = new OleDbCommand();
                OleDbDataReader _dr;

                _cmd.Connection = _conn;
                try
                {
                    _conn.Open();
                    if (_bo == BindOperator.Select)
                    {
                        _cmd.CommandText = "select Products.ID,Products.Name,Products.Description from Products where " + (this.ID != 0 ? "ID=" + this.ID.ToString() : (this.Name != null ? "Name='" + this.Name : "Description like '_" + this.Description + "_") + "'");
                    }
                    if (_bo == BindOperator.Insert)
                    {
                        _cmd.CommandText = "insert into Products (Name,Description) values ('" + this.Name + "','" + this.Description + "')";
                        _cmd.ExecuteScalar();
                        _cmd.CommandText = "select ID,Name,Description from products where id = (select Max(ID) from Products)";
                    }
                    if (_bo == BindOperator.Update)
                    {
                        _cmd.CommandText = "update products set Name='" + this.Name + "',Description='" + this.Description + "' where ID=" + this.ID;
                        _cmd.ExecuteNonQuery();
                        _cmd.CommandText = "select ID,Name,Description from products where id = " + this.ID;
                    }
                    if (_bo == BindOperator.Delete)
                    {
                        _cmd.CommandText = "select ID,Name,Description from products where id = " + this.ID;
                    }
                    _dr = _cmd.ExecuteReader();
                    _dr.Read();
                    this.ID          = _dr.GetInt32(0);
                    this.Name        = _dr.GetValue(1).ToString();
                    this.Description = _dr.GetValue(2).ToString();
                    this.Images.pID  = this.ID;
                    _dr.Close();
                    if (_bo == BindOperator.Select)
                    {
                        Images.DataBind(_bo);
                    }
                    if (_bo == BindOperator.Insert)
                    {
                        Images.DataBind(_bo);
                    }
                    if (_bo == BindOperator.Update && this.Images.Path[0] != "")
                    {
                        Images.DataBind(_bo);
                    }
                    if (_bo == BindOperator.Delete)
                    {
                        _cmd.CommandText = "delete from products where ID=" + this.ID;
                        _cmd.ExecuteNonQuery();
                        this.Images.clear();
                        this.Images.DataBind(BindOperator.Update);
                    }
                    this.Status = ORMStatus.Saved;
                }
                catch (Exception ex)
                {
                    _tf = false;
                    Exception _ex = new Exception("ORM.Products[" + this.ID + "]:" + ex.Message);
                    throw _ex;
                }
                finally {
                    _conn.Close();
                }
                return(_tf == false?FuncStatus.Fail:FuncStatus.Success);
            }
Example #3
0
            public FuncStatus DataBind(BindOperator _bo)
            {
                bool _tf = true;
                OleDbConnection _conn = new OleDbConnection(Prument.Properties.Settings.Default.Properties["dataConnectionString"].DefaultValue.ToString());
                OleDbCommand _cmd = new OleDbCommand();
                OleDbDataReader _dr;
                _cmd.Connection = _conn;
                try
                {
                    _conn.Open();
                    if (_bo == BindOperator.Select)
                    {
                        _cmd.CommandText = "select Products.ID,Products.Name,Products.Description from Products where " + (this.ID != 0 ? "ID=" + this.ID.ToString() : (this.Name != null ? "Name='" + this.Name : "Description like '_" + this.Description + "_") + "'");

                    }
                    if (_bo == BindOperator.Insert)
                    {
                        _cmd.CommandText = "insert into Products (Name,Description) values ('" + this.Name + "','" + this.Description + "')";
                        _cmd.ExecuteScalar();
                        _cmd.CommandText = "select ID,Name,Description from products where id = (select Max(ID) from Products)";
                    }
                    if (_bo == BindOperator.Update) {
                        _cmd.CommandText = "update products set Name='" + this.Name + "',Description='" + this.Description + "' where ID=" +this.ID;
                        _cmd.ExecuteNonQuery();
                        _cmd.CommandText = "select ID,Name,Description from products where id = " + this.ID;
                    }
                    if (_bo == BindOperator.Delete)
                    {
                        _cmd.CommandText = "select ID,Name,Description from products where id = " + this.ID;
                    }
                    _dr = _cmd.ExecuteReader();
                    _dr.Read();
                    this.ID = _dr.GetInt32(0);
                    this.Name = _dr.GetValue(1).ToString();
                    this.Description = _dr.GetValue(2).ToString();
                    this.Images.pID = this.ID;
                    _dr.Close();
                    if (_bo == BindOperator.Select) {
                        Images.DataBind(_bo);
                    }
                    if (_bo == BindOperator.Insert) {
                        Images.DataBind(_bo);
                    }
                    if (_bo == BindOperator.Update && this.Images.Path[0] != "") {
                        Images.DataBind(_bo);
                    }
                    if (_bo == BindOperator.Delete)
                    {
                        _cmd.CommandText = "delete from products where ID=" + this.ID;
                        _cmd.ExecuteNonQuery();
                        this.Images.clear();
                        this.Images.DataBind(BindOperator.Update);
                    }
                    this.Status = ORMStatus.Saved;
                }
                catch (Exception ex)
                {
                    _tf = false;
                    Exception _ex = new Exception("ORM.Products["+this.ID+"]:" + ex.Message);
                    throw _ex;
                }
                finally {
                    _conn.Close();
                }
                return _tf == false?FuncStatus.Fail:FuncStatus.Success;
            }
Example #4
0
            public FuncStatus DataBind(BindOperator _bp)
            {
                bool _tf = true;
                int i;
                OleDbConnection _conn = new OleDbConnection(Prument.Properties.Settings.Default.Properties["dataConnectionString"].DefaultValue.ToString());
                OleDbCommand _cmd = new OleDbCommand();
                OleDbDataReader _dr;
                _cmd.Connection = _conn;
                try
                {
                    _conn.Open();
                    if (_bp == BindOperator.Update) {
                        _cmd.CommandText = "delete from Images where pID = " + this.pID;
                        _cmd.ExecuteNonQuery();
                    }
                    if (_bp == BindOperator.Insert || _bp == BindOperator.Update)
                    {
                        i = 0;
                        while (i < _max)
                        {
                            _cmd.CommandText = "insert into Images (Path,pID) values ('" + this.Path[i] + "'," + this.pID + ")";
                            _cmd.ExecuteNonQuery();
                            i++;
                        }
                    }
                    _cmd.CommandText = "select ID,Path,pID from Images where pID=" + this.pID;
                    _dr = _cmd.ExecuteReader();
                    i = 0;
                    while (_dr.Read())
                    {
                        this.ID[i] = _dr.GetInt32(0);
                        this.Path[i] = _dr.GetValue(1).ToString();
                        this.pID = _dr.GetInt32(2);
                        i++;
                    }

                }
                catch (Exception ex) {
                    _tf = false;
                    Exception _ex = new Exception("ORM.Images:" + ex.Message);
                    throw _ex;
                }
                finally
                {
                    _conn.Close();
                }
                return _tf == false ? FuncStatus.Fail : FuncStatus.Success;
            }