0001 function buildConditions(varargin)
0002
0003
0004
0005
0006
0007
0008 ALLHEIGHT = 25;
0009 fontsize = 10;
0010
0011 panel = varargin{1};
0012 Ppos = get(panel, 'Position');
0013 mainfig = findobj('Tag', 'LTPDARepomainfig');
0014 Nc = getappdata(mainfig, 'Nconditions');
0015 conn = getappdata(mainfig, 'connection');
0016 Gproperties = getappdata(mainfig, 'Gproperties');
0017
0018
0019 tableSelected = getappdata(mainfig, 'tableSelected');
0020
0021 fieldList = findobj('Tag', 'fieldsList');
0022 fselection = get(fieldList, 'Value');
0023
0024 fieldOrder = findobj('Tag', 'fieldOrderBy');
0025 forder = get(fieldOrder, 'Value');
0026
0027 sortDir = findobj('Tag', 'sortDir');
0028 sort = get(sortDir, 'Value');
0029
0030 conds = cell(Nc,4);
0031 for k=1:Nc
0032 pmh = findobj('Tag', sprintf('c%02dField', k));
0033 conds{k,1} = get(pmh, 'Value');
0034 pmh = findobj('Tag', sprintf('c%02dCondition', k));
0035 conds{k,2} = get(pmh, 'Value');
0036 pmh = findobj('Tag', sprintf('c%02dValue', k));
0037 conds{k,3} = get(pmh, 'String');
0038 if k<Nc
0039 pmh = findobj('Tag', sprintf('c%02dCompound', k));
0040 conds{k,4} = get(pmh, 'Value');
0041 end
0042 end
0043
0044 delete(get(panel, 'Children'))
0045 drawnow
0046
0047
0048
0049
0050 tables = getTables(conn);
0051 Sleft = 10;
0052 Sheight = ALLHEIGHT;
0053 Sbottom = Ppos(2) + Ppos(4) - 20 - Sheight;
0054 Swidth = 50;
0055
0056 sth = uicontrol(panel,'Style','text',...
0057 'String', 'From',...
0058 'Fontsize', fontsize,...
0059 'BackgroundColor', Gproperties.Gcol,...
0060 'HorizontalAlignment', 'left',...
0061 'Position',[Sleft Sbottom Swidth Sheight]);
0062
0063 Sleft = Sleft + Swidth + 10;
0064 Swidth = 150;
0065 pmh = uicontrol(panel,'Style','popupmenu',...
0066 'String', tables,...
0067 'Fontsize', fontsize,...
0068 'BackgroundColor', Gproperties.Gcol,...
0069 'Value', 1,...
0070 'Position',[Sleft Sbottom Swidth Sheight],...
0071 'Tag', 'tableSelect');
0072 if ~isempty(tableSelected)
0073 set(pmh, 'Value', tableSelected);
0074 end
0075 set(pmh, 'Callback', {'cb_tableSelect', pmh, mainfig});
0076
0077
0078
0079
0080
0081 fields = getFields(conn);
0082 pos = get(pmh, 'Position');
0083 Sleft = 10;
0084 Sheight = ALLHEIGHT;
0085 Sbottom = pos(2) + pos(4) - 40 - Sheight;
0086 Swidth = 50;
0087
0088 sth = uicontrol(panel,'Style','text',...
0089 'String', 'Select',...
0090 'Fontsize', fontsize,...
0091 'BackgroundColor', Gproperties.Gcol,...
0092 'HorizontalAlignment', 'left',...
0093 'Position',[Sleft Sbottom Swidth Sheight]);
0094
0095 Sleft = Sleft + Swidth + 10;
0096 Swidth = 150;
0097 Sheight = 200;
0098 Sbottom = pos(2) + pos(4) - 40 - Sheight;
0099 lbh = uicontrol(panel,'Style','listbox',...
0100 'String', fields,...
0101 'Value',1,...
0102 'BackgroundColor', 'w',...
0103 'Fontsize', fontsize,...
0104 'Max', 1000,...
0105 'Position',[Sleft Sbottom Swidth Sheight],...
0106 'Tag', 'fieldsList');
0107
0108 set(lbh, 'Callback', {'cb_fieldSelect', pmh, mainfig});
0109 if ~isempty(fselection)
0110 set(lbh, 'Value', fselection);
0111 end
0112
0113
0114
0115 listpos = get(lbh, 'Position');
0116 Sleft = 10;
0117 Sheight = 40;
0118 Sbottom = Ppos(2) + 60;
0119 Swidth = 60;
0120
0121 sth = uicontrol(panel,'Style','text',...
0122 'String', 'Query:',...
0123 'Fontsize', fontsize,...
0124 'Max', 5,...
0125 'BackgroundColor', Gproperties.Gcol,...
0126 'HorizontalAlignment', 'left',...
0127 'Position', [Sleft Sbottom Swidth Sheight]);
0128
0129 Sleft = 10 + Swidth + 20;
0130 Swidth = 650;
0131 Sheight = 100;
0132 Sbottom = Ppos(2) + 60;
0133 sth = uicontrol(panel,'Style','edit',...
0134 'String', '',...
0135 'Fontsize', fontsize,...
0136 'Max', 5,...
0137 'BackgroundColor', 'w',...
0138 'HorizontalAlignment', 'left',...
0139 'Position', [Sleft Sbottom Swidth Sheight],...
0140 'Tag', 'queryDisplayTxt');
0141
0142
0143
0144
0145
0146
0147 conditions = {'=', '<>', '<=', '>=', '<', '>', 'like', 'not like', 'is'};
0148 compounds = {'AND', 'OR', 'XOR'};
0149
0150 pos = get(lbh, 'Position');
0151 Sleft = pos(1) + pos(3) + 20;
0152 Sheight = ALLHEIGHT;
0153 Sbottom = Ppos(2) + Ppos(4) - 25 - Sheight;
0154 Swidth = 50;
0155
0156 sth = uicontrol(panel,'Style','text',...
0157 'String', 'Where',...
0158 'Fontsize', fontsize,...
0159 'BackgroundColor', Gproperties.Gcol,...
0160 'HorizontalAlignment', 'left',...
0161 'Position',[Sleft Sbottom Swidth Sheight]);
0162
0163
0164
0165 Cheight = ALLHEIGHT;
0166 STEP = 5;
0167 for k=1:Nc
0168 Cleft = pos(1) + pos(3) + 10 + STEP;
0169 Cbottom = pos(2) + pos(4) -25 - (k-1)*(Cheight+10);
0170 Cwidth = 150;
0171
0172 pmh = uicontrol(panel,'Style','popupmenu',...
0173 'String', fields,...
0174 'Fontsize', fontsize,...
0175 'BackgroundColor', 'w', ...
0176 'Value',1,'Position',[Cleft Cbottom Cwidth Cheight],...
0177 'Tag', sprintf('c%02dField', k));
0178 set(pmh, 'Callback', 'buildquery');
0179 if ~isempty(conds{k,1})
0180 set(pmh, 'Value', conds{k,1});
0181 end
0182
0183
0184 Cleft = Cleft + Cwidth + STEP;
0185 Cwidth = 100;
0186 pmh = uicontrol(panel,'Style','popupmenu',...
0187 'String', conditions,...
0188 'Fontsize', fontsize,...
0189 'BackgroundColor', 'w',...
0190 'Value',1,'Position',[Cleft Cbottom Cwidth Cheight],...
0191 'Tag', sprintf('c%02dCondition', k));
0192 set(pmh, 'Callback', 'buildquery');
0193 if ~isempty(conds{k,2})
0194 set(pmh, 'Value', conds{k,2});
0195 end
0196
0197
0198 Cleft = Cleft + Cwidth + STEP;
0199 Cwidth = 150;
0200 sth = uicontrol(panel,'Style','edit',...
0201 'String','',...
0202 'Fontsize', fontsize,...
0203 'BackgroundColor', 'w',...
0204 'HorizontalAlignment', 'left',...
0205 'Position',[Cleft Cbottom Cwidth Cheight],...
0206 'Tag', sprintf('c%02dValue', k));
0207 set(sth, 'Callback', 'buildquery');
0208 if ~isempty(conds{k,3})
0209 set(sth, 'String', conds{k,3});
0210 end
0211
0212
0213 if k<Nc
0214 Cleft = Cleft + Cwidth + STEP;
0215 Cwidth = 80;
0216 pmh = uicontrol(panel,'Style','popupmenu',...
0217 'String', compounds,...
0218 'Fontsize', 10,...
0219 'BackgroundColor', Gproperties.Gcol,...
0220 'Value',1,'Position',[Cleft Cbottom Cwidth Cheight],...
0221 'Tag', sprintf('c%02dCompound', k));
0222 set(pmh, 'Callback', 'buildquery');
0223 if ~isempty(conds{k,4})
0224 set(pmh, 'Value', conds{k,4});
0225 end
0226 end
0227
0228 end
0229
0230
0231
0232 k = Nc+1;
0233 Bbottom = pos(2) + pos(4) -25 - (k-1)*(Cheight+10);
0234 Bleft = pos(1) + pos(3) + 20;
0235 Bheight = ALLHEIGHT;
0236 Bwidth = 20;
0237 pbh = uicontrol(panel,'Style','pushbutton','Fontsize', fontsize, 'String','+',...
0238 'Position',[Bleft Bbottom Bwidth Bheight ],...
0239 'Tag', 'condPlusBtn');
0240 set(pbh, 'Callback', {'cb_condPlusBtn', pbh, panel, mainfig});
0241 Bleft = pos(1) + pos(3) + 20 + 30;
0242 pbh = uicontrol(panel,'Style','pushbutton','Fontsize', fontsize, 'String','-',...
0243 'Position',[Bleft Bbottom Bwidth Bheight ],...
0244 'Tag', 'condSubtractBtn');
0245 set(pbh, 'Callback', {'cb_condSubtractBtn', pbh, panel, mainfig});
0246
0247
0248
0249
0250 k = Nc + 2;
0251 Sleft = pos(1) + pos(3) + 20;
0252 Sheight = ALLHEIGHT;
0253 Swidth = 60;
0254 Sbottom = pos(2) + pos(4) - 25 -(k-1)*(Cheight+10);
0255 sth = uicontrol(panel,'Style','text',...
0256 'String', 'Order by',...
0257 'Fontsize', fontsize,...
0258 'BackgroundColor', Gproperties.Gcol,...
0259 'HorizontalAlignment', 'left',...
0260 'Position',[Sleft Sbottom Swidth Sheight]);
0261
0262
0263 Sleft = pos(1) + pos(3) + 20 + Swidth + 20;
0264 Swidth = 100;
0265 pmh = uicontrol(panel,'Style','popupmenu',...
0266 'String', fields,...
0267 'Fontsize', fontsize,...
0268 'BackgroundColor', Gproperties.Gcol,...
0269 'Value',1,'Position',[Sleft Sbottom Swidth Sheight],...
0270 'Tag', 'fieldOrderBy');
0271 set(pmh, 'Callback', 'buildquery');
0272 if ~isempty(forder)
0273 set(pmh, 'Value', forder);
0274 end
0275
0276
0277 Sleft = Sleft + 20 + Swidth;
0278 Swidth = 100;
0279 pmh = uicontrol(panel,'Style','popupmenu',...
0280 'String', {'DESC', 'ASC'},...
0281 'Fontsize', fontsize,...
0282 'BackgroundColor', Gproperties.Gcol,...
0283 'Value',1,'Position',[Sleft Sbottom Swidth Sheight],...
0284 'Tag', 'sortDir');
0285 set(pmh, 'Callback', 'buildquery');
0286 if ~isempty(sort)
0287 set(pmh, 'Value', sort);
0288 end
0289
0290
0291
0292
0293
0294 k = Nc + 3;
0295 Sleft = Ppos(1) + 10;
0296 Sheight = ALLHEIGHT;
0297 Swidth = 100;
0298 Sbottom = Ppos(2) + 10;
0299 pbh = uicontrol(panel,'Style','pushbutton','String','Execute query',...
0300 'Position',[Sleft Sbottom Swidth Sheight ],...
0301 'Tag', 'refreshListBtn');
0302 set(pbh, 'Callback', {'cb_executeQuery', pbh, mainfig});
0303
0304
0305
0306 buildquery()
0307
0308 drawnow
0309