unit ProjectPropertiesFrm;

interface

uses
  ProjectFme,
  ProjectData, ProjectProperty, StaffDm,
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, JimPages, ComCtrls, ToolWin, MScrollBox,
  XPMenu, JimCombos, Mask, ImgList, ZJGrid, ZjGridDBA;

type
  TProjectPropertiesForm = class(TForm)
    btnOk: TButton;
    btnCancel: TButton;
    xpm: TXPMenu;
    pnlTop: TPanel;
    tbTop: TToolBar;
    tobtnBase: TToolButton;
    Images: TImageList;
    pnlBlank: TPanel;
    tobtnStaff: TToolButton;
    tobtnView: TToolButton;
    jpsProperties: TJimPages;
    jpsPropertiesBase: TJimPage;
    jpsPropertiesStaff: TJimPage;
    jpsPropertiesView: TJimPage;
    pnlBase: TPanel;
    tbContents: TToolBar;
    tobtnDealInfo: TToolButton;
    tobtnTechParameters: TToolButton;
    tobtnDealPayment: TToolButton;
    msbBase: TMScrollBox;
    lblDealInfo: TLabel;
    lblBuilder: TLabel;
    lblConstructor: TLabel;
    lblSupervisor: TLabel;
    lblTechParameters: TLabel;
    lblLoadLevel: TLabel;
    lblDealPayTitle: TLabel;
    pnlDealInfoBar: TPanel;
    leProjectName: TLabeledEdit;
    leDealName: TLabeledEdit;
    leDealIndex: TLabeledEdit;
    leBName: TLabeledEdit;
    leBLegal: TLabeledEdit;
    leBDate: TLabeledEdit;
    leCName: TLabeledEdit;
    leCLegal: TLabeledEdit;
    leCDate: TLabeledEdit;
    leSName: TLabeledEdit;
    leSLegal: TLabeledEdit;
    leSDate: TLabeledEdit;
    pnlTechParametersBar: TPanel;
    leStartPeg: TLabeledEdit;
    leEndPeg: TLabeledEdit;
    leLength: TLabeledEdit;
    leLaneCount: TLabeledEdit;
    cbLoadLevel: TComboBox;
    pnlDealPayBar: TPanel;
    leContractPrice: TLabeledEdit;
    leStartedSubsist: TLabeledEdit;
    leMaterialSubsist: TLabeledEdit;
    pnlViewBar: TPanel;
    leView: TLabel;
    zgStaff: TZJGrid;
    zaStaff: TZjGridDBA;
    jcbPhase: TJimComboBox;
    tobtnSafe: TToolButton;
    lblSafeTitel: TLabel;
    pnlSafeBar: TPanel;
    lblUnlockPassword: TLabel;
    imgValid: TImageList;
    pnlUnlockPassword: TPanel;
    pnlOrgPW: TPanel;
    leUnlockPassword: TLabeledEdit;
    imgOrg: TImage;
    pnlNewPW: TPanel;
    leNewUnlockPasswordAgain: TLabeledEdit;
    leNewUnLockPassword: TLabeledEdit;
    imgNew: TImage;
    imgNewAgain: TImage;
    lblPasswordHint: TLabel;
    leDealType: TLabeledEdit;
    pnlAllView: TPanel;
    pnlAlias: TPanel;
    pnlPriceChange: TPanel;
    cbShowPriceChange: TCheckBox;
    pnlBGL: TPanel;
    cbShowBGLCode: TCheckBox;
    pnlDesignQuantity: TPanel;
    cbShowDesignQuantity: TCheckBox;
    cbShowAlias: TCheckBox;
    tobtnCalcParameters: TToolButton;
    pnlCalcParametersBar: TPanel;
    lblCalcParametersTitel: TLabel;
    leQuantityDigit: TLabeledEdit;
    lblDigit: TLabel;
    leTotalPriceDigit: TLabeledEdit;
    udQuantity: TUpDown;
    udTotalPrice: TUpDown;
    gbPM_Digit: TGroupBox;
    lePM_PriceDigit: TLabeledEdit;
    udPM_PriceDigit: TUpDown;
    pnlReport: TPanel;
    leReport: TLabel;
    cbShowReportShading: TCheckBox;
    edtReportShading: TEdit;
    tobtnDateTime: TToolButton;
    lblDateTime: TLabel;
    pnlDateTime: TPanel;
    lblBaseline: TLabel;
    dtpBaseline: TDateTimePicker;
    lblDeadline: TLabel;
    dtpDeadline: TDateTimePicker;
    lblDateHint: TLabel;
    cbDealPayAloneDigiy: TCheckBox;
    leDealPayTotalPriceDigit: TLabeledEdit;
    udDealPayTotalPriceDigit: TUpDown;
    pnlReportView: TPanel;
    lblReportShowStateTitle: TLabel;
    pnlReportViewBar: TPanel;
    cbReportShowState: TCheckBox;
    edtReportShowStateText: TEdit;
    cbReportShowStageWithoutReply: TCheckBox;
    leDealPhase: TLabeledEdit;
    leSName_2: TLabeledEdit;
    lblSupervisor_2: TLabel;
    leSLegal_2: TLabeledEdit;
    leSDate_2: TLabeledEdit;
    leCName_2: TLabeledEdit;
    leCLegal_2: TLabeledEdit;
    leCDate_2: TLabeledEdit;
    lblConstructor_2: TLabel;
    pnlOverRange: TPanel;
    Label1: TLabel;
    Panel2: TPanel;
    cbShowOverRange: TCheckBox;
    pnlViewPart1: TPanel;
    pnlViewPart2: TPanel;
    pnlApprovalCode: TPanel;
    cbShowApprovalCode: TCheckBox;
    procedure btnOkClick(Sender: TObject);
    procedure leContractPriceClick(Sender: TObject);
    procedure msbBaseMouseWheel(Sender: TObject; Shift: TShiftState;
      WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
    procedure msbBaseMouseWheelDown(Sender: TObject;
      Shift: TShiftState; MousePos: TPoint; var Handled: Boolean);
    procedure msbBaseMouseWheelUp(Sender: TObject; Shift: TShiftState;
      MousePos: TPoint; var Handled: Boolean);
    procedure msbBaseVScroll(Sender: TObject);
    procedure tobtnDealInfoClick(Sender: TObject);
    procedure tobtnBaseClick(Sender: TObject);
    procedure jcbPhaseChanged(Sender: TObject);
    procedure zgStaffCellGetColor(Sender: TObject; ACoord: TPoint;
      var AColor: TColor);
    procedure zgStaffCellGetFont(Sender: TObject; ACoord: TPoint;
      AFont: TFont);
    procedure zgStaffCellCanEdit(Sender: TObject; const ACoord: TPoint;
      var Allow: Boolean);
    procedure leUnlockPasswordKeyPress(Sender: TObject; var Key: Char);
    procedure leNewUnlockPasswordAgainExit(Sender: TObject);
    procedure leNewUnLockPasswordExit(Sender: TObject);
    procedure leUnlockPasswordExit(Sender: TObject);
    procedure cbShowReportShadingClick(Sender: TObject);
    procedure dtpBaselineChange(Sender: TObject);
    procedure cbDealPayAloneDigiyClick(Sender: TObject);
    procedure cbReportShowStateClick(Sender: TObject);
  private
    FProjectData: TProjectData;
    FStaffData: TStaffData;
    FProjProperties: TProjProperties;
    FProjectFrame: TProjectFrame;

    procedure InitAllPage;
    procedure InitDealInfo;
    procedure InitDealPay;
    procedure InitTechParameters;
    procedure InitProjectView;
    procedure InitStaffRela;
    procedure InitSafe;
    procedure InitCalcParameters;
    procedure InitDateTime;

    procedure SaveDealInfo;
    procedure SaveDealPay;
    procedure SaveTechParameters;
    procedure SaveSafe;
    procedure SaveCalcParameters;
    procedure SaveProjectView;
    procedure SaveDateTime;

    procedure ResetContentsCheck; overload;
    procedure ResetContentsCheck(ATag: Integer); overload;
    procedure ResetVertScrollBarPosition(ATag: Integer);

    procedure CheckValidKey(var AKey: Char);

    procedure CheckOrgPassword;
    procedure CheckNewPassword;
    procedure CheckNewPasswordAgain;

    procedure CheckDate;

    procedure SetProjectData(const Value: TProjectData);
  public
    procedure Save;

    property ProjectData: TProjectData read FProjectData write SetProjectData;
    property ProjProperties: TProjProperties read FProjProperties;
    property ProjectFrame: TProjectFrame read FProjectFrame write FprojectFrame;
  end;

procedure ModifyProjectProperties(ProjectFrame: TProjectFrame);

implementation

uses
  PhaseProperty, DB, UtilMethods, ZhAPI;

{$R *.dfm}

procedure ModifyProjectProperties(ProjectFrame: TProjectFrame);
var
  PropertiesForm: TProjectPropertiesForm;
begin
  PropertiesForm := TProjectPropertiesForm.Create(nil);
  try
    PropertiesForm.ClientHeight := 357;
    PropertiesForm.ClientWidth := 530;
    PropertiesForm.ProjectFrame := ProjectFrame;
    PropertiesForm.ProjectData := ProjectFrame.ProjectData;
    PropertiesForm.zgStaff.OnCellCanEdit := PropertiesForm.zgStaffCellCanEdit;
    if PropertiesForm.ShowModal = mrOk then
      PropertiesForm.Save;
  finally
    PropertiesForm.Free;
  end;
end;

{ TProjectPropertiesForm }

procedure TProjectPropertiesForm.InitAllPage;
begin
  InitDealInfo;
  InitTechParameters;
  InitDealPay;
  InitSafe;
  InitCalcParameters;
  InitDateTime;
  InitStaffRela;
  InitProjectView;
end;

procedure TProjectPropertiesForm.InitProjectView;
begin
  cbShowPriceChange.Checked := FProjProperties.ShowPriceChange;
  cbShowBGLCode.Checked := FProjProperties.ShowBGLCode;
  cbShowDesignQuantity.Checked := FProjProperties.ShowDesignQuantity;
  cbShowAlias.Checked := FProjProperties.ShowAlias;
  cbShowOverRange.Checked := FProjProperties.ShowOverRange;
  cbShowApprovalCode.Checked := FProjProperties.ShowApprovalCode;

  cbShowReportShading.Checked := FProjProperties.ShowReportShading;
  edtReportShading.Enabled := cbShowReportShading.Checked;
  edtReportShading.Text := FProjProperties.ReportShading;

  cbReportShowState.Checked := FProjProperties.ReportShowState;
  edtReportShowStateText.Text := FProjProperties.ReportShowStateText;
  edtReportShowStateText.Enabled := cbReportShowState.Checked;
  cbReportShowStageWithoutReply.Checked := FProjProperties.ReportShowStateWithoutReply;
  cbReportShowStageWithoutReply.Enabled := cbReportShowState.Checked;
end;

procedure TProjectPropertiesForm.btnOkClick(Sender: TObject);
begin
  ModalResult := mrOk;
end;

procedure TProjectPropertiesForm.Save;
begin
  SaveDealPay;
  SaveDealInfo;
  SaveTechParameters;
  SaveSafe;
  SaveCalcParameters;
  SaveDateTime;
  SaveProjectView;
end;

procedure TProjectPropertiesForm.InitDealPay;
begin
  leContractPrice.Text := FloatToStr(FProjProperties.ContractPrice);
  leContractPrice.ReadOnly := (FProjProperties.PhaseCount > 1) or ((FProjProperties.PhaseCount = 1) and (FProjProperties.AuditStatus <> 0));
  SetWindowLong(leContractPrice.Handle, GWL_STYLE, GetWindowLong(leContractPrice.Handle, GWL_STYLE) or ES_RIGHT);

  leStartedSubsist.Text := FloatToStr(FProjProperties.StartedSubsisit);
  leStartedSubsist.ReadOnly := (FProjProperties.PhaseCount > 1) or ((FProjProperties.PhaseCount = 1) and (FProjProperties.AuditStatus <> 0));
  SetWindowLong(leStartedSubsist.Handle, GWL_STYLE, GetWindowLong(leStartedSubsist.Handle, GWL_STYLE) or ES_RIGHT);

  leMaterialSubsist.Text := FloatToStr(FProjProperties.MaterialSubsist);
  leMaterialSubsist.ReadOnly := (FProjProperties.PhaseCount > 1) or ((FProjProperties.PhaseCount = 1) and (FProjProperties.AuditStatus <> 0));
  SetWindowLong(leMaterialSubsist.Handle, GWL_STYLE, GetWindowLong(leMaterialSubsist.Handle, GWL_STYLE) or ES_RIGHT);
end;

procedure TProjectPropertiesForm.SaveDealPay;
begin
  if (FProjProperties.PhaseCount > 1) or ((FProjProperties.PhaseCount = 1) and (FProjProperties.AuditStatus <> 0)) then Exit;
  FProjProperties.ContractPrice := StrToFloatDef(leContractPrice.Text, 0);
  FProjProperties.StartedSubsisit := StrToFloatDef(leStartedSubsist.Text, 0);
  FProjProperties.MaterialSubsist := StrToFloatDef(leMaterialSubsist.Text, 0);
  FProjectData.DealPaymentData.CalcStarted_RangePrice;
  if FProjectData.PhaseData.Active then
    FProjectData.PhaseData.PhasePayData.CalculateAll;                              
end;

procedure TProjectPropertiesForm.leContractPriceClick(Sender: TObject);
begin
  if not TLabeledEdit(Sender).ReadOnly then
    TLabeledEdit(Sender).SelectAll;
end;

procedure TProjectPropertiesForm.msbBaseMouseWheel(Sender: TObject;
  Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint;
  var Handled: Boolean);
begin
  ResetContentsCheck;
end;

procedure TProjectPropertiesForm.msbBaseMouseWheelDown(Sender: TObject;
  Shift: TShiftState; MousePos: TPoint; var Handled: Boolean);
begin
  SendMessage(msbBase.Handle,WM_VSCROLL,SB_LINEDOWN, 0);
end;

procedure TProjectPropertiesForm.msbBaseMouseWheelUp(Sender: TObject;
  Shift: TShiftState; MousePos: TPoint; var Handled: Boolean);
begin
  SendMessage(msbBase.Handle,WM_VSCROLL,SB_LINEUP, 0);
end;

procedure TProjectPropertiesForm.ResetContentsCheck(ATag: Integer);
begin
  tobtnDealInfo.Down := tobtnDealInfo.Tag = ATag;
  tobtnTechParameters.Down := tobtnTechParameters.Tag = ATag;
  tobtnDealPayment.Down := tobtnDealPayment.Tag = ATag;
  tobtnSafe.Down := tobtnSafe.Tag = ATag;
  tobtnCalcParameters.Down := tobtnCalcParameters.Tag = ATag;
  tobtnDateTime.Down := tobtnDateTime.Tag = ATag;
end;

procedure TProjectPropertiesForm.msbBaseVScroll(Sender: TObject);
begin
  ResetContentsCheck;
end;

procedure TProjectPropertiesForm.ResetContentsCheck;
begin
  if msbBase.VertScrollBar.Position < 523 then
    ResetContentsCheck(tobtnDealInfo.Tag)
  else if msbBase.VertScrollBar.Position < 683 then
    ResetContentsCheck(tobtnTechParameters.Tag)
  else if msbBase.VertScrollBar.Position < 796 then
    ResetContentsCheck(tobtnDealPayment.Tag)
  else if msbBase.VertScrollBar.Position < 926 then
    ResetContentsCheck(tobtnSafe.Tag)
  else if msbBase.VertScrollBar.Position < 1101 then
    ResetContentsCheck(tobtnCalcParameters.Tag)
  else
    ResetContentsCheck(tobtnDateTime.Tag);
end;

procedure TProjectPropertiesForm.tobtnDealInfoClick(Sender: TObject);
begin
  ResetContentsCheck(TToolButton(Sender).Tag);
  ResetVertScrollBarPosition(TToolButton(Sender).Tag);
end;

procedure TProjectPropertiesForm.ResetVertScrollBarPosition(ATag: Integer);
begin
  if ATag = tobtnDealInfo.Tag then
    msbBase.VertScrollBar.Position := 0
  else if ATag = tobtnTechParameters.Tag then
    msbBase.VertScrollBar.Position := 523
  else if ATag = tobtnDealPayment.Tag then
    msbBase.VertScrollBar.Position := 683
  else if ATag = tobtnSafe.Tag then
    msbBase.VertScrollBar.Position := 796
  else if ATag = tobtnCalcParameters.Tag then
    msbBase.VertScrollBar.Position := 926
  else if ATag = tobtnDateTime.Tag then
    msbBase.VertScrollBar.Position := 1101;
end;

procedure TProjectPropertiesForm.InitDealInfo;
begin
  leProjectName.Text := FProjProperties.ProjectName;
  leDealName.Text := FProjProperties.DealName;
  leDealIndex.Text := FProjProperties.DealIndex;
  leDealType.Text := FProjProperties.DealType;
  leBName.Text := FProjProperties.BName;
  leBLegal.Text := FProjProperties.BLegal;
  leBDate.Text := FProjProperties.BDate;
  leCName.Text := FProjProperties.CName;
  leCLegal.Text := FProjProperties.CLegal;
  leCDate.Text := FProjProperties.CDate;
  leCName_2.Text := FProjProperties.CName_2;
  leCLegal_2.Text := FProjProperties.CLegal_2;
  leCDate_2.Text := FProjProperties.CDate_2;
  leSName.Text := FProjProperties.SName;
  leSLegal.Text := FProjProperties.SLegal;
  leSDate.Text := FProjProperties.SDate;
  leSName_2.Text := FProjProperties.SName_2;
  leSLegal_2.Text := FProjProperties.SLegal_2;
  leSDate_2.Text := FProjProperties.SDate_2;
end;

procedure TProjectPropertiesForm.InitTechParameters;
begin
  cbLoadLevel.ItemIndex := FProjProperties.LoadLevel;
  leStartPeg.Text := FProjProperties.StartPeg;
  leEndPeg.Text := FProjProperties.EndPeg;
  leLength.Text := FloatToStr(FProjProperties.LoadLength);
  leLaneCount.Text := IntToStr(FProjProperties.LaneCount);
  leDealPhase.Text := FProjProperties.DealPhase;
end;

procedure TProjectPropertiesForm.SaveDealInfo;
begin
  FProjProperties.ProjectName := leProjectName.Text;
  FProjProperties.DealName := leDealName.Text;
  FProjProperties.DealIndex := leDealIndex.Text;
  FProjProperties.DealType := leDealType.Text;
  FProjProperties.BName := leBName.Text;
  FProjProperties.BLegal := leBLegal.Text;
  FProjProperties.BDate := leBDate.Text;
  FProjProperties.CName := leCName.Text;
  FProjProperties.CLegal := leCLegal.Text;
  FProjProperties.CDate := leCDate.Text;
  FProjProperties.CName_2 := leCName_2.Text;
  FProjProperties.CLegal_2 := leCLegal_2.Text;
  FProjProperties.CDate_2 := leCDate_2.Text;
  FProjProperties.SName := leSName.Text;
  FProjProperties.SLegal := leSLegal.Text;
  FProjProperties.SDate := leSDate.Text;
  FProjProperties.SName_2 := leSName_2.Text;
  FProjProperties.SLegal_2 := leSLegal_2.Text;
  FProjProperties.SDate_2 := leSDate_2.Text;
end;

procedure TProjectPropertiesForm.SaveTechParameters;
begin
  FProjProperties.LoadLevel := cbLoadLevel.ItemIndex;
  FProjProperties.StartPeg := leStartPeg.Text;
  FProjProperties.EndPeg := leEndPeg.Text;
  FProjProperties.LoadLength := StrToFloatDef(leLength.Text, 0);
  FProjProperties.LaneCount := StrToIntDef(leLaneCount.Text, 0);
  FProjProperties.DealPhase := leDealPhase.Text;
end;

procedure TProjectPropertiesForm.tobtnBaseClick(Sender: TObject);

  procedure ResetTopButtonDown(ATag: Integer);
  begin
    tobtnBase.Down := tobtnBase.Tag = ATag;
    tobtnStaff.Down := tobtnStaff.Tag = ATag;
    tobtnView.Down := tobtnView.Tag = ATag;
  end;

begin
  ResetTopButtonDown(TToolButton(Sender).Tag);
  jpsProperties.ActivePageIndex := TToolButton(Sender).Tag;
  jcbPhase.Visible := TToolButton(Sender).Tag = tobtnStaff.Tag;
end;

procedure TProjectPropertiesForm.InitStaffRela;
var
  I: Integer;
begin
  tobtnStaff.Enabled := FProjectData.PhaseIndex > 0;
  zaStaff.DataSet := FProjectData.StaffData.cdsStaffView;
  jcbPhase.Items.Clear;
  for I := 1 to FProjectData.ProjProperties.PhaseCount do
    jcbPhase.Items.Add(Format('第 %d 期', [I]));
  jcbPhase.ItemIndex := FProjectData.ProjProperties.PhaseCount - 1;
end;

procedure TProjectPropertiesForm.SetProjectData(const Value: TProjectData);
begin
  FProjectData := Value;
  FStaffData := FProjectData.StaffData;
  FProjProperties := FProjectData.ProjProperties;
  InitAllPage;
  msbBase.VertScrollBar.Position := 0;
  jpsProperties.ActivePage := jpsPropertiesBase;
end;

procedure TProjectPropertiesForm.jcbPhaseChanged(Sender: TObject);
begin
  FStaffData.ResetViewFilter(jcbPhase.ItemIndex + 1);
end;

procedure TProjectPropertiesForm.zgStaffCellGetColor(Sender: TObject;
  ACoord: TPoint; var AColor: TColor);
begin
  if FStaffData.cdsStaff.FindKey([jcbPhase.ItemIndex + 1, ACoord.Y - zgStaff.FixedRowCount]) then
    if FStaffData.cdsStaffEnable.AsBoolean then
      AColor := clWindow
    else
      AColor := $DCDCDC;
end;

procedure TProjectPropertiesForm.zgStaffCellGetFont(Sender: TObject;
  ACoord: TPoint; AFont: TFont);
begin
  if FStaffData.cdsStaff.FindKey([jcbPhase.ItemIndex + 1, ACoord.Y - zgStaff.FixedRowCount]) then
    if not FStaffData.cdsStaffLocked.AsBoolean and FStaffData.cdsStaffEnable.AsBoolean then
      AFont.Color := clWindowText
    else
      AFont.Color := $A9A9A9;
end;

procedure TProjectPropertiesForm.zgStaffCellCanEdit(Sender: TObject;
  const ACoord: TPoint; var Allow: Boolean);
begin
  if ACoord.X < 2 then Allow := False;
  if FStaffData.cdsStaff.FindKey([jcbPhase.ItemIndex + 1, ACoord.Y - zgStaff.FixedRowCount]) then
    Allow := Allow and not FStaffData.cdsStaffLocked.AsBoolean and FStaffData.cdsStaffEnable.AsBoolean;
end;

procedure TProjectPropertiesForm.InitSafe;
var
  bHasPassword: Boolean;
begin
  bHasPassword := FProjProperties.UnlockInfoPassword <> '';
  pnlOrgPW.Visible := bHasPassword;
  leNewUnLockPassword.ReadOnly := bHasPassword;
end;

procedure TProjectPropertiesForm.SaveSafe;
begin
  if leUnlockPassword.Text = FProjProperties.UnlockInfoPassword then
    if leNewUnLockPassword.Text = leNewUnlockPasswordAgain.Text then
      FProjProperties.UnlockInfoPassword := leNewUnLockPassword.Text
    else ErrorMessage('两次密码输入不一致，密码修改不成功！')
  else if leUnlockPassword.Text <> '' then
    ErrorMessage('原密码输入错误，密码修改不成功！');
end;

procedure TProjectPropertiesForm.leUnlockPasswordKeyPress(Sender: TObject;
  var Key: Char);
begin
  CheckValidKey(Key);
end;

procedure TProjectPropertiesForm.CheckValidKey(var AKey: Char);
begin
  if not (AKey in ['A'..'Z', 'a'..'z', '0'..'9', #8]) then
    AKey := #0;
end;

procedure TProjectPropertiesForm.leNewUnlockPasswordAgainExit(
  Sender: TObject);
begin
  CheckNewPasswordAgain;
end;

procedure TProjectPropertiesForm.leNewUnLockPasswordExit(Sender: TObject);
begin
  CheckNewPassword;
  if leNewUnlockPasswordAgain.Text <> '' then
    CheckNewPasswordAgain;
end;

procedure TProjectPropertiesForm.CheckNewPassword;
var
  bValid: Boolean;
begin
  bValid := CheckValidPassword(leNewUnLockPassword.Text);
  imgNew.Visible := not bValid;
  if not bValid then
    lblPasswordHint.Caption := leNewUnLockPassword.Hint;
  lblPasswordHint.Visible := not bValid;
  leNewUnlockPasswordAgain.ReadOnly := not bValid;
end;

procedure TProjectPropertiesForm.CheckNewPasswordAgain;
var
  bValid: Boolean;
begin
  bValid := not(CheckValidPassword(leNewUnLockPassword.Text)
      and (leNewUnlockPasswordAgain.Text <> leNewUnLockPassword.Text));
  imgNewAgain.Visible := not bValid;
  if not bValid then
    lblPasswordHint.Caption := leNewUnlockPasswordAgain.Hint;
  lblPasswordHint.Visible := not bValid;
end;

procedure TProjectPropertiesForm.leUnlockPasswordExit(Sender: TObject);
begin
  CheckOrgPassword;
end;

procedure TProjectPropertiesForm.CheckOrgPassword;
var
  bValid: Boolean;
begin
  bValid := CheckValidPassword(leUnlockPassword.Text);
  imgOrg.Visible := not bValid;
  if not bValid then
    lblPasswordHint.Caption := leUnlockPassword.Hint;
  lblPasswordHint.Visible := not bValid;
  leNewUnLockPassword.ReadOnly := not bValid;
end;

procedure TProjectPropertiesForm.SaveCalcParameters;
begin
  if FProjProperties.PhaseCount = 0 then
  begin
    FProjProperties.QuantityDigit := udQuantity.Position;
    FProjProperties.TotalPriceDigit := udTotalPrice.Position;
    FProjectData.ResetFloatDigitView;
    FProjProperties.DecimalManager.Common.Quantity.Digit := udQuantity.Position;
    FProjProperties.DecimalManager.Common.TotalPrice.Digit := udTotalPrice.Position;
    FProjProperties.DecimalManager.PriceMargin.Quantity.Digit := udQuantity.Position;
    FProjProperties.DecimalManager.PriceMargin.TotalPrice.Digit := udTotalPrice.Position;

    FProjProperties.DealPayAloneDigit := cbDealPayAloneDigiy.Checked;
    FProjProperties.DecimalManager.DealPay.TotalPrice.Digit := udDealPayTotalPriceDigit.Position;
  end;
  if (FProjProperties.PhaseCount = 1) and not FProjectData.PriceMarginReadOnly then
    FProjProperties.DecimalManager.PriceMargin.Price.Digit := udPM_PriceDigit.Position;
end;

procedure TProjectPropertiesForm.InitCalcParameters;
begin
  udQuantity.Position := FProjProperties.QuantityDigit;
  leQuantityDigit.ReadOnly := FProjProperties.PhaseCount > 0;
  udQuantity.Enabled := FProjProperties.PhaseCount = 0;
  udTotalPrice.Position := FProjProperties.TotalPriceDigit;
  leTotalPriceDigit.ReadOnly := FProjProperties.PhaseCount > 0;
  udTotalPrice.Enabled := FProjProperties.PhaseCount = 0;

  udPM_PriceDigit.Position := FProjProperties.DecimalManager.PriceMargin.Price.Digit;
  lePM_PriceDigit.ReadOnly := FProjectData.PriceMarginReadOnly and (FProjProperties.PhaseCount > 1);
  udPM_PriceDigit.Enabled := not lePM_PriceDigit.ReadOnly;

  cbDealPayAloneDigiy.Checked := FProjProperties.DealPayAloneDigit;
  cbDealPayAloneDigiy.Enabled := FProjProperties.PhaseCount = 0;

  udDealPayTotalPriceDigit.Position := FProjProperties.DecimalManager.DealPay.TotalPrice.Digit;
  leDealPayTotalPriceDigit.ReadOnly := (FProjProperties.PhaseCount > 0);
  leDealPayTotalPriceDigit.Enabled := cbDealPayAloneDigiy.Checked;
  udDealPayTotalPriceDigit.Enabled := (FProjProperties.PhaseCount = 0) and cbDealPayAloneDigiy.Checked;
end;

procedure TProjectPropertiesForm.SaveProjectView;
begin
  FProjProperties.ShowReportShading := cbShowReportShading.Checked;
  FProjProperties.ReportShading := edtReportShading.Text;

  FProjProperties.ReportShowState := cbReportShowState.Checked;
  FProjProperties.ReportShowStateText := edtReportShowStateText.Text;
  FProjProperties.ReportShowStateWithoutReply := cbReportShowStageWithoutReply.Checked;

  FProjProperties.ShowPriceChange := cbShowPriceChange.Checked;
  FProjProperties.ShowBGLCode := cbShowBGLCode.Checked;
  FProjProperties.ShowDesignQuantity := cbShowDesignQuantity.Checked;
  FProjProperties.ShowAlias := cbShowAlias.Checked;
  FProjProperties.ShowOverRange := cbShowOverRange.Checked;
  FProjProperties.ShowApprovalCode := cbShowApprovalCode.Checked;
  // 刷新界面显示
  FProjectFrame.RefreshColumnDisplay;
end;

procedure TProjectPropertiesForm.cbShowReportShadingClick(Sender: TObject);
begin
  edtReportShading.Enabled := cbShowReportShading.Checked;
end;

procedure TProjectPropertiesForm.InitDateTime;
var
  fs: TFormatSettings;
begin
  GetLocaleFormatSettings(GetUserDefaultLCID, fs);
  fs.DateSeparator := '-';
  fs.ShortDateFormat := dtpBaseline.Format;
  dtpBaseline.Date := StrToDateDef(ProjProperties.Baseline, Date, fs);
  dtpDeadline.Date := StrToDateDef(ProjProperties.Deadline, Date, fs);
  CheckDate;
end;

procedure TProjectPropertiesForm.SaveDateTime;
begin
  ProjProperties.Baseline := FormatDateTime(dtpBaseline.Format, dtpBaseline.Date);
  ProjProperties.Deadline := FormatDateTime(dtpDeadline.Format, dtpDeadline.Date);
end;

procedure TProjectPropertiesForm.CheckDate;
var
  iBaseline, iDeadline: Integer;
begin
  iBaseline := Trunc(dtpBaseline.Date);
  iDeadline := Trunc(dtpDeadline.Date);
  lblDateHint.Visible := iBaseline > iDeadline;
end;

procedure TProjectPropertiesForm.dtpBaselineChange(Sender: TObject);
begin
  CheckDate;
end;

procedure TProjectPropertiesForm.cbDealPayAloneDigiyClick(Sender: TObject);
begin
  leDealPayTotalPriceDigit.ReadOnly := (FProjProperties.PhaseCount > 0);
  leDealPayTotalPriceDigit.Enabled := cbDealPayAloneDigiy.Checked;
  udDealPayTotalPriceDigit.Enabled := (FProjProperties.PhaseCount = 0) and cbDealPayAloneDigiy.Checked;
end;

procedure TProjectPropertiesForm.cbReportShowStateClick(Sender: TObject);
begin
  cbReportShowStageWithoutReply.Enabled := cbReportShowState.Checked;
  if cbReportShowState.Checked then
    cbReportShowStageWithoutReply.Checked := True;
  edtReportShowStateText.Enabled := cbReportShowState.Checked;
end;

end.
