Пример #1
0
        public List <IDGenCriteriaInfo> GetObjectByID(SqlTransaction objTransaction, IDGenCriteriaInfo objIDGenCriteriaInfo)
        {
            string pCompanyCode = String.Empty;

            pCompanyCode = objIDGenCriteriaInfo.CompanyCode_FK.ToString();
            List <IDGenCriteriaInfo> objIDGenCriteriaInfoList = new List <IDGenCriteriaInfo>();
            IDGenCriteriaInfo        IDGenCriteriaInfo        = new IDGenCriteriaInfo();
            StringBuilder            vComText = new StringBuilder();

            vComText.Append("SELECT CriteriaCode,CAST(CriteriaID as NUMERIC) CriteriaID,CriteriaName,CompanyCode,UserCode,ActionDate,ActionType,CriteriaConditionText FROM LS_IDGenCriteria Where CompanyCode =" + pCompanyCode + "");
            if (!string.IsNullOrEmpty(objIDGenCriteriaInfo.CriteriaCode_PK))
            {
                vComText.Append(" AND CriteriaCode='" + objIDGenCriteriaInfo.CriteriaCode_PK + "'");
            }
            else if (!string.IsNullOrEmpty(objIDGenCriteriaInfo.CriteriaID))
            {
                vComText.Append(" AND CriteriaID='" + objIDGenCriteriaInfo.CriteriaID + "'");
            }
            vComText.Append(" Order By CriteriaId");
            SqlConnection connection = _supplierDbContext.GetConn();

            connection.Open();
            SqlDataReader dr;
            SqlCommand    objDbCommand = new SqlCommand(vComText.ToString(), connection);

            dr = objDbCommand.ExecuteReader();
            while (dr.Read())
            {
                IDGenCriteriaInfo                       = new IDGenCriteriaInfo();
                IDGenCriteriaInfo.IsNew                 = false;
                IDGenCriteriaInfo.CompanyCode_FK        = Convert.ToInt16(dr["CompanyCode"]);
                IDGenCriteriaInfo.UserCode              = dr["UserCode"].ToString();
                IDGenCriteriaInfo.ActionDate            = dr["ActionDate"].ToString();
                IDGenCriteriaInfo.ActionType            = dr["ActionType"].ToString();
                IDGenCriteriaInfo.CriteriaCode_PK       = dr["CriteriaCode"].ToString();
                IDGenCriteriaInfo.CriteriaID            = dr["CriteriaID"].ToString();
                IDGenCriteriaInfo.CriteriaName          = dr["CriteriaName"].ToString();
                IDGenCriteriaInfo.CriteriaConditionText = dr["CriteriaConditionText"].ToString();
                objIDGenCriteriaInfoList.Add(IDGenCriteriaInfo);
            }
            dr.Close();
            if (objIDGenCriteriaInfoList.Count == 1)
            {
                IDGenCriteriaInfo.IDGenCriteriaConditionList_VW = GetCriteriaConditionList(objTransaction, IDGenCriteriaInfo);
            }
            return(objIDGenCriteriaInfoList);
        }
