富文本编辑器图片上传失败的BUG解决:IndexError:list index out of range

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_43162402/article/details/83662380

富文本编辑器图片上传失败的BUG解决

问题原因

我们将通过Django上传的图片保存到了FastDFS中,而保存在FastDFS中的文件名没有后缀名(.png/.jpg/.jif),而ckeditor在处理上传的文件名按照有后缀名来处理,所以会出现bug错误
bug

解决方法

找到虚拟环境目录中的ckeditor_uploader/views.py文件,如

~/.virtualenvs/meiduo/lib/python3.5/site-packages/ckeditor_uploader/views.py

或者直接点击报错的最后一行进入源文件进行如下修改:
method

展开阅读全文

求助:IndexError: list index out of range

08-21

使用Spyder(python 3.6)代码为:rn#!/usr/bin/env python3rnimport sysrnrnfrom xlrd import open_workbookrnfrom xlwt import Workbookrnrninput_file = sys.argv[1]rnoutput_file = sys.argv[2]rnrnoutput_workbook = Workbook()rnoutput_worksheet = output_workbook.add_sheet('jan_2013_output')rnrnwith open_workbook(input_file) as workbook:rn worksheet = workbook.sheet_by_name('january_2013')rn for row_index in range(worksheet.nrows):rn for column_index in range(worksheet.ncols):rn output_worksheet.write(row_index, column_index, worksheet.cell_value(row_index, column_index))rnoutput_workbook.save(output_file)rnrn执行:python 2excel_parsing_and_write.py sale_2013 Loutput.xlsrnrn出现问题,输出;rnPython 3.6.2 |Anaconda custom (64-bit)| (default, Sep 19 2017, 08:03:39) [MSC v.1900 64 bit (AMD64)]rnType "copyright", "credits" or "license" for more information.rnrnIPython 6.1.0 -- An enhanced Interactive Python.rnrnrnrnrunfile('C:/LearnPython/excel/2excel_parsing_and_write.py', args='sales_2013.xlsx', wdir='C:/LearnPython/excel')rnTraceback (most recent call last):rnrn File "", line 1, in rn runfile('C:/LearnPython/excel/2excel_parsing_and_write.py', args='sales_2013.xlsx', wdir='C:/LearnPython/excel')rnrn File "H:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 710, in runfilern execfile(filename, namespace)rnrn File "H:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 101, in execfilern exec(compile(f.read(), filename, 'exec'), namespace)rnrn File "C:/LearnPython/excel/2excel_parsing_and_write.py", line 8, in rn output_file = sys.argv[2]rnrnIndexError: list index out of range 论坛

报错:sys.argv[1] IndexError: list index out of range

05-26

