private void ProcessFromRequest(eEditMode editMode)
        {
            switch (editMode)
            {
            case eEditMode.新增:
                CurrEditMode = editMode;
                ClearFromControls();
                HelperUtil.ControlReadOnly(pnlMain, false);

                chb_IsUse.Checked  = true;
                dbi_Sequence.Value = commonDAO.GetFuelKindSort();
                break;

            case eEditMode.修改:
                CurrEditMode = editMode;
                InitObjectInfo();
                HelperUtil.ControlReadOnly(pnlMain, false);
                break;

            case eEditMode.查看:
                CurrEditMode = editMode;
                InitObjectInfo();
                HelperUtil.ControlReadOnly(pnlMain, true);
                break;

            case eEditMode.除:
                CurrEditMode = editMode;
                DelTreeNode();
                ClearFromControls();
                HelperUtil.ControlReadOnly(pnlMain, true);
                break;
            }
        }
Beispiel #2
0
        /// <summary>
        /// 同步集团数据
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="thirdDber"></param>
        /// <param name="output"></param>
        private void DownLoadData(TableOrView entity, OracleDapperDber thirdDber, Action <string, eOutputType> output)
        {
            //同步集团数据
            string sbSearch = "select ";

            foreach (var item in entity.PropertySetDetails)
            {
                sbSearch += string.Format("{0},", item.Source);
            }

            sbSearch  = sbSearch.Trim(',');
            sbSearch += string.Format(" from {0} ", entity.Source);

            if (!string.IsNullOrWhiteSpace(entity.TimeIntervalProperty))
            {
                int    intervalValue = 7;
                string configValue   = commonDAO.GetAppletConfigString("数据同步智仁接口", "获取集团数据时间间隔(天)");
                if (!string.IsNullOrWhiteSpace(configValue))
                {
                    Int32.TryParse(configValue, out intervalValue);
                }
                DateTime startTime = DateTime.Now.AddDays(-intervalValue);

                sbSearch += string.Format(" where {0}>=to_date('{1}','yyyy-MM-dd hh24:mi:ss')", entity.TimeIntervalProperty, startTime.ToString("yyyy-MM-dd HH:mm:ss"));
            }

            DataTable dt = thirdDber.ExecuteDataTable(sbSearch);

            if (dt == null || dt.Rows.Count <= 0)
            {
                return;
            }

            Boolean ishavepk = entity.PropertySetDetails.Count(a => a.DesPrimaryKey != null && a.DesPrimaryKey.ToLower() == "true") > 0;

            foreach (DataRow item in dt.Rows)
            {
                //只有更新和新增操作
                string strChaXun = string.Format("select * from {0} where 1=1 ", entity.Destination);
                if (ishavepk)
                {
                    foreach (var pk in entity.PropertySetDetails.Where(a => a.DesPrimaryKey != null && a.DesPrimaryKey.ToLower() == "true"))
                    {
                        strChaXun += string.Format("and {0}='{1}' ", pk.Destination, item[pk.Source] == null ? "" : item[pk.Source].ToString());
                    }
                }
                else
                {
                    foreach (var pk in entity.PropertySetDetails)
                    {
                        strChaXun += string.Format("and {0}='{1}' ", pk.Destination, item[pk.Source] == null ? "" : item[pk.Source].ToString());
                    }
                }

                DataTable dtHaveData = SelfDber.ExecuteDataTable(strChaXun);
                if (dtHaveData == null || dtHaveData.Rows.Count <= 0)
                {
                    //新增
                    string insertSql = string.Format(@"insert into {0} (", entity.Destination);
                    string names     = "ID, CREATIONTIME, CREATORUSERID,LASTMODIFICATIONTIME,";
                    string values    = string.Format("'{0}', sysdate,1,sysdate,", Guid.NewGuid().ToString());

                    if (entity.Description == "矿点同步")
                    {
                        string code = commonDAO.GetMineNewChildCode("000");
                        if (!string.IsNullOrEmpty(code))
                        {
                            names  += "Code,";
                            values += "'" + code + "',";
                        }
                        names  += "Sort,";
                        values += commonDAO.GetMineSort() + ",";
                    }
                    else if (entity.Description == "煤种同步")
                    {
                        string code = commonDAO.GetFuelKindNewChildCode("000");
                        if (!string.IsNullOrEmpty(code))
                        {
                            names  += "Code,";
                            values += "'" + code + "',";
                        }
                        names  += "Sort,";
                        values += commonDAO.GetFuelKindSort() + ",";
                    }

                    if (!string.IsNullOrWhiteSpace(entity.IsSoftDelete) && entity.IsSoftDelete.ToLower() == "true")
                    {
                        names  += "ISDELETED,";
                        values += "0,";
                    }

                    if (!string.IsNullOrWhiteSpace(entity.TreeParentId))
                    {
                        names  += "parentid,";
                        values += string.Format("'{0}',", entity.TreeParentId);
                    }

                    foreach (var detail in entity.PropertySetDetails)
                    {
                        names  += string.Format("{0},", detail.Destination);
                        values += string.Format("'{0}',", item[detail.Source] == null ? "" : item[detail.Source].ToString());
                    }

                    if (!string.IsNullOrWhiteSpace(entity.IsHaveSyncTime) && entity.IsHaveSyncTime.ToLower() == "true")
                    {
                        names  += "SYNCTIME,";
                        values += "sysdate,";
                    }

                    insertSql += names.Trim(',') + ") values (" + values.Trim(',') + ")";
                    if (SelfDber.Execute(insertSql) > 0)
                    {
                        output(string.Format("接口取数【{0}】已同步,操作:新增", entity.Description), eOutputType.Normal);
                    }
                }
                else
                {
                    //更新
                    string updateSql = string.Format("update {0} set ", entity.Destination);

                    foreach (var detail in entity.PropertySetDetails)
                    {
                        updateSql += string.Format("{0}='{1}',", detail.Destination, item[detail.Source] == null ? "" : item[detail.Source].ToString());
                    }

                    if (!string.IsNullOrWhiteSpace(entity.IsHaveSyncTime) && entity.IsHaveSyncTime.ToLower() == "true")
                    {
                        updateSql += "SYNCTIME=sysdate,";
                    }

                    updateSql = updateSql.Trim(',') + string.Format(" where id='{0}'", dtHaveData.Rows[0]["ID"].ToString());
                    if (SelfDber.Execute(updateSql) > 0)
                    {
                        output(string.Format("接口取数【{0}】已同步,操作:更新", entity.Description), eOutputType.Normal);
                    }
                }
            }
        }