예제 #1
0
        private void AddFieldValue(changeStatus nStatus, string sFld, Dictionary <string, object> row, EmployeeInfo emp, string HistoryForeignKey, ref string sSql, ref string sValList)
        {
            string sVal = QuoteNull;
            object val  = null;

            if (row.ContainsKey(sFld))
            {
                val = row[sFld];
            }
            else if (nStatus == changeStatus.AddHistory)
            {
                if (sSql.Length > 0)
                {
                    sSql += ",";
                }
                sSql += QuoteField(sFld);

                if (sValList.Length > 0)
                {
                    sValList += ",";
                }

                if (sFld.Equals("Update_Time", StringComparison.OrdinalIgnoreCase) ||
                    sFld.Equals("Create_Time", StringComparison.OrdinalIgnoreCase))
                {
                    sValList += FuncCurrentTimestamp;
                }
                else
                {
                    sValList += QuoteField(sFld);
                }

                return;
            }
            else if (nStatus == changeStatus.Where)//条件语句不关心没有给值的字段
            {
                return;
            }

            if (val != null && val.GetType() == typeof(string))
            {
                if (Cvt.IsNumerical(val))
                {
                    sVal = val.ToString();
                }
                else
                {
                    sVal = QuoteValue(val.ToString());
                }
            }
            else if (sFld.Equals("_Employee_Update", StringComparison.OrdinalIgnoreCase))
            {
                if (nStatus == changeStatus.Where)
                {
                    return;
                }

                sVal = emp._Employee.ToString();
            }
            else if (sFld.Equals("_Site", StringComparison.OrdinalIgnoreCase))
            {
                sVal = emp._Site_Working.ToString();
            }
            else if (sFld.Equals("_Project", StringComparison.OrdinalIgnoreCase))
            {
                sVal = emp._Project_Working.ToString();
            }
            else if (sFld.Equals(HistoryForeignKey, StringComparison.OrdinalIgnoreCase) && nStatus == changeStatus.Add)
            {
                sVal = "@nLastPrimaryID";
            }
            else
            {
                try
                {
                    sVal = Convert.ToInt32(val).ToString();
                }
                catch (Exception)
                {
                }
            }


            if (nStatus == changeStatus.Add)
            {
                if (sFld.Equals("Update_Time", StringComparison.OrdinalIgnoreCase) == false &&
                    sFld.Equals("Create_Time", StringComparison.OrdinalIgnoreCase) == false)
                {
                    if (sSql.Length > 0)
                    {
                        sSql += ",";
                    }
                    sSql += QuoteField(sFld);

                    if (sValList.Length > 0)
                    {
                        sValList += ",";
                    }
                    sValList += sVal;
                }
            }
            else if (nStatus == changeStatus.Update)
            {
                if (sSql.Length > 0)
                {
                    sSql += ",";
                }

                if (sFld.Equals("Update_Time", StringComparison.OrdinalIgnoreCase) ||
                    sFld.Equals("Create_Time", StringComparison.OrdinalIgnoreCase))
                {
                    sSql += QuoteField(sFld) + "=" + FuncCurrentTimestamp;
                }
                else
                {
                    sSql += QuoteField(sFld) + "=" + sVal;
                }
            }
            else if (nStatus == changeStatus.Where)
            {
                if (sSql.Length > 0)
                {
                    sSql += " AND ";
                }

                if (sFld.Equals("Update_Time", StringComparison.OrdinalIgnoreCase) ||
                    sFld.Equals("Create_Time", StringComparison.OrdinalIgnoreCase))
                {
                    return;//条件语句不关心创建时间或更新时间
                }
                else
                {
                    sSql += QuoteField(sFld) + "=" + sVal;
                }
            }
            else if (nStatus == changeStatus.AddHistory)
            {
                if (sSql.Length > 0)
                {
                    sSql += ",";
                }
                sSql += QuoteField(sFld);

                if (sValList.Length > 0)
                {
                    sValList += ",";
                }

                if (sFld.Equals("Update_Time", StringComparison.OrdinalIgnoreCase) ||
                    sFld.Equals("Create_Time", StringComparison.OrdinalIgnoreCase))
                {
                    sValList += FuncCurrentTimestamp;
                }
                else
                {
                    sValList += sVal;
                }
            }
        }
예제 #2
0
        private void AddFieldValue(changeStatus nStatus, Field Fld, Dictionary <string, object> row, EmployeeInfo emp, string HistoryForeignKey, ref string sSql, ref string sValList)
        {
            //if (Fld.editor == Editor.none)
            //    return;

            string sVal = QuoteNull;
            object val  = null;

            if ((Fld.editor & Editor.order) != Editor.none)
            {
                val = row["__index"];
            }
            else if (row.ContainsKey(Fld) && row[Fld] != null)
            {
                val = row[Fld];
                if (Fld.type == FieldType.Int && Cvt.IsNumerical(val) == false)
                {
                    val = null;
                }
            }
            else if (nStatus == changeStatus.AddHistory)
            {
                if (sSql.Length > 0)
                {
                    sSql += ",";
                }
                sSql += QuoteField(Fld);

                if (sValList.Length > 0)
                {
                    sValList += ",";
                }

                if (Fld.name.Equals("Update_Time", StringComparison.OrdinalIgnoreCase) ||
                    Fld.name.Equals("Create_Time", StringComparison.OrdinalIgnoreCase))
                {
                    sValList += FuncCurrentTimestamp;
                }
                else
                {
                    sValList += QuoteField(Fld);
                }

                return;
            }
            else if (nStatus == changeStatus.Where)//条件语句不关心没有给值的字段
            {
                return;
            }

            if (val != null && val.GetType() == typeof(string))
            {
                if (Cvt.IsNumerical(val))
                {
                    sVal = val.ToString();
                }
                else
                {
                    sVal = QuoteValue(val.ToString());
                }
            }
            else if (Fld.name.Equals("_Employee_Update", StringComparison.OrdinalIgnoreCase))
            {
                if (nStatus == changeStatus.Where)
                {
                    return;
                }

                sVal = emp._Employee.ToString();
            }
            //else if (val == null && Fld.name.Equals("_Site", StringComparison.OrdinalIgnoreCase))
            //{
            //    sVal = emp._Site_Working.ToString();
            //}
            //else if (val == null && Fld.name.Equals("_Project", StringComparison.OrdinalIgnoreCase))
            //{
            //    sVal = emp._Project_Working.ToString();
            //}
            else if (Fld.name.Equals(HistoryForeignKey, StringComparison.OrdinalIgnoreCase) && nStatus == changeStatus.Add)
            {
                sVal = "@nLastPrimaryID";
            }
            else
            {
                try
                {
                    if (val != null)
                    {
                        sVal = Convert.ToInt64(val).ToString();
                    }
                    else if (nStatus != changeStatus.AddHistory)
                    {
                        return;
                    }
                }
                catch (Exception)
                {
                }
            }


            if (nStatus == changeStatus.Add)
            {
                if (Fld.name.Equals("Update_Time", StringComparison.OrdinalIgnoreCase) == false &&
                    Fld.name.Equals("Create_Time", StringComparison.OrdinalIgnoreCase) == false)
                {
                    if (sSql.Length > 0)
                    {
                        sSql += ",";
                    }
                    sSql += QuoteField(Fld);

                    if (sValList.Length > 0)
                    {
                        sValList += ",";
                    }
                    sValList += sVal;
                }
            }
            else if (nStatus == changeStatus.Update)
            {
                if (sSql.Length > 0)
                {
                    sSql += ",";
                }

                if (Fld.name.Equals("Update_Time", StringComparison.OrdinalIgnoreCase) ||
                    Fld.name.Equals("Create_Time", StringComparison.OrdinalIgnoreCase))
                {
                    sSql += QuoteField(Fld) + "=" + FuncCurrentTimestamp;
                }
                else
                {
                    sSql += QuoteField(Fld) + "=" + sVal;
                }
            }
            else if (nStatus == changeStatus.Where)
            {
                if (Fld.name.Equals("Update_Time", StringComparison.OrdinalIgnoreCase) ||
                    Fld.name.Equals("Create_Time", StringComparison.OrdinalIgnoreCase))
                {
                    return;//条件语句不关心创建时间或更新时间
                }
                else
                {
                    if (sSql.Length > 0)
                    {
                        sSql += " AND ";
                    }
                    sSql += QuoteField(Fld) + "=" + sVal;
                }
            }
            else if (nStatus == changeStatus.AddHistory)
            {
                if (sSql.Length > 0)
                {
                    sSql += ",";
                }
                sSql += QuoteField(Fld);

                if (sValList.Length > 0)
                {
                    sValList += ",";
                }

                if (Fld.name.Equals("Update_Time", StringComparison.OrdinalIgnoreCase) ||
                    Fld.name.Equals("Create_Time", StringComparison.OrdinalIgnoreCase))
                {
                    sValList += FuncCurrentTimestamp;
                }
                else
                {
                    sValList += sVal;
                }
            }
        }