运行时报错:firstFolder = sys.argv[1]rnIndexError: list index out of rangern怎么回事?rnrn```rnimport numpy as nprnimport cv2rnimport sysrnfrom matplotlib import pyplot as pltrnrn# img = cv2.imread('logo.png',0)rn# # Initiate ORB detectorrn# orb = cv2.ORB_create()rn# # find the keypoints with ORBrn# kp = orb.detect(img,None)rn# # compute the descriptors with ORBrn# kp, des = orb.compute(img, kp)rn# # draw only keypoints location,not size and orientationrn# img2 = cv2.drawKeypoints(img, kp, None, color=(0,255,0), flags=0)rn# plt.imshow(img2), plt.show()rnrnfrom os import listdirrnfrom os.path import isfile, joinrnrnrnclass Application:rn def __init__(self, extractor, detector):rn self.extractor = extractorrn self.detector = detectorrnrn def train_vocabulary(self, file_list, vocabulary_size):rn kmeans_trainer = cv2.BOWKMeansTrainer(vocabulary_size)rn for path_to_image in file_list:rn img = cv2.imread(path_to_image, 0)rn kp, des = self.detector.detectAndCompute(img, None)rn kmeans_trainer.add(des)rn return kmeans_trainer.cluster()rnrn def extract_features_from_image(self, file_name):rn image = cv2.imread(file_name)rn return self.extractor.compute(image, self.detector.detect(image))rnrn def extract_train_data(self, file_list, category):rn train_data, train_responses = [], []rn for path_to_file in file_list:rn train_data.extend(self.extract_features_from_image(path_to_file))rn train_responses.append(category)rn return train_data, train_responsesrnrn def train_classifier(self, data, responses):rn n_trees = 200rn max_depth = 10rn model = cv2.ml.RTrees_create()rn eps = 1rn criteria = (cv2.TERM_CRITERIA_MAX_ITER, n_trees, eps)rn model.setTermCriteria(criteria)rn model.setMaxDepth(max_depth)rn model.train(np.array(data), cv2.ml.ROW_SAMPLE, np.array(responses))rn return modelrnrn def predict(self, file_name):rn features = self.extract_features_from_image(file_name)rn return self.classifier.predict(features)[0]rnrn def train(self, files_array, vocabulary_size=12):rn all_categories = []rn for category in files_array:rn all_categories += categoryrnrn vocabulary = self.train_vocabulary(all_categories, vocabulary_size)rn self.extractor.setVocabulary(vocabulary)rnrn data = []rn responses = []rn for id in range(len(files_array)):rn data_temp, responses_temp = self.extract_train_data(files_array[id], id)rn data += data_temprn responses += responses_temprnrn self.classifier = self.train_classifier(data, responses)rnrn def error(self, file_list, category):rn responses = np.array([self.predict(file) for file in file_list])rn _responses = np.array([category for _ in range(len(responses))])rn return 1 - np.sum(responses == _responses) / len(responses)rnrnrndef get_images_from_folder(folder):rn return ["%s/%s" % (folder, f) for f in listdir(folder) if isfile(join(folder, f))]rnrnrndef start(folders, detector_type, voc_size, train_proportion):rn if detector_type == "SIFT":rn # "Scale Invariant Feature Transform"rn extract = cv2.xfeatures2d.SIFT_create()rn detector = cv2.xfeatures2d.SIFT_create()rn else:rn # "Speeded up Robust Features"rn extract = cv2.xfeatures2d.SURF_create()rn detector = cv2.xfeatures2d.SURF_create()rn flann_params = dict(algorithm=1, trees=5)rn matcher = cv2.FlannBasedMatcher(flann_params, )rn extractor = cv2.BOWImgDescriptorExtractor(extract, matcher)rnrn train = []rn test = []rn for folder in folders:rn images = get_images_from_folder(folder)rn np.random.shuffle(images)rnrn slice = int(len(images) * train_proportion)rn train_images = images[0:slice]rn test_images = images[slice:]rn train.append(train_images)rn test.append(test_images)rnrn app = Application(extractor, detector)rn app.train(train, voc_size)rnrn total_error = 0.0rnrn for id in range(len(test)):rn print(app.error(train[id], id))rn test_error = app.error(test[id], id)rn print(test_error)rn print("---------")rn total_error = total_error + test_errorrnrn total_error = total_error / float(len(test))rn print("Total error = %f" % total_error)rnrnrnfirstFolder = sys.argv[1]rnsecondFolder = sys.argv[2]rndetectorType = sys.argv[3]rnvocSize = int(sys.argv[4])rntrainProportion = float(sys.argv[5])rnrnstart([firstFolder, secondFolder], detectorType, vocSize, trainProportion)rnrnrn``` 问答

Row index out of range问题

06-18

