📄 unit20.cpp
字号:
CanSelect = false;
}
}
else
{
if(ARow <= m_StdParaCount) CanSelect = false;
if(ACol == 0
|| ACol == 3
|| ACol == 4
|| ACol ==6
|| ACol ==7
|| ACol ==8
)
{
CanSelect = false;
}
}
*/
}
//---------------------------------------------------------------------------
void __fastcall TFormXGD::StringGrid1DblClick(TObject *Sender)
{
TPoint pt;
int row, col;
TStringGrid *sgrid;
char gs[80];
sgrid = (TStringGrid *)Sender;
GetCursorPos(&pt);
pt = sgrid->ScreenToClient(pt);
sgrid->MouseToCell(pt.x, pt.y, col, row);
//if(!m_bStdCompl && col == 3 && row > 0)
if(col == 3 && row > 0)
{
FormInData->ShowModal();
if(FormInData->bOK)
{
m_pXGDParas[row - 1].Abs = FormInData->fRVal;
//sprintf(gs, "%1.3f", );
FNFloatToStr(gs, 1, m_NDJD, FormInData->fRVal);
sgrid->Cells[col][row] = gs;
sgrid->Cells[7][row] = FormInData->iNum;
m_bAmend = true;
btnAddItem->Enabled = CheckForNewItem();
if(m_bStdCompl)
{
DrawWorkQX();
}
}
}
}
//---------------------------------------------------------------------------
bool TFormXGD::NewItem(void)
{
int i;
char gs[80];
if((StringGrid1->RowCount-1) > m_MaxParaCount) return false;
if(m_AllParaCount == 0)
{
i = 1;
}
else
{
if(!CheckForNewItem()) return false;
StringGrid1->RowCount = StringGrid1->RowCount + 1;
i = StringGrid1->RowCount - 1;
}
if(m_bStdCompl)
{
if(i < m_StdParaCount)
{
StringGrid1->Cells[0][i]= "√";
}
else
{
StringGrid1->Cells[0][i]= i - m_StdParaCount;
}
}
else
{
StringGrid1->Cells[0][i] = i;
}
sprintf(gs, "未命名%d", i);
StringGrid1->Cells[1][i] = gs;
sprintf(gs, "编号%.0d", i);
StringGrid1->Cells[2][i] = gs;
StringGrid1->Cells[3][i] = ""; //吸光度
StringGrid1->Cells[4][i] = ""; //浓度
StringGrid1->Cells[5][i] = ""; //标准浓度
StringGrid1->Cells[6][i] = ""; //浓度偏差
StringGrid1->Cells[7][i] = "1";//测量次数
GetLocalTime(&m_pXGDParas[0].Time); //日期时间
StringGrid1->Cells[8][i] = DateTimeToStr(SystemTimeToDateTime(m_pXGDParas[0].Time));
StringGrid1->Cells[9][i] = "(无)";
m_AllParaCount++;
m_pXGDParas[i - 1].bValid = false;
//StringGrid1->Enabled = false;
//StringGrid1->Col = 2;
//StringGrid1->Row = i;
//StringGrid1->Enabled = true;
//StringGrid1->Col = 2;
//StringGrid1->Row = i;
SelectGridCell(StringGrid1, 2, i);
btnAddItem->Enabled = false;
StringGrid1->Repaint();
return true;
}
//---------------------------------------------------------------------------
void __fastcall TFormXGD::btnAddItemClick(TObject *Sender)
{
NewItem();
m_bAmend = true;
if(m_bStdCompl)
SelectGridCell(StringGrid1, 0, StringGrid1->RowCount - 1);
}
//---------------------------------------------------------------------------
bool TFormXGD::CheckForNewItem(void)
{
int i;
for(i = 1; i < StringGrid1->RowCount; i++)
{
if( !IsFloat(StringGrid1->Cells[3][i])
|| !IsFloat(StringGrid1->Cells[4][i])
|| !IsFloat(StringGrid1->Cells[5][i]))
{
return false;
}
}
return true;
}
//---------------------------------------------------------------------------
void __fastcall TFormXGD::btnDelClick(TObject *Sender)
{
int i,j;
if(m_SelectRow <= 0
|| (m_bStdCompl && m_SelectRow <= m_StdParaCount)
)
return;
if(Application->MessageBox("是否删除选中的数据?",
"提示",MB_YESNO|MB_ICONWARNING)==IDNO) return;
for(i = m_SelectRow; i < StringGrid1->RowCount - 1; i++)
{
for(j = 0; j < StringGrid1->ColCount; j++)
{
StringGrid1->Cells[j][i]=StringGrid1->Cells[j][i+1];
}
if(!m_bStdCompl)
StringGrid1->Cells[0][i] = IntToStr(i);
else
StringGrid1->Cells[0][i] = IntToStr(i - m_StdParaCount);
}
m_AllParaCount--;
if(StringGrid1->RowCount == 2)
{
for(i = 0; i < StringGrid1->ColCount; i++)
StringGrid1->Cells[i][1] = "";
NewItem();
}
else
{
StringGrid1->RowCount = StringGrid1->RowCount - 1;
}
if(StringGrid1->Row == m_SelectRow)
{
m_SelectRow = -1;
//StringGrid1->Row = 1;
//StringGrid1->Col = 1;
}
m_SelectRow = -1;
StringGrid1->Options >> goRowSelect;
StringGrid1->Options << goEditing;
StringGrid1->Options << goAlwaysShowEditor;
btnDel->Enabled = false;
if(StringGrid1->RowCount == 1)
{
StringGrid1->RowCount = 2;
for(i = 0; i < StringGrid1->ColCount; i++)
StringGrid1->Cells[i][1] = "";
NewItem();
StringGrid1->Row = 1;
}
else
{
if(m_bStdCompl && (StringGrid1->RowCount == (m_StdParaCount + 1)))
{
NewItem();
StringGrid1->Row = m_StdParaCount;
}
}
btnAddItem->Enabled = CheckForNewItem();
if(!m_bStdCompl)
{
if(btnAddItem->Enabled && StringGrid1->RowCount >= 3)
{
btnBuildStd->Enabled = true;
}
else
{
btnBuildStd->Enabled = false;
}
}
else
{
btnBuildStd->Enabled = true;
}
StringGrid1->Repaint();
DrawWorkQX();
m_bAmend = true;
}
//---------------------------------------------------------------------------
void TFormXGD::CommonDrawBK(TCanvas *Canvas,
int left, int right, int top, int bottom,
float xl, float xh, float yl, float yh,
int &PWx00, int &PWx11, int &PWy00, int &PWy11,
int &PWx0, int &PWx1, int &PWy0, int &PWy1)
{
//TRect rs,rd;
int wx0, wx1;
int wy0, wy1;
int wx00, wx11, wy00, wy11;
char gs[80];
TSize sz;
int temp;
Canvas->Pen->Style = psSolid;
//清除背景
Canvas->Pen->Color = clBlack;
Canvas->Rectangle(left + 1, top + 1, right - 1, bottom - 1);
sprintf(gs, "%1.3f", yh);
//FNFloatToStr(gs, 1, m_NDJD, yh);
sz = Canvas->TextExtent(gs);
wx00 = sz.cx;
sprintf(gs, "%1.3f", yl);
//FNFloatToStr(gs, 1, m_NDJD, yl);
sz = Canvas->TextExtent(gs);
if(wx00 < sz.cx) wx00 = sz.cx;
wx00 = wx00 + left;
sprintf(gs, "%1.3f", xh);
//FNFloatToStr(gs, 1, m_XGDJD + 1, xh);
sz = Canvas->TextExtent(gs);
wx11 = right - sz.cx / 2;
sprintf(gs, "%1.2f", xl);
//FNFloatToStr(gs, 1, m_XGDJD, xl);
sz = Canvas->TextExtent(gs);
wy00 = top + sz.cy;
wy11 = bottom - sz.cy - sz.cy;
wy0 = wy00 + sz.cy;
wy1 = wy11 - sz.cy;
wx0 = wx00;
wx1 = wx11;
PWx00 = wx00; PWx11 = wx11;
PWy00 = wy00; PWy11 = wy11;
PWx0 = wx0; PWx1 = wx1;
PWy0 = wy0; PWy1 = wy1;
//画矩形框
Canvas->Rectangle(wx00, wy00, wx11, wy11);
//画三条虚线
Canvas->Pen->Style=psDot;
Canvas->MoveTo(wx0,wy0);
Canvas->LineTo(wx1,wy0);
Canvas->MoveTo(wx0,wy1);
Canvas->LineTo(wx1,wy1);
//Canvas->MoveTo(wx0,(wy1+wy0)/2);
//Canvas->LineTo(wx1,(wy1+wy0)/2);
Canvas->Pen->Style=psSolid;
//画坐标刻度
int x,y;
for(int i=1;i<10;i++)
{ x=wx0 + i * (wx1 - wx0) / 10;
y=wy00;
Canvas->MoveTo(x, y);
Canvas->LineTo(x, y+3);
y = wy11;
Canvas->MoveTo(x,y);
Canvas->LineTo(x,y-3);
}
//画间隔点
for(int i=1;i<20;i++)
for(int j=1;j<10;j++)
{ x=wx0+(wx1-wx0)*i/20;
y=wy0+(wy1-wy0)*j/10;
Canvas->Pixels[x][y]=clBlack;
}
//画坐标值
Canvas->Font->Color = clMaroon;
sprintf(gs, "%4.1f", xl);
sz = Canvas->TextExtent(gs);
Canvas->TextOut(wx00 - sz.cx / 2, wy11 + 1, gs);
sprintf(gs, "%4.1f", xh);
sz = Canvas->TextExtent(gs);
Canvas->TextOut(wx11 - sz.cx / 2, wy11 + 1, gs);
//Image1->Canvas->TextFlags=ETO_RTLREADING;//右对齐
sprintf(gs, "%1.2f", yh);
sz = Canvas->TextExtent(gs);
Canvas->TextOut(wx00 - sz.cx - 1, wy0 - sz.cy / 2, gs);
sprintf(gs, "%1.2f", yl);
sz = Canvas->TextExtent(gs);
Canvas->TextOut(wx0 - sz.cx - 1, wy1 - sz.cy / 2, gs);
}
//---------------------------------------------------------------------------
void TFormXGD::CommonDrawQX(TCanvas *Canvas,
float xl, float xh, float yl, float yh,
//float dxl, float dxh, float dyl, dyh,
float pdx[], float pdy[], int n,
int Wx00, int Wx11, int Wy00, int Wy11,
int Wx0, int Wx1, int Wy0, int Wy1,
TColor color, bool bLine)
{
int x,y,i;
int wx0, wx1, wy0, wy1;
float dx, dy;
wx0 = Wx0; wx1 = Wx1;
wy0 = Wy0; wy1 = Wy1;
if(n <= 0) return; // 如果数据就返回
if(fabs(xh - xl) < 0.0000001) return;
if(fabs(yh - yl) < 0.0000001) return;
for(i = 0; i < n; i++)
{
dx = pdx[i];
dy = pdy[i];
x = wx0 + (wx1 - wx0) * (dx - xl) / (xh - xl) ;
y = wy0+ (wy1 - wy0) * (yh - dy) / (yh - yl);
if(x < wx0 || x > wx1) continue;
else
{
if(y > wy1) y = wy1;
else if(y < wy0) y = wy0;
Canvas->MoveTo(x, y);
break;
}
}
Canvas->Pen->Style = psSolid;
Canvas->Pen->Color = color;
for(i = 0; i < n; i++)
{
dx = pdx[i];
dy = pdy[i];
if(dx < xl || dx > xh) continue;
x = wx0 + (wx1 - wx0) * (dx - xl) / (xh - xl) ;
y = wy0+ (wy1 - wy0) * (yh - dy) / (yh - yl);
if(x < wx0) x = wx0;
else if(x > wx1) x = wx1;
if(y > wy1) y = wy1;
else if(y < wy0) y = wy0;
if(bLine)
{
Canvas->LineTo(x, y);
}
else
{
Canvas->MoveTo(x, y);
Canvas->Ellipse(x - 2, y - 2, x + 2, y + 2);
}
}
}
//---------------------------------------------------------------------------
void TFormXGD::CommonDrawPoint(TCanvas *Canvas,
float xl, float xh, float yl, float yh,
//float dxl, float dxh, float dyl, dyh,
float dx, float dy, int number,
int Wx00, int Wx11, int Wy00, int Wy11,
int Wx0, int Wx1, int Wy0, int Wy1,
TColor color, bool bShowNumber)
{
int x,y,i;
int wx0, wx1, wy0, wy1;
TSize sz;
int PixelsPerCmX, PixelsPerCmY;
int rx, ry;
if(fabs(xh - xl) < 0.0000001) return;
if(fabs(yh - yl) < 0.0000001) return;
wx0 = Wx0; wx1 = Wx1;
wy0 = Wy0; wy1 = Wy1;
Canvas->Pen->Style = psSolid;
Canvas->Pen->Color = color;
PixelsPerCmX = GetDeviceCaps(Canvas->Handle,LOGPIXELSX) / 2.54; // 每厘米点数
PixelsPerCmY = GetDeviceCaps(Canvas->Handle,LOGPIXELSY) / 2.54;
rx = 0.1 * PixelsPerCmX;
ry = 0.1 * PixelsPerCmY;
if(dx >= xl && dx <= xh)
{
x = wx0 + (wx1 - wx0) * (dx - xl) / (xh - xl) ;
y = wy0+ (wy1 - wy0) * (yh - dy) / (yh - yl);
if(x < wx0) x = wx0;
else if(x > wx1) x = wx1;
if(y > wy1) y = wy1;
else if(y < wy0) y = wy0;
Canvas->MoveTo(x, y);
Canvas->Ellipse(x - rx, y - ry, x + rx, y + ry);
sz = Canvas->TextExtent(number);
if(x < ((wx0 + wx1) / 2))
{
y = y + 2;
}
else
{
y = y - sz.cy - 2;
}
x = x - sz.cx / 2;
if(bShowNumber)
{
Canvas->Font->Color = color;
Canvas->TextOutA(x, y, number);
}
}
}
//---------------------------------------------------------------------------
void __fastcall TFormXGD::btnBuildStdClick(TObject *Sender)
{
BuildStd();
/*
int i;
float stdx[2], stdy[2];
AnsiString Str;
char gs[80];
GetPara();
if(!m_bStdCompl && CheckForNewItem() && m_AllParaCount >= 2)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -