//--------------------------------------------------------------------------- #include #pragma hdrstop #include "YarnAccount_F.h" #include "MainImage.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" //--------------------------------------------------------------------------- #define IDS_ACCOUNT StringTable[0] #define IDS_WARPYARNACCOUNT StringTable[1] #define IDS_TOTAL StringTable[2] #define IDS_WEFTYARNACCOUNT StringTable[3] #define IDS_CODE StringTable[4] #define IDS_YARNS StringTable[5] TYarnAccountForm *YarnAccountForm; //--------------------------------------------------------------------------- __fastcall TYarnAccountForm::TYarnAccountForm(TComponent* Owner) : TForm(Owner) { //================================================================ StringTable.Create(DirectoryItem, Language, "YarnAccount"); SetSmallFont(Font); SetSmallFont(StaticText6->Font); SetSmallFont(StaticText1->Font); SetSmallFont(Panel3->Font); SetSmallFont(Panel4->Font); SetSmallFont(Label1->Font); SetSmallFont(Label2->Font); SetSmallFont(Label3->Font); SetSmallFont(Label4->Font); SetSmallFont(Label5->Font); SetSmallFont(Label6->Font); SetSmallFont(Label7->Font); SetSmallFont(Label8->Font); Caption = IDS_ACCOUNT ; StaticText1->Caption = IDS_WEFTYARNACCOUNT; StaticText6->Caption = IDS_WARPYARNACCOUNT; Label1->Caption = IDS_TOTAL; Label2->Caption = IDS_TOTAL; Label3->Caption = IDS_TOTAL; Label4->Caption = IDS_TOTAL; Label5->Caption = IDS_TOTAL; Label6->Caption = IDS_TOTAL; Label7->Caption = IDS_TOTAL; Label8->Caption = IDS_TOTAL; //================================================================ } //--------------------------------------------------------------------------- void __fastcall TYarnAccountForm::FormCreate(TObject *Sender) { TIniFile *IniFile = new TIniFile(DirectoryItem + "\\Main.ini"); if (IniFile) { Left = IniFile->ReadInteger("YarnAccount", "FormLeft", (Screen->Width-Width)>>1); Top = IniFile->ReadInteger("YarnAccount", "FormTop", (Screen->Height-Height)>>1); delete IniFile; } } //--------------------------------------------------------------------------- void __fastcall TYarnAccountForm::FormDestroy(TObject *Sender) { TIniFile *IniFile = new TIniFile(DirectoryItem + "\\Main.ini"); if (IniFile) { if (Left<0) Left = 10; if (Top<0) Top = 10; IniFile->WriteInteger("YarnAccount", "FormLeft", Left); IniFile->WriteInteger("YarnAccount", "FormTop", Top); delete IniFile; } } //--------------------------------------------------------------------------- void __fastcall TYarnAccountForm::FormClose(TObject *Sender, TCloseAction &Action) { if (FOnCloseForm) FOnCloseForm(); } //--------------------------------------------------------------------------- void __fastcall TYarnAccountForm::FormShow(TObject *Sender) { RearrangeData(); } //--------------------------------------------------------------------------- void __fastcall TYarnAccountForm::WarpGridDrawCell(TObject *Sender, int Col, int Row, TRect &Rect, TGridDrawState State) { AnsiString str; int x, y; TSize size; size.cx = Rect.Right-Rect.Left; size.cy = Rect.Bottom-Rect.Top; if (Row == 0) { WarpGrid->Canvas->Font->Color = clBlack; switch (Col % 3) { case 0: str = IDS_CODE; break; case 1: str = IDS_COMMON_LENGTH; break; case 2: str = IDS_YARNS; break; } } else { WarpGrid->Canvas->Font->Color = clBlack; if (Col % 3) { str = ExtractData(Col, Row, WARP); if (str == "0" || str == "0.00") return; } else { WarpGrid->Canvas->Font->Color = clBlue; str = (Col / 3)*8 + Row; } } x = (size.cx-WarpGrid->Canvas->TextWidth(str)) / 2; if (x<0) x = 0; y = (size.cy-WarpGrid->Canvas->TextHeight(str)) / 2; if (y<0) y = 0; WarpGrid->Canvas->TextRect(Rect, Rect.Left+x, Rect.Top+y, str); } //--------------------------------------------------------------------------- void __fastcall TYarnAccountForm::WeftGridDrawCell(TObject *Sender, int Col, int Row, TRect &Rect, TGridDrawState State) { AnsiString str; int x, y; TSize size; size.cx = Rect.Right-Rect.Left; size.cy = Rect.Bottom-Rect.Top; if (Row == 0) { WeftGrid->Canvas->Font->Color = clBlack; switch (Col % 3) { case 0: str = IDS_CODE; break; case 1: str = IDS_COMMON_LENGTH; break; case 2: str = IDS_YARNS; break; } } else { if (Col % 3) { WeftGrid->Canvas->Font->Color = clBlack; str = ExtractData(Col, Row, WEFT); if (str == "0" || str == "0.00") return; } else { WeftGrid->Canvas->Font->Color = clRed; str = (Col / 3)*8 + Row; } } x = (size.cx-WeftGrid->Canvas->TextWidth(str)) / 2; if (x<0) x = 0; y = (size.cy-WeftGrid->Canvas->TextHeight(str)) / 2; if (y<0) y = 0; WeftGrid->Canvas->TextRect(Rect, Rect.Left+x, Rect.Top+y, str); } //--------------------------------------------------------------------------- AnsiString __fastcall TYarnAccountForm::ExtractData(int Col, int Row, int W) { TYarnArray *ya; int i; int xcode = (Col / 3)*8 + Row; // 1 - 32 int xindex = Col % 3; // 0, 1, 2 double totlen = 0; int totyar = 0; if (xindex == 1) { totlen = MainImageForm->Plan->GetYarnLength(W, xcode, false); if (MainImageForm->CurrentUnit == uCm) { totlen = totlen * 2.54; } return Format("%.2f", OPENARRAY(TVarRec, (totlen))); } else if (xindex == 2) { totyar = MainImageForm->Plan->GetYarnLength(W, xcode, true); return Format("%d", OPENARRAY(TVarRec,(totyar))); } return "0"; } //--------------------------------------------------------------------------- void __fastcall TYarnAccountForm::RearrangeData() { WeftGrid->Repaint(); WarpGrid->Repaint(); ChangeTotalSize(); } //--------------------------------------------------------------------------- void __fastcall TYarnAccountForm::ChangeTotalSize() { TYarnArray *ya; double weftlen[8] = {0, 0, 0, 0, 0, 0, 0, 0}; double warplen[8] = {0, 0, 0, 0, 0, 0, 0, 0}; int weftyar[8] = {0, 0, 0, 0, 0, 0, 0, 0}; int warpyar[8] = {0, 0, 0, 0, 0, 0, 0, 0}; int i, j; for (j = 0; j < 8; j++) { //A, B, C, D, E... for (i = 0; i < 8; i ++) { warplen[j] += MainImageForm->Plan->GetYarnLength(WARP, j*8 + i, false); warpyar[j] += MainImageForm->Plan->GetYarnLength(WARP, j*8 + i, true); } } for (j = 0; j < 8; j++) { //A, B, C, D, E... for (i = 0; i < 8; i ++) { weftlen[j] += MainImageForm->Plan->GetYarnLength(WEFT, j*8 + i, false); weftyar[j] += MainImageForm->Plan->GetYarnLength(WEFT, j*8 + i, true); } } if (MainImageForm->CurrentUnit == uCm) { for (i = 0; i < 8; i++) { warplen[i] *= 2.54; weftlen[i] *= 2.54; } } if (warplen[0]) { WarpALen->Caption = Format("%.2f", OPENARRAY(TVarRec, (warplen[0]))); WarpAYar->Caption = warpyar[0]; } else { WarpALen->Caption = ""; WarpAYar->Caption = ""; } if (warplen[1]) { WarpBLen->Caption = Format("%.2f", OPENARRAY(TVarRec, (warplen[1]))); WarpBYar->Caption = warpyar[1]; } else { WarpBLen->Caption = ""; WarpBYar->Caption = ""; } if (warplen[2]) { WarpCLen->Caption = Format("%.2f", OPENARRAY(TVarRec, (warplen[2]))); WarpCYar->Caption = warpyar[2]; } else { WarpCLen->Caption = ""; WarpCYar->Caption = ""; } if (warplen[3]) { WarpDLen->Caption = Format("%.2f", OPENARRAY(TVarRec, (warplen[3]))); WarpDYar->Caption = warpyar[3]; } else { WarpDLen->Caption = ""; WarpDYar->Caption = ""; } if (warplen[4]) { WarpELen->Caption = Format("%.2f", OPENARRAY(TVarRec, (warplen[4]))); WarpEYar->Caption = warpyar[4]; } else { WarpELen->Caption = ""; WarpEYar->Caption = ""; } if (warplen[5]) { WarpFLen->Caption = Format("%.2f", OPENARRAY(TVarRec, (warplen[5]))); WarpFYar->Caption = warpyar[5]; } else { WarpFLen->Caption = ""; WarpFYar->Caption = ""; } if (warplen[6]) { WarpGLen->Caption = Format("%.2f", OPENARRAY(TVarRec, (warplen[6]))); WarpGYar->Caption = warpyar[6]; } else { WarpGLen->Caption = ""; WarpGYar->Caption = ""; } if (warplen[7]) { WarpHLen->Caption = Format("%.2f", OPENARRAY(TVarRec, (warplen[7]))); WarpHYar->Caption = warpyar[7]; } else { WarpHLen->Caption = ""; WarpHYar->Caption = ""; } if (weftlen[0]) { WeftALen->Caption = Format("%.2f", OPENARRAY(TVarRec, (weftlen[0]))); WeftAYar->Caption = weftyar[0]; } else { WeftALen->Caption = ""; WeftAYar->Caption = ""; } if (weftlen[1]) { WeftBLen->Caption = Format("%.2f", OPENARRAY(TVarRec, (weftlen[1]))); WeftBYar->Caption = weftyar[1]; } else { WeftBLen->Caption = ""; WeftBYar->Caption = ""; } if (weftlen[2]) { WeftCLen->Caption = Format("%.2f", OPENARRAY(TVarRec, (weftlen[2]))); WeftCYar->Caption = weftyar[2]; } else { WeftCLen->Caption = ""; WeftCYar->Caption = ""; } if (weftlen[3]) { WeftDLen->Caption = Format("%.2f", OPENARRAY(TVarRec, (weftlen[3]))); WeftDYar->Caption = weftyar[3]; } else { WeftDLen->Caption = ""; WeftDYar->Caption = ""; } if (weftlen[4]) { WeftELen->Caption = Format("%.2f", OPENARRAY(TVarRec, (weftlen[4]))); WeftEYar->Caption = weftyar[3]; } else { WeftELen->Caption = ""; WeftEYar->Caption = ""; } if (weftlen[5]) { WeftFLen->Caption = Format("%.2f", OPENARRAY(TVarRec, (weftlen[5]))); WeftFYar->Caption = weftyar[5]; } else { WeftFLen->Caption = ""; WeftFYar->Caption = ""; } if (weftlen[6]) { WeftGLen->Caption = Format("%.2f", OPENARRAY(TVarRec, (weftlen[6]))); WeftGYar->Caption = weftyar[3]; } else { WeftGLen->Caption = ""; WeftGYar->Caption = ""; } if (weftlen[7]) { WeftHLen->Caption = Format("%.2f", OPENARRAY(TVarRec, (weftlen[7]))); WeftHYar->Caption = weftyar[7]; } else { WeftHLen->Caption = ""; WeftHYar->Caption = ""; } } //--------------------------------------------------------------------------- void __fastcall TYarnAccountForm::UnitChange() { WarpGrid->Repaint(); WeftGrid->Repaint(); ChangeTotalSize(); } //---------------------------------------------------------------------------