예제 #1
0
        public int Add(CardManage.Model.Building model, out string strErrorInfo)
        {
            strErrorInfo = "";
            MySqlParameter[] parameters =
            {
                new MySqlParameter("@RtnInfo",           MySqlDbType.VarChar,  500),
                new MySqlParameter("@NewID",             MySqlDbType.Int32),
                new MySqlParameter("@Tag",               MySqlDbType.Int32),   //类型
                new MySqlParameter("@iID",               MySqlDbType.Int32),
                new MySqlParameter("@iBname",            MySqlDbType.VarChar),
                new MySqlParameter("@iFlag",             MySqlDbType.Int32),
                new MySqlParameter("@iCode",             MySqlDbType.Int32),
                new MySqlParameter("@iFID",              MySqlDbType.Int32),
                new MySqlParameter("@iContact",          MySqlDbType.VarChar),
                new MySqlParameter("@iTel",              MySqlDbType.VarChar),
                new MySqlParameter("@iBuildingSerialNo", MySqlDbType.VarChar)
            };
            parameters[0].Direction = ParameterDirection.Output;
            parameters[1].Direction = ParameterDirection.Output;
            parameters[2].Value     = 0;//新增
            parameters[3].Value     = 0;
            parameters[4].Value     = model.BName;
            parameters[5].Value     = model.Flag;
            parameters[6].Value     = model.Code;
            parameters[7].Value     = model.FID;
            parameters[8].Value     = model.Contact;
            parameters[9].Value     = model.Tel;
            parameters[10].Value    = model.BuildingSerialNo;

            try
            {
                DbHelperSQL.RunProcedure(string.Format("{0}_ADD_UPDATE", this._TableName), parameters, out int rowsAffected);
                strErrorInfo = Functions.FormatString(parameters[0].Value);
                int iNewID = Functions.FormatInt(parameters[1].Value);
                return(iNewID);
            }
            catch (MySqlException ex)
            {
                strErrorInfo = ex.Message;
                return(0);
            }
        }
예제 #2
0
        public CardManage.Model.Building GetModel(int Flag, int ID)
        {
            CardManage.Model.Building model      = null;
            MySqlParameter[]          parameters =
            {
                new MySqlParameter("@Flag",         MySqlDbType.Int32),
                new MySqlParameter("@SelNum",       MySqlDbType.Int32),
                new MySqlParameter("@Where_String", MySqlDbType.VarChar)
            };
            parameters[0].Value = Flag;
            parameters[1].Value = 1;
            parameters[2].Value = string.Format("ID={0}", ID);

            DataSet ds = DbHelperSQL.RunProcedure(string.Format("{0}_GetBywhere_Num", this._TableName), parameters, "ds");

            if (ds.Tables[0].Rows.Count > 0)
            {
                model = new CardManage.Model.Building();
                DataRow dRow = ds.Tables[0].Rows[0];
                model.ID               = Functions.FormatInt(dRow["ID"]);;
                model.BName            = Functions.FormatString(dRow["BName"]);
                model.Flag             = Functions.FormatInt(dRow["Flag"]);
                model.FlagDesc         = Functions.FormatString(dRow["FlagDesc"]);
                model.Code             = Functions.FormatInt(dRow["Code"]);
                model.Contact          = Functions.FormatString(dRow["Contact"]);
                model.Tel              = Functions.FormatString(dRow["Tel"]);
                model.BuildingSerialNo = Functions.FormatString(dRow["BuildingSerialNo"]);
                model.FID              = Functions.FormatInt(dRow["FID"]);

                switch (Flag)
                {
                case 1:    //楼栋->父:小区
                    model.FatherInfo = new Model.Building()
                    {
                        ID    = model.FID,
                        Flag  = model.Flag - 1,
                        BName = Functions.FormatString(dRow["AreaName"]),
                        Code  = Functions.FormatInt(dRow["AreaCode"]),
                        FID   = 0
                    };
                    break;

                case 2:    //单元->父:楼栋
                    model.FatherInfo = new Model.Building()
                    {
                        ID    = model.FID,
                        Flag  = model.Flag - 1,
                        BName = Functions.FormatString(dRow["BuildName"]),
                        Code  = Functions.FormatInt(dRow["BuildCode"]),
                        FID   = Functions.FormatInt(dRow["AreaID"]),

                        //楼栋->父:小区
                        FatherInfo = new Model.Building()
                    };
                    model.FatherInfo.FatherInfo.ID    = model.FatherInfo.FID;
                    model.FatherInfo.FatherInfo.Flag  = model.FatherInfo.Flag - 1;
                    model.FatherInfo.FatherInfo.BName = Functions.FormatString(dRow["AreaName"]);
                    model.FatherInfo.FatherInfo.Code  = Functions.FormatInt(dRow["AreaCode"]);
                    model.FatherInfo.FatherInfo.FID   = 0;
                    break;

                case 3:    //房间->父:单元
                    model.FatherInfo = new Model.Building()
                    {
                        ID    = model.FID,
                        Flag  = model.Flag - 1,
                        BName = Functions.FormatString(dRow["UnitName"]),
                        Code  = Functions.FormatInt(dRow["UnitCode"]),
                        FID   = Functions.FormatInt(dRow["BuildID"])
                    };

                    //单元->父:楼栋
                    model.FatherInfo.FatherInfo = new Model.Building()
                    {
                        ID    = model.FatherInfo.FID,
                        Flag  = model.FatherInfo.Flag - 1,
                        BName = Functions.FormatString(dRow["BuildName"]),
                        Code  = Functions.FormatInt(dRow["BuildCode"]),
                        FID   = Functions.FormatInt(dRow["AreaID"]),

                        //楼栋->父:小区
                        FatherInfo = new Model.Building()
                    };
                    model.FatherInfo.FatherInfo.FatherInfo.ID    = model.FatherInfo.FatherInfo.FID;
                    model.FatherInfo.FatherInfo.FatherInfo.Flag  = model.FatherInfo.FatherInfo.Flag - 1;
                    model.FatherInfo.FatherInfo.FatherInfo.BName = Functions.FormatString(dRow["AreaName"]);
                    model.FatherInfo.FatherInfo.FatherInfo.Code  = Functions.FormatInt(dRow["AreaCode"]);
                    model.FatherInfo.FatherInfo.FatherInfo.FID   = 0;
                    break;
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }