白桦的天空

第一次的心动,永远的心痛!
  首页  :: 新随笔  :: 联系 :: 管理

常用函数

Posted on 2005-06-01 15:18  白桦的天空  阅读(482)  评论(1编辑  收藏  举报
//同时修改主从表、或多表的时候,对从表的更新模式做调整
        protected override void SetUpdateMode(SQLTableInfo info, ref UpdateMode mode)
        
{
           
if (info.TableName == fFaultTableInfo.TableName || info.TableName==fProductTableInfo.TableName)
            mode 
= UpdateMode.Merge;
        }

//代码表
        protected override void AddCodeTable(StringCollection codeTables)
        
{
           
base.AddCodeTable(codeTables);    
           codeTables.Add(
"CD_SELL_AREA");        //销售范围
         }
        

//数据权限
        protected override void SetSubFunctionKey(PageStyle style, ref object subKey)
        
{
            
base.SetSubFunctionKey (style, ref subKey);
        }


//主从表内容
        protected override void AddDetailListTable(StringCollection detailTables, StringCollection detailCodeTables, 

object key)
        
{
            
//登录的用户信息
            string UsersSql = string.Format("SELECT DISTINCT USER_ID CODE_VALUE,USER_NAME CODE_NAME FROM UR_USERS 

WHERE (USER_ID IN(SELECT HP_CREATE_ID FROM EB_HOSPITAL WHERE HP_ID 
= '{0}')) OR (USER_ID IN(SELECT HP_UPDATE_ID FROM 

EB_HOSPITAL WHERE HP_ID 
= '{0}'))",key.ToString());
            BrowseInfo.ChangeSql(UsersSql,"UR_USERS",DbConnection,this);

            
//医院信息
            string HospitalSql = string.Format("select * from EB_HOSPITAL EB_HOSPITAL_DETAIL where HP_PARENT_ID = 

'{0}'",key.ToString());
            BrowseInfo.ChangeSql(HospitalSql,"EB_HOSPITAL_DETAIL",DbConnection,this);
            
//人员信息
            string PersonSql = string.Format("select EB_PERSON_INFO.* from EB_PERSON_INFO INNER JOIN EB_HOSPITAL 

ON PI_HP_ID 
= HP_ID AND HP_ID = '{0}'",key.ToString());
            BrowseInfo.ChangeSql(PersonSql,"EB_PERSON_INFO",DbConnection,this);
            
//保修卡信息            
            string CardSql = string.Format("SELECT EB_GUARANTEE_CARD.*, EB_PRODUCT_OUT.* FROM EB_HOSPITAL INNER 

JOIN EB_GUARANTEE_CARD ON  EB_HOSPITAL.HP_ID 
= EB_GUARANTEE_CARD.GC_HP_ID AND EB_HOSPITAL.HP_ID ='{0}' INNER JOIN 

EB_PRODUCT_OUT ON  EB_GUARANTEE_CARD.GC_PC_CODE 
= EB_PRODUCT_OUT.PO_PC_CODE AND       EB_GUARANTEE_CARD.GC_BAR_CODE = 

EB_PRODUCT_OUT.PO_BAR_CODE
",key.ToString());            

            BrowseInfo.ChangeSql(CardSql,
"EB_GUARANTEE_CARD",DbConnection,this);
            
            
base.AddDetailListTable(detailTables, detailCodeTables, key);
        }




//多表的修改    
protected override void FillUpdateTables(object key,PageStyle style)
        
{            
            TableInfo.SetKeyValueAndFill(DbConnection,key,
this);
            
            
            fCFTableInfo.FillData(
this,DbConnection,string.Format("WHERE CF_RSC_ID = {0}",key.ToString()));
            fCSFTableInfo.FillData(
this.DbConnection,string.Format("WHERE CSF_RSC_ID = {0}",key.ToString()));
            
//工作报告信息            
            string ReportSql = string.Format("select SR_ID AS CODE_VALUE,SR_CODE AS CODE_NAME from EB_SERVICE 

where SR_ID
='{0}'",Tables[TableName].Rows[0]["RSC_SR_ID"].ToString());
            BrowseInfo.ChangeSql(ReportSql,"EB_SERVICE",DbConnection,this);
            MidSearchFields.FillDataSet(
this);

        }
    

//夺标的修改删除
protected override void FillUpdateTables(DataSet postDataSet)
        
{
            
//从表内容
             string key = postDataSet.Tables[TableName].Rows[0][KeyFields].ToString();            
            TableInfo.SetKeyValueAndFill(DbConnection,key,
this);
            fCFTableInfo.FillData(DbConnection,
string.Format("WHERE CF_RSC_ID = '{0}'",key));
           fCSFTableInfo.FillData(DbConnection,
string.Format("WHERE CSF_RSC_ID = '{0}'",key));
            
//将服务工作报考的名称替换为ID PostDataSet.Tables                
            DataTable fTable =PostDataSet.Tables[TableName];
            
string sql = string.Format("Select SR_ID from EB_SERVICE where 

SR_CODE
='{0}'",fTable.Rows[0]["RSC_SR_ID"]);
            string fsr_id=DataSetUtil.ExecuteScalar(sql,DbConnection).ToString();
            
//替换结束
            if(fsr_id == null || fsr_id == string.Empty)
            
{
                ErrorObjects.Add(
new ErrorObject("EB_REPAIR_SERVICE_CONTRACT" , "RSC_SR_ID" , "输入服务单号不

正确
",0));
                fTable.Rows[0]["RSC_SR_ID"]= DBNull.Value;
            }

            
else
            
{                
                fTable.Rows[
0]["RSC_SR_ID"]=Convert.ToInt32(fsr_id);
            }

            CheckPostData(PostDataSet,fCFTableInfo);
            CheckPostData(PostDataSet,fCSFTableInfo);
            
        }

        
public void CheckPostData(DataSet postData,SQLTableInfo fDtailTableInfo)    
        
{
                DataTable table 
= postData.Tables[fDtailTableInfo.TableName] ;
            
            
if(table == null)
            
{
                TableInfoCollection.Remove(fDtailTableInfo);
                
return;
            }
    
            
if (postData.Tables.Contains(fDtailTableInfo.TableName))
            
{
                
                
int i = 1 ;                
                
for (int j=table.Rows.Count - 1; j>=0--j, ++i)
                
{
                    DataRow row 
= table.Rows[j] ;
                    
if (row[fDtailTableInfo.KeyFields].ToString() == string.Empty)
                        row[fDtailTableInfo.KeyFields] 
= -i ;

                }

            }

        }

                    

        
protected override void CommittingData()
        
{
            
base.CommittingData ();
            
if(this.CurrentPageStyle == PageStyle.Update && this.PostDataSet.Tables[fCFTableInfo.TableName] == 

null && 
                Tables[fCFTableInfo.TableName] 
!= null && 
                Tables[fCFTableInfo.TableName].Rows.Count 
> 0)
            
{
                fCFTableInfo.SetCommands(AdapterCommand.Delete,DbConnection);
                
foreach(DataRow row in Tables[fCFTableInfo.TableName].Rows)
                
{
                    row.Delete();
                }

                TableInfoCollection.Add(fCFTableInfo);
            }

            
if(this.CurrentPageStyle == PageStyle.Update && this.PostDataSet.Tables[fCSFTableInfo.TableName] == 

null && 
                Tables[fCSFTableInfo.TableName] 
!= null && 
                Tables[fCSFTableInfo.TableName].Rows.Count 
> 0)
            
{
                fCSFTableInfo.SetCommands(AdapterCommand.Delete,DbConnection);
                
foreach(DataRow row in Tables[fCSFTableInfo.TableName].Rows)
                
{
                    row.Delete();
                }

                TableInfoCollection.Add(fCSFTableInfo);
            }

        }