Пример #2
0
        public string GenerateIDWithDate(SqlTransaction objTransaction, object objModel, EnumIdCategory pCriteriaId, DateTime pDateTime)
        {
            IDGenCriteriaInfo objIDGenCriteriaInfo = new IDGenCriteriaInfo();

            objIDGenCriteriaInfo.CriteriaID = ((int)pCriteriaId).ToString();
            PropertyInfo pi = objModel.GetType().GetProperty("CompanyCode_FK");

            if (pi == null)
            {
                pi = objModel.GetType().GetProperty("CompanyCode");
                objIDGenCriteriaInfo.CompanyCode_FK = Convert.ToInt32(pi.GetValue(objModel, null));
            }
            else
            {
                objIDGenCriteriaInfo.CompanyCode_FK = (int)pi.GetValue(objModel, null);
            }
            List <IDGenCriteriaInfo> objIDGenCriteriaInfoList = GetObjectByID(objTransaction, objIDGenCriteriaInfo);
            StringBuilder            sbGenId = new StringBuilder();

            if (objIDGenCriteriaInfoList.Count > 0)
            {
                List <IDGenCriteriaCondition> objCriteriaConditionList = objIDGenCriteriaInfoList[0].IDGenCriteriaConditionList_VW;
                for (int i = 0; i < objCriteriaConditionList.Count; i++)
                {
                    IDGenCriteriaCondition objCriteriaCondition = (IDGenCriteriaCondition)objCriteriaConditionList[i];
                    switch (objCriteriaCondition.ConditionType)
                    {
                    case "0":    //"Business Object";
                        Type tp = objModel.GetType();

                        PropertyInfo objProperty = tp.GetProperty(objCriteriaCondition.ConditionValue.Split('.')[1].ToString());
                        if (objProperty != null)
                        {
                            string vText = objProperty.GetValue(objModel, null).ToString();
                            if (vText.Length > objCriteriaCondition.ConditionValueLength)
                            {
                                vText = vText.Substring(0, objCriteriaCondition.ConditionValueLength);
                            }
                            else
                            {
                                if (!string.IsNullOrEmpty(objCriteriaCondition.PaddingText))
                                {
                                    char PaddingText = objCriteriaCondition.PaddingText[0];

                                    vText = vText.PadRight(objCriteriaCondition.ConditionValueLength, PaddingText);
                                }
                                else
                                {
                                    vText = vText.PadLeft(objCriteriaCondition.ConditionValueLength, '0');
                                }
                            }
                            sbGenId.Append(vText);
                        }
                        break;

                    case "2":    //"System Year";
                        if (objCriteriaCondition.ConditionValueLength > 0)
                        {
                            string vYear = pDateTime.Year.ToString();
                            if (vYear.Length >= objCriteriaCondition.ConditionValueLength)
                            {
                                vYear = vYear.Substring(vYear.Length - objCriteriaCondition.ConditionValueLength, objCriteriaCondition.ConditionValueLength);
                                sbGenId.Append(vYear);
                            }
                            else
                            {
                                sbGenId.Append(vYear);
                            }
                        }
                        break;

                    case "3":    //"System Month";
                        if (objCriteriaCondition.ConditionValue.ToUpper() == "MMM")
                        {
                            sbGenId.Append(pDateTime.ToString("MMM"));
                        }
                        else if (objCriteriaCondition.ConditionValue.ToUpper() == "MM")
                        {
                            sbGenId.Append(pDateTime.ToString("MM"));
                        }
                        else
                        {
                            sbGenId.Append(pDateTime.ToString("MM"));
                        }
                        break;

                    case "4":    //"System Day";
                        //Bug Fixed [01-01-2012] By Bashar
                        string tempDay    = pDateTime.Day.ToString();
                        string tempDayPad = tempDay.PadLeft(tempDay.Length + 2, '0');
                        sbGenId.Append(tempDayPad.Substring(tempDayPad.Length - 2, 2));
                        //sbGenId.Append(DateTime.Now.Day.ToString());
                        break;

                    case "5":    //"System Hour";
                        sbGenId.Append(DateTime.Now.Hour.ToString());
                        break;

                    case "6":    //"System Min";
                        sbGenId.Append(DateTime.Now.Minute.ToString());
                        break;

                    case "7":    //"System Sec";
                        sbGenId.Append(DateTime.Now.Second.ToString());
                        break;

                    case "8":    //"Static Value";
                        sbGenId.Append(objCriteriaCondition.ConditionValue.ToString());
                        break;

                    case "9":    //"Auto Increment";
                        sbGenId = GetAutoIncrimentValue(objTransaction, objModel, objCriteriaCondition, sbGenId, objCriteriaConditionList, pDateTime);
                        break;
                    }
                }
            }
            return(sbGenId.ToString());
        }
Пример #3
0
        public List <IDGenCriteriaCondition> GetCriteriaConditionList(SqlTransaction objTransaction, IDGenCriteriaInfo objIDGenCriteriaInfo)
        {
            string pCompanyCode = String.Empty;

            pCompanyCode = objIDGenCriteriaInfo.CompanyCode_FK.ToString();
            List <IDGenCriteriaCondition> CriteriaConditionList = new List <IDGenCriteriaCondition>();
            IDGenCriteriaCondition        objCriteriaCondition;

            if (!string.IsNullOrEmpty(objIDGenCriteriaInfo.CriteriaCode_PK))
            {
                string        vComText   = @"SELECT * FROM LS_IDGenCriteriaCondition 
                                    WHERE CompanyCode = " + pCompanyCode + " AND CriteriaCode='" + objIDGenCriteriaInfo.CriteriaCode_PK + "' And ActionType !='Delete'  ORDER BY SortOrder";
                SqlConnection connection = _supplierDbContext.GetConn();
                connection.Open();
                SqlDataReader dr;
                SqlCommand    objDbCommand = new SqlCommand(vComText.ToString(), connection);
                dr = objDbCommand.ExecuteReader();
                while (dr.Read())
                {
                    objCriteriaCondition                       = new IDGenCriteriaCondition();
                    objCriteriaCondition.IsNew                 = false;
                    objCriteriaCondition.UserCode              = dr["UserCode"].ToString();
                    objCriteriaCondition.CompanyCode_FK        = Convert.ToInt16(dr["CompanyCode"]);
                    objCriteriaCondition.ActionDate            = dr["ActionDate"].ToString();
                    objCriteriaCondition.ActionType            = dr["ActionType"].ToString();
                    objCriteriaCondition.ConditionCode_PK      = dr["ConditionCode"].ToString();
                    objCriteriaCondition.SortOrder             = Convert.ToInt16(dr["SortOrder"]);
                    objCriteriaCondition.ConditionText         = dr["ConditionText"].ToString();
                    objCriteriaCondition.ConditionType         = dr["ConditionType"].ToString();
                    objCriteriaCondition.ConditionValue        = dr["ConditionValue"].ToString();
                    objCriteriaCondition.ConditionValueLength  = Convert.ToInt16(dr["ConditionValueLength"]);
                    objCriteriaCondition.CriteriaCode_FK       = dr["CriteriaCode"].ToString();
                    objCriteriaCondition.AutoIncrementCriteria = dr["AutoIncrementCriteria"].ToString();
                    objCriteriaCondition.PaddingText           = dr["PaddingText"].ToString();
                    CriteriaConditionList.Add(objCriteriaCondition);
                }
                dr.Close();
            }
            return(CriteriaConditionList);
        }