public class Table1 extends JFramern String rid[] = new String[100];rn int count = 0;rn /*rn * public static void main(String a[]) new Table1(); rn */rn rn public void center(JFrame frame) rn double x = frame.getWidth(); // 居中困难rn double y = frame.getHeight();rn Toolkit kit = Toolkit.getDefaultToolkit();rn Dimension screenSize = kit.getScreenSize();rn double xx = screenSize.getWidth();rn double yy = screenSize.getHeight();rn frame.setLocation((int) (xx / 2 - x / 2), (int) (yy / 2 - y / 2));rn rn public Table1() rn JPanel zuida = new JPanel(new BorderLayout(0, 10));rn JPanel jp1 = fangzi();rn JPanel jp2 = dingdan();rn jp2.setBorder(BorderFactory.createTitledBorder("订单信息"));rn JTabbedPane tp = new JTabbedPane();rn tp.addTab("房间预定", jp1);rn tp.addTab("订单信息", jp2);rn // zuida.add(jp1);rn zuida.add("North", tp);rn JFrame frame = new JFrame("酒店");rn frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);rn //zuida.setBackground(new Color(102,204,255)); 设置背景颜色rn zuida.setBorder(new EmptyBorder(5, 5, 5, 5));rn frame.setContentPane(zuida);rn frame.setVisible(true);rn frame.pack();rn center(frame);rn System.out.println("123");rn // frame.setLocationRelativeTo(null);//这个也是居中的方法rn rn JPanel fangzi() rn JTable jiu = jiudian();rn JTable table = order();rn JScrollPane pane = new JScrollPane(jiu); // 加滑轮rn JPanel panel = new JPanel();//rn JPanel panel2 = new JPanel(new FlowLayout(FlowLayout.CENTER, 30, 10));rn JPanel panel3 = new JPanel(new GridLayout(1, 10));rn JPanel panel4 = new JPanel(new BorderLayout(0, 10));rn panel.setPreferredSize(new Dimension(600, 400));rn panel.setLayout(new BorderLayout());rn JButton b1 = new JButton("预订");rn JButton b2 = new JButton("加至购物车");rn JButton b3 = new JButton("预定多个");rn JButton b4 = new JButton("生成订单");rn panel2.add(b1);rn panel2.add(b2);rn panel2.add(b3);rn panel2.add(b4);rn ButtonListener bListener = new ButtonListener(jiu,rid);rn rn JButton b5 = new JButton("查询空房");rn panel3.add(b5);rn rn rn bListener.jPanel = panel;rn bListener.jPanel2 = pane;rn ButtonListener bListener2 = new ButtonListener(table);rn b5.addActionListener(bListener2);rn rn b1.addActionListener(bListener);rn b2.addActionListener(bListener);rn b3.addActionListener(bListener);rn b4.addActionListener(bListener);rnrn panel.add("Center", pane);rn panel.add("South", panel2);rn panel.add("North", panel3);rn panel.setBorder(BorderFactory.createTitledBorder("房间信息"));rn rn rn rn return panel;rn rn JPanel dingdan() rn JTable dingdan = order();rn JScrollPane pane = new JScrollPane(dingdan);rn JPanel jp10 = new JPanel(new BorderLayout());rn jp10.add("Center", pane);rn JButton b1 = new JButton("确定");rn JButton b2 = new JButton("刷新");rn jp10.add("South", b1);rn jp10.add("North",b2);rn ButtonListener bListener1 = new ButtonListener(dingdan);rn b1.addActionListener(bListener1);rn b2.addActionListener(bListener1);rn return jp10;rn rn JTable order() //生成订单的表格rn Vector lieV = new Vector();rn Vector hangV = new Vector();rn try rn Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");rn Connection con;rn con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DataBaseName=Hotel", "sa", "123");rn PreparedStatement statement = con.prepareStatement("Select * from 订单 where Userid =? ");rn statement.setString(1, new MainClass().getname());rn ResultSet rs = statement.executeQuery();rn while (rs.next()) rn Vector hangv = new Vector();rn hangv.add(Integer.parseInt(rs.getString(1)));rn hangv.add(rs.getString(2)); rn hangv.add((rs.getString(3))); rn hangv.add((rs.getString(4))); rn hangv.add((rs.getInt(5))); rn hangv.add((rs.getString(6))); rn hangv.add((rs.getInt(7)));rn hangV.add(hangv);rn rn catch (Exception e) rn System.out.println("Error" + e);rn rn final Object Lie[] = "订单编号", "用户", "房间编号", "订单日期","数量", "状态","价格" ;rn lieV.add("订单编号");rn lieV.add("用户");rn lieV.add("房间编号");rn lieV.add("订单日期");rn lieV.add("数量");rn lieV.add("状态");rn lieV.add("价格");rn rn //JTable jiu = new JTable(row, Lie); // 建立表格rn DefaultTableModel tableModel = new DefaultTableModel(hangV, lieV);rn JTable jiu = new JTable(tableModel); rn jiu.setPreferredScrollableViewportSize(new Dimension(400, 300));rn jiu.setRowHeight(30);rn jiu.setRowMargin(5);rn jiu.setRowSelectionAllowed(true);rn jiu.setSelectionBackground(Color.WHITE);rn jiu.setSelectionForeground(Color.red);rn jiu.setGridColor(Color.BLACK);rn // jiu.selectAll();rn jiu.setRowSelectionInterval(0, 0);rnrn //jiu.clearSelection();rn jiu.setDragEnabled(false);rn jiu.setShowGrid(true);rn jiu.setShowHorizontalLines(false);rn jiu.setShowVerticalLines(false);rn //jiu.doLayout();rn jiu.setBackground(Color.LIGHT_GRAY);rn //ButtonListener bListener = new ButtonListener(jiu, rid);rn //bListener.otherTable = jiu;rn return jiu;rn rn //!!!!rn JTable jiudian() //生成酒店的表格 rn // 用向量来实现动态的大小rn //Object 可以不用了rn Vector lieV = new Vector();rn Vector hangV = new Vector();rn Object row[][] = new Object[30][30];rn try rn Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");rn Connection con;rn con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DataBaseName=Hotel", "sa", "123");rn Statement statement = con.createStatement();rn ResultSet rs = statement.executeQuery("Select * from 房间");rn int x = 0;rn int y = 0;rn rn while (rs.next()) rn Vector hangv = new Vector();rn row[x][y] = Integer.parseInt(rs.getString("rid"));rn hangv.add(row[x][y]);rn y++;rn row[x][y] = rs.getInt("Rprice");rn hangv.add(row[x][y]);rn y++;rn row[x][y] = (rs.getString("raddress"));rn hangv.add(row[x][y]);rn y++;rn row[x][y] = (rs.getString("rtype"));rn hangv.add(row[x][y]);rn y++;rn row[x][y] = (rs.getString("rstate"));rn hangv.add(row[x][y]);rn x++;rn y = 0;rn hangV.add(hangv);rn rn catch (Exception e) rn System.out.println("Error" + e);rn rn final Object Lie[] = "编号", "价格", "位置", "类型", "状态" ;rn lieV.add("编号");rn lieV.add("价格");rn lieV.add("位置");rn lieV.add("类型");rn lieV.add("状态");rn rn //JTable jiu = new JTable(row, Lie); // 建立表格rn DefaultTableModel tableModel = new DefaultTableModel(hangV, lieV);rn JTable jiu = new JTable(tableModel); rn jiu.setPreferredScrollableViewportSize(new Dimension(400, 300));rn jiu.setRowHeight(30);rn jiu.setRowMargin(5);rn jiu.setRowSelectionAllowed(true);rn jiu.setSelectionBackground(Color.WHITE);rn jiu.setSelectionForeground(Color.red);rn jiu.setGridColor(Color.BLACK);rn // jiu.selectAll();rn jiu.setRowSelectionInterval(0, 0);rnrn //jiu.clearSelection();rn jiu.setDragEnabled(false);rn jiu.setShowGrid(true);rn jiu.setShowHorizontalLines(false);rn jiu.setShowVerticalLines(false);rn jiu.doLayout();rn jiu.setBackground(Color.LIGHT_GRAY);rnrn return jiu;rn rnrnrnrnrnErrorjava.lang.IllegalArgumentException: Row index out of rangern实在不知道怎么修改rn 论坛

Parameter index out of range 谢谢!

05-27

谢谢大家!帮我看看这个错误怎么回事,谢谢!!rnrnjava.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).rn at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:2493)rn at com.mysql.jdbc.PreparedStatement.setString(PreparedStatement.java:3213)rn at database.LinkDB.addBook(LinkDB.java:35)rn at action.addBookAction.execute(addBookAction.java:37)rn at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)rn at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)rn at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)rn at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)rn at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)rn at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)rn at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)rn at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)rn at java.lang.Thread.run(Thread.java:595)rn 论坛

【求助】python beautifulsoup下载网页错误IndexError: list index out of range

11-22

最近刚学习用beautifulsoup抓取东西,但按照网页给的程序运行出错,请朋友们帮忙看看什么原因,Python2.7rnrn#代码如下,来源:http://rsj217.diandian.com/post/2012-11-15/40042985002rnrn# -*- coding: utf-8 -*-rn# target urlrn# http://travel.fengniao.com/slide/334/3344576_%d.htmlrn# target picturern# rn rnimport urllib2rnfrom BeautifulSoup import BeautifulSouprn rn# get the url of web which has the picture =>url resultsrnurlList = ['http://travel.fengniao.com/slide/334/3344576_%d.html' % i for i in range(1,40)]rnimgurl = []rn# open every url via urllib2,get the img tag via BeautifulSouprnfor i in urlList:rn html = urllib2.urlopen(i)rn soup = BeautifulSoup(html)rn imgsResult = soup.findAll('img',id="mainPic")rn imgurl.append(imgsResult[0]['src'])rn rn# the resultrnprint imgurlrnrnrn运行结果如下:rn>>> ================================ RESTART ================================rn>>> rnrnTraceback (most recent call last):rn File "C:\Python27\蜂鸟图片集下载", line 20, in rn imgurl.append(imgsResult[0]['src'])rnIndexError: list index out of rangern>>> rnrnrn此外,不用循环,单独对某一页面使用时,结果出现为空rnimport urllib2rnfrom bs4 import BeautifulSouprnurl='http://travel.fengniao.com/slide/334/3344576_1.html'rnhtml = urllib2.urlopen(url)rnsoup = BeautifulSoup(html)rnimgsResult = soup.findAll('img',id="mainPic")rnprint imgsResultrnrn运行结果rn>>> ================================ RESTART ================================rn>>> rn[]rn>>> rn请各位帮看看错在哪里,为什么运行不出来 论坛

