Gentel的一些基本操作

/// <summary>
        /// 取得最大序列号
        /// </summary>
        /// <param name="guid">guid号</param>
        /// <param name="RunType">新增:true;查询:false</param>
        /// <returns>序列号</returns>
        public static int getSequenceNum (long PersonnelAutoID, bool RunType) {
            string tableName = new YLFNBaseHelper<T>().GetTableName();
            int maxNum = 1;
            string strSql = "Select max(SequenceNum) From " + tableName + " With(nolock) ";
            strSql += " Where PersonnelAutoID = " + PersonnelAutoID.ToString().Trim();
            SqlResult sr = Broker.Execute(strSql);
            if (RunType)//新增时
            {
                if (sr != null)
                    maxNum = sr.GetInt(0, 0) + 1;
                else
                    maxNum = 1;
            }
            else
            { //查询时
                if (sr != null)
                    maxNum = sr.GetInt(0, 0);
                else
                    maxNum = 0;//没有信息时
            }
            return maxNum;
        }
    }


        public static void RemoveAll (long personnelAutoID)
        {
            SqlBuilder sb = new SqlBuilder(Gentle.Framework.StatementType.Select, typeof(T));
            sb.AddConstraint(Operator.Equals, "PersonnelAutoID", personnelAutoID);
            SqlStatement st = sb.GetStatement(true);
            SqlResult sr = Broker.Execute(st);
            if (sr.Rows.Count > 0)
            {
                SqlBuilder RemoveSB = new SqlBuilder(Gentle.Framework.StatementType.Delete, typeof(T));
                RemoveSB.AddConstraint(Operator.Equals, "PersonnelAutoID", personnelAutoID);
                SqlStatement RemoveST = RemoveSB.GetStatement();
                string sql = RemoveST.Sql;
                RemoveST.Execute();
                return;
            }
            return;
        }
        #endregion


        public static bool IsExistUnit(string strUnitCoding)
        {
            SqlBuilder sb = new SqlBuilder(Gentle.Framework.StatementType.Select, typeof(T));
            sb.AddConstraint(Operator.Equals, "UnitCode", strUnitCoding);
            SqlStatement st = sb.GetStatement(true);
            SqlResult sr = Broker.Execute(st);
            if (sr.Rows.Count > 0)
                return true;
            return false;
        }
        #endregion

 public static DataTable GetNextUnitList(string perUnitCoding)
        {
           
            int codeLen=perUnitCoding.Trim().Length;
            int selectCodeLen=0;
            if (codeLen < 2) return null;

            if(codeLen>=2&&codeLen<4)
            {
                selectCodeLen=4;
                codeLen=2;
            }
            if(codeLen>=4&&codeLen<6)
            {
                selectCodeLen=6;
                codeLen=4;
            }
            if(codeLen>=6&&codeLen<9)
            {
                selectCodeLen=9;
                 codeLen=6;
            }
            if(codeLen>=9&&codeLen<12)
            {
                selectCodeLen=12;
                 codeLen=9;
            }
            string sql = "select * from m_Units where len(UnitCoding)=" + selectCodeLen.ToString() +
                " and left(UnitCoding," + codeLen.ToString() + ")="+perUnitCoding.Substring(0,codeLen).ToString();

            SqlStatement stmt = new SqlStatement(Gentle.Framework.StatementType.Select, new System.Data.SqlClient.SqlCommand(), sql);

            return ObjectView.GetDataView(stmt.Execute()).ToTable();
        }



 public static DataTable GetQueryDataTable(string CropID, string OrderID)
        {
            string StrSQl = "SELECT OrderID,LineID,OrderPersonnelNum,Linkman,LinkSex,LinkTelphone,LinkFax,Linkmobile,LinkEmail,";
            StrSQl += "dbo.getLineName(LineID) AS LineName,JoinTeamDate,OrderDate,Remark,";
            StrSQl += "CASE OrderStatus WHEN 0 THEN '待确认' WHEN 1 THEN '已确认' WHEN 2 THEN '已取消' END AS OrderStatus,";
            StrSQl += "CASE AffirmMothed WHEN 1 THEN '短信' WHEN 2 THEN '电话' WHEN 3 THEN 'Email' WHEN 4 THEN '传真' END AS AffirmMothed";
            StrSQl += " FROM TourOrderInfo";
            StrSQl += " WHERE CropID ='" + CropID + "' AND OrderID LIKE '%" + OrderID + "%'";
            SqlResult sr = Broker.Execute(StrSQl);
            DataTable dt = ObjectView.GetDataView(sr).Table;
            if (dt.Rows.Count > 0)
            {
                return dt;
            }
            else
            {
                return null;
            }
        }

