Example #1
0
 public Drawing(Drawing obj)
 {
     PropertyInfo[] p = obj.GetType().GetProperties();                               // get entity properties
     for (int i = 0; i < (p.Length); i++)
     {
         if (!p[i].PropertyType.Name.Contains("list") && !p[i].Name.Contains("arg"))
             p[i].SetValue(this, p[i].GetValue(obj, null), null);                    // set entity's property values to obj properties
     }
 }
        public object Fetch(object obj)
        {
            int id;
            string type;                                                                    //type of object passed
            string objtype = obj.GetType().ToString();                                      //get object type
            if (objtype == "System.String")
            {
                string[] strTemp = ((string)obj).Split(new char[] { '|' });                 //if the object type is a string then extract the id and type
                id = Convert.ToInt32(strTemp[0]);
                type = strTemp[1];
            }
            else
            {
                id = ((Drawing)obj).dwg_id;
                type = "all";                                                               //object is  drawing and get all information
            }

            _drawing = new Drawing();
            _user = (User)System.Web.HttpContext.Current.Session[Constant.session.User];
            _dbmgr = new DBManager(_user.plantDBStr);
            _dbmgr.ConnectionString = _user.plantDBStr;

            try
            {
                _dbmgr.Open();
                switch (type)
                {
                    case "component":
                        FetchComponentList(id, _dbmgr);
                        return _drawing.componentlist;
                    case "cable":
                        FetchCableList(id, _dbmgr);
                        return _drawing.cablelist;
                    case "routeloca":
                        FetchRoutelocaList(id, _dbmgr);
                        return _drawing.routelocalist;
                    default:
                        FetchDrawing(id, _dbmgr);
                        FetchComponentList(id, _dbmgr);
                        FetchCableList(id, _dbmgr);
                        FetchRoutelocaList(id, _dbmgr);
                        return _drawing;
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                _dbmgr.Dispose();
            }
        }
        private void FetchDrawing(int id, IDBManager dbmgr)
        {
            string qryLocal = "SELECT * FROM viewDWGLIST WHERE DWG_ID=@id";

            dbmgr.CreateParameters(1);
            dbmgr.AddParameters(0, "@id", id);
            dbmgr.ExecuteReader(CommandType.Text, qryLocal);
            if (dbmgr.DataReader.Read())
            {
                // get properties of object and fetch object
                PropertyInfo[] p = _drawing.GetType().GetProperties();
                _drawing = (Drawing)FetchObject(_drawing, p, dbmgr);
            }

            dbmgr.CloseReader();
        }