list index out of bounds

11-07

unit Unit6;rnrninterfacernrnusesrn Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,rn Dialogs, StdCtrls, ComCtrls, DB, ADODB, Grids, DBGrids, ToolWin,hotelmodual,rn Menus;rnrntypern TForm6 = class(TForm)rn ToolBar1: TToolBar;rn ToolButton1: TToolButton;rn ToolButton2: TToolButton;rn ToolButton3: TToolButton;rn ToolButton4: TToolButton;rn ToolButton5: TToolButton;rn ToolButton6: TToolButton;rn ADOQuery1: TADOQuery;rn ADOTable1: TADOTable;rn DBGrid1: TDBGrid;rn DataSource1: TDataSource;rn PageControl1: TPageControl;rn GroupBox1: TGroupBox;rn Label1: TLabel;rn Label2: TLabel;rn Label3: TLabel;rn Label4: TLabel;rn Label5: TLabel;rn Label6: TLabel;rn Edit1: TEdit;rn Edit2: TEdit;rn Edit3: TEdit;rn Edit4: TEdit;rn Edit5: TEdit;rn Edit6: TEdit;rn PopupMenu1: TPopupMenu;rn procedure FormShow(Sender: TObject);rn procedure ToolButton1Click(Sender: TObject);rn procedure ToolButton2Click(Sender: TObject);rn procedure Edit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);rn procedure ToolButton3Click(Sender: TObject);rn procedure ToolBar1Click(Sender: TObject);rn procedure ADOTable1AfterScroll(DataSet: TDataSet);rn procedure ToolButton5Click(Sender: TObject);rn procedure ToolButton6Click(Sender: TObject);rn privatern Private declarations rn pmark:integer;rn function ptest():string;rnrn publicrn Public declarations rn end;rnrnvarrn Form6: TForm6;rnrnimplementationrnrnuses Unit3;rnrn$R *.dfmrnrnprocedure TForm6.ADOTable1AfterScroll(DataSet: TDataSet);rnbeginrnedit1.Text:=adotable1.FieldByName('roomid').AsString;rnedit2.Text:=adotable1.FieldByName('roomtype').AsString;rnedit3.Text:=adotable1.FieldByName('tvor').AsString;rnedit4.Text:=adotable1.FieldByName('airconditionaryor').AsString;rnedit5.Text:=adotable1.FieldByName('netor').AsString;rnedit6.Text:=adotable1.FieldByName('price').AsString;rnrnedit1.ReadOnly:=true;rnedit2.ReadOnly:=true;rnedit3.ReadOnly:=true;rnedit4.ReadOnly:=true;rnedit5.ReadOnly:=true;rnedit6.ReadOnly:=true;rn pmark:=2;rnend;rnrnprocedure TForm6.Edit1KeyDown(Sender: TObject; var Key: Word;rn Shift: TShiftState);rn varrn x,x1:integer;rn tc:tcomponent;rn beginrn if not (ActiveControl is TDBGrid) thenrn beginrn if (key=13)or(key=vk_down) thenrn beginrn perform (WM_NEXTDLGCTL,0,0);rn end;rn if key=VK_UP then perform(WM_NEXTDLGCTL,1,0);rn end;rnend;rnrnprocedure TForm6.FormShow(Sender: TObject);rnvarrn i:integer;rnbeginrn adoquery1.Connection:=datamodule3.ADOConnection1;rn adotable1.connection:=datamodule3.ADOConnection1;rnrn adotable1.Close;rn adotable1.TableName:='room';rn adotable1.Open;rnrn with dbgrid1 dorn beginrn columns.clear;rnrnfor i := 0 to 5 do columns.Add;rn columns[0].Title.caption:='房间号';rn columns[1].Title.caption:='房间类型';rn columns[2].Title.caption:='是否有电视';rn columns[3].Title.caption:='是否有空调';rn columns[4].Title.caption:='是否有宽带';rn columns[5].Title.caption:='价格';rnrn columns[0].fieldname:='roomid';rn columns[1].fieldname:='roomtype';rn columns[2].fieldname:='tvor';rn columns[3].fieldname:='airconditionaryor';rn columns[4].fieldname:='netor';rn columns[5].fieldname:='price';rnrn columns[0].Width:=40;rn columns[1].Width:=100;rn columns[2].Width:=80;rn columns[3].Width:=100;rn columns[4].Width:=60;rn columns[5].Width:=60;rnrn for I := 0 to 5 dorn beginrn Columns[i].Title.Alignment:=tacenter;rn end;rn//options:=options-[dgediting];rn end;rn pagecontrol1.Pages[0].Caption:='房间信息';rn pagecontrol1.activepageindex:=0;rn dbgrid1.popupmenu:=popupmenu1;rn pmark:=0;rnrnend;rnrnprocedure TForm6.ToolBar1Click(Sender: TObject);rnvarrns,s1,s2:string;rnn:integer;rnbeginrn s:=ptest();rn if(s='')thenrn beginrn adotable1.AfterScroll:=nil;rn n:=0;rn if(pmark=1) then adotable1.Append;rnrn adotable1.Edit;rn adotable1.FieldByName('roomid').AsString:=trim(edit1.text);rn adotable1.fieldbyname('roomtype').AsString:=trim(edit2.text);rn adotable1.fieldbyname('tvor').AsString:=trim(edit3.Text);rn adotable1.fieldbyname('airconditionaryor').AsString:=trim(edit4.text);rn adotable1.fieldbyname('netor').AsString:=trim(edit5.text);rn adotable1.fieldbyname('price').AsString:=trim(edit6.text);rn adotable1.Post;rn pmark:=2;rn adotable1.AfterScroll:=adotable1.afterscroll;rn endrn elsern beginrn s:='数据验证发现以下错误:'+char(13)+s+char(13)+char(13)+'数据保存失败!';rn application.MessageBox(pchar(s),'系统提示',0+16);rn end;rnend;rnrnprocedure TForm6.ToolButton1Click(Sender: TObject);rnvarrni:integer;rnbeginrn for i := 1 to 6 dorn beginrn tedit(findcomponent('edit'+inttostr(i))).Text:='';rn tedit(findcomponent('edit'+inttostr(i))).readonly:=false;;rn end;rn edit1.SetFocus;rn pmark:=1;rn pagecontrol1.ActivePageIndex:=0;rnend;rnrnprocedure TForm6.ToolButton2Click(Sender: TObject);rnvarrni:integer;rns:string;rnbeginrn for i:= 1 to 6 dorn beginrn s:='edit'+inttostr(i);rn tedit(findcomponent(s)).ReadOnly:=false;rn end;rn edit1.readonly:=true;rn pmark:=2;rnend;rnrnprocedure TForm6.ToolButton3Click(Sender: TObject);rnvarrnx:integer;rnbeginrn if(adotable1.RecordCount>0) thenrn beginrn x:=application.MessageBox(pchar('删除记录:'+trim(edit1.text)+char(13)+char(13)+'是否确定?'),'系统提示',4+32);rn if(x=6)then adotable1.Delete;rn end;rnend;rnrnrnrnprocedure TForm6.ToolButton5Click(Sender: TObject);rnbeginrnadotable1.Close;rnadotable1.open;rnend;rnrnprocedure TForm6.ToolButton6Click(Sender: TObject);rnbeginrnform6.Close;rnform3.show;rnend;rnrnfunction TForm6.ptest():string;rnvarrns1,s2,s3,s4,s5,s6,xerr:string;rnx:double;rnx1,x2:integer;rnbeginrn //数据验证,错误信息存放在xerr中rn xerr:='';rn //判断数值型数据是否正确rn x:=0;rn s1:=trim(edit1.text);rn s2:=trim(edit2.text);rn s3:=trim(edit3.text);rn s4:=trim(edit4.text);rn s5:=trim(edit5.Text);rn s6:=trim(edit6.Text);rn beginrn //验证产品编码是否唯一rn adoquery1.close;rn adoquery1.sql.text:='select 1 from room where roomid=p1';rn adoquery1.Parameters.ParamByName('p1').Value:=s1;rn adoquery1.Open;rn if adoquery1.RecordCount>0 then xerr:=xerr+char(13)+'房间号码重复!';rn end;rn if (s1='') then xerr:=xerr+char(13)+'房间号码不能为空!';rn if (s2='') then xerr:=xerr+char(13)+'房间类型不能为空!';rn if (s6='') then xerr:=xerr+char(13)+'房间价格不能为空!';rn result:=xerr;rnend;rn 论坛

没有更多推荐了,返回首页