public static DataTable GetLineGroupDT(int typevalue, string CropID)
        {
            string StrSQl = "SELECT GroupID,dbo.getLineName(LineID) AS LineName,ProductCode,JourneyPersonnelNum,LinePrice,JourneyDays,";
            StrSQl += "StartLineContent,CONVERT(varchar(12) , StartLineDate, 102 )  AS StartLineDate,";//发团周期、固定发团时间
            StrSQl += " (HomePosition+SPACE(1)+ArrivePosition) AS Position,PublishDate,CropID,LineID";//始发地和目的地、发布时间
            StrSQl += " FROM TourGroupInfo ";
            StrSQl += " WHERE CropID ='" + CropID + "' AND LineID= '" + typevalue + "'";
            SqlResult sr = Broker.Execute(StrSQl);
            DataTable dt = ObjectView.GetDataView(sr).Table;
            if (dt.Rows.Count > 0)
            {
                return dt;
            }
            else
            {
                return null;
            }
        }

 public static DataTable GetNewsTypeDT(int typevalue)
        {
            string Sqlstr = "  SELECT NewsID,NewsTitle,NewsDate,NewsAuthor,NewsType,IsGoodNews FROM tour_news Where ";
            Sqlstr += "NewsType =" + typevalue;
            Sqlstr += " Order By NewsDate Desc ";
            SqlResult sr = Broker.Execute(Sqlstr.ToString());
            DataTable dt = ObjectView.GetDataView(sr).Table;
            if (dt.Rows.Count > 0)
            {
                return dt;
            }
            else
            {
                return null;
            }
        }

 public static bool NowISFeed(long PersonnelAutoID)
        {
            string sql = "select NowIsFeed from WM_BornInfo WITH (NOLOCK) where PersonnelAutoID = " + PersonnelAutoID;
            SqlStatement stmt = new SqlStatement(Gentle.Framework.StatementType.Select, new SqlCommand(), sql);
            SqlResult sr = stmt.Execute();
            if (sr.Rows.Count > 0)
            {
                // bool ddd = sr.GetBoolean(0, 0);
                //return ddd;
                return sr.GetBoolean(0, 0);
            }
            return false;
        }

 public static DataTable GetDataTableList(string strTable,string unitcoding)
        {
            string sql = "select * from " + strTable + " where UnitCoding ='" + unitcoding + "'";
            SqlStatement stmt = new SqlStatement(Gentle.Framework.StatementType.Select, new SqlCommand(), sql);
            SqlResult sr = stmt.Execute();
            if (sr.Rows.Count > 0)
                return ObjectView.GetDataView(sr).Table;
            return null;
        } 

 public static DataTable GetLineGroupDT(int typevalue, string CropID)
        {
            string StrSQl = "SELECT GroupID,dbo.getLineName(LineID) AS LineName,ProductCode,JourneyPersonnelNum,LinePrice,JourneyDays,";
            StrSQl += "StartLineContent,CONVERT(varchar(12) , StartLineDate, 102 )  AS StartLineDate,";
            StrSQl += " (HomePosition+SPACE(1)+ArrivePosition) AS Position,PublishDate,CropID,LineID";
            StrSQl += " FROM TourGroupInfo ";
            StrSQl += " WHERE CropID ='" + CropID + "' AND LineID= '" + typevalue + "'";
            SqlResult sr = Broker.Execute(StrSQl);
            DataTable dt = ObjectView.GetDataView(sr).Table;
            if (dt.Rows.Count > 0)
            {
                return dt;
            }
            else
            {
                return null;
            }
        }

 /// <summary>
        /// 返回户信息DateDatable(查询时候使用)
        /// </summary>
        /// <param name="unitcoding">户所在协会单位代码</param>
        /// <param name="FamilyName">户主名称</param>
        /// <param name="BeginDate">开始时间</param>
        /// <param name="EndDate">结束时间</param>
        /// <returns></returns>
        public static DataTable GetPutFamily_List(string unitcoding, string FamilyName,string BeginDate, string EndDate)
        {
            string sql = "select * from xhm_LinkInfo where UnitCoding = '" + unitcoding + "'";

            //查找相似名称的户主
            if (!string.IsNullOrEmpty(FamilyName))
            {
                sql += " and FamilyName like '%" + FamilyName + "%'";
            }
            //开始时间不为空,则查询大于当前选择时间的所有记录
            if (!string.IsNullOrEmpty(BeginDate))
            {
                sql += " and CreateDate >= '" + BeginDate + "'";
            }

            //结束时间不为空,则查询小于当前选择时间的所有记录
            if (!string.IsNullOrEmpty(EndDate))
            {
                sql += " and CreateDate <= '" + EndDate + "'";
            }

            //如果时间都不 选择则只查询当前月的记录(月初1号到月底)
            if (string.IsNullOrEmpty(BeginDate) && string.IsNullOrEmpty(EndDate))
            {
                //DaysInMonth:返回指定年和月中的天数。
                int getCurrentMonthMaxDay = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month);
                sql += " and CreateDate >= '" + DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + "1' and CreateDate <= '" + DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + getCurrentMonthMaxDay + "'";
            }
            SqlStatement stmt = new SqlStatement(Gentle.Framework.StatementType.Select, new SqlCommand(), sql);
            SqlResult sr = stmt.Execute();
            if (sr.Rows.Count > 0)
                return ObjectView.GetDataView(sr).Table;
            return null;
        }



/// <summary>
        /// 人员基本信息
        /// </summary>
        /// <param name="unitCoding"></param>
        /// <param name="whereSql"></param>
        /// <param name="pageNumber"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public static DataTable Page(string unitCoding, string whereSql, int pageNumber, int pageSize)
        {
            SqlCommand cmd = new SqlCommand();
            int _rowLimit = pageSize;//每行显示20条记录
            int _rowOffset = 0;
            string sql = "Select MemberID,MemberName,LoginID,IDCardNumber, ";
            sql += " SexName,JobID,JobName ";
            sql += " From dbo.v_xhm_MemberInfo Where " + whereSql;
            sql += " Order by UnitCoding Asc";
            SqlStatement st = new SqlStatement(Gentle.Framework.StatementType.Select, cmd, sql, _rowLimit, _rowOffset);
            ArrayList rows = st.Page(pageNumber).Rows;
            if (rows.Count > 0)
            {
                //构造结果记录集表
                DataTable dt = new DataTable();
                DataColumn col0 = new DataColumn("MemberID");//人员编号
                DataColumn col1 = new DataColumn("MemberName");//姓名
                DataColumn col2 = new DataColumn("LoginID");//登录ID
                DataColumn col3 = new DataColumn("IDCardNumber");//身份证号
                DataColumn col4 = new DataColumn("SexName");//性别
                DataColumn col5 = new DataColumn("JobID");//职务编号
                DataColumn col6 = new DataColumn("JobName");//职务名称
                dt.Columns.Add(col0);
                dt.Columns.Add(col1);
                dt.Columns.Add(col2);
                dt.Columns.Add(col3);
                dt.Columns.Add(col4);
                dt.Columns.Add(col5);
                dt.Columns.Add(col6);
                for (int i = 0; i < rows.Count; i++)
                {
                    object[] objectRow = rows[i] as object[];
                    DataRow row = dt.NewRow();
                    row["MemberID"] = objectRow[0];
                    row["MemberName"] = objectRow[1];
                    row["LoginID"] = objectRow[2];
                    row["IDCardNumber"] = objectRow[3];
                    row["SexName"] = objectRow[4];
                    row["JobID"] = objectRow[5];
                    row["JobName"] = objectRow[6];
                    dt.Rows.Add(row);
                }
                return dt;
            }
            return null;
        }

  /// <summary>
        /// 取得一笔资料
        /// </summary>
        /// <param name="unitCoding"></param>
        /// <returns></returns>
        public static DataTable GetUnitCodingList(string unitCoding)
        {
            SqlBuilder sb = new SqlBuilder(Gentle.Framework.StatementType.Select, typeof(XHM_UnitInfo));
            if (!string.IsNullOrEmpty(unitCoding))
                sb.AddConstraint(Operator.Equals, "UnitCoding", unitCoding);
            SqlStatement st = sb.GetStatement(true);
            SqlResult sr = st.Execute();
            DataTable dt = new DataTable();
            for (int i = 0; i < sr.ColumnNames.Length; i++)
            {
                DataColumn col = new DataColumn(sr.ColumnNames[i]);
                dt.Columns.Add(col);
            }
            for (int m = 0; m < sr.Rows.Count; m++)
            {
                DataRow row = dt.NewRow();
                row["UnitCoding"] = sr.GetString(m, "UnitCoding");
                row["UnitName"] = sr.GetString(m, "UnitName");
                row["UnitType"] = sr.GetBoolean(m, "UnitType");
                row["PersonnelCount"] = sr.GetInt(m, "PersonnelCount");
                row["Notes"] = sr.GetString(m, "Notes");
                dt.Rows.Add(row);
            }
            return dt;
        }

 /// <summary>
        /// 删除该单位的信息
        /// </summary>
        /// <param name="unitCoding"></param>
      public static void RemoveAll(string unitCoding)
        {
            SqlBuilder RemoveSB = new SqlBuilder(Gentle.Framework.StatementType.Delete, typeof(XHM_UnitInfo));
            RemoveSB.AddConstraint(Operator.Equals, "UnitCoding", unitCoding);
            SqlStatement RemoveST = RemoveSB.GetStatement();
            RemoveST.Execute();
        }
posted @ 2007-09-11 17:45  nestea  阅读(396)  评论(0编辑  收藏  举报