⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit_frontcheck.pas

📁 用delphi开发的美容院管理系统
💻 PAS
📖 第 1 页 / 共 2 页
字号:
procedure Tfrm_frontcheck.SpeedButton6Click(Sender: TObject);
begin
  DoServiceMeal;
  if sg_Meal.RowCount >=2 then sbtn_addEmp2.Enabled :=true;
end;

procedure Tfrm_frontcheck.SpeedButton7Click(Sender: TObject);
begin
  if sg_Meal.cells[0,sg_Meal.row]='' then exit;

  if (MessageBox(handle,'你确认删除该服务套餐吗?','询问',mb_yesno+mb_iconinformation))<>IDYes then exit;
  
  StringGridDelete(sg_Meal,sg_Meal.row);

  if sg_Meal.RowCount <=2 then sbtn_addEmp2.Enabled :=false;
  
  ComputeCostsum;
end;

procedure Tfrm_frontcheck.sbtn_saveClick(Sender: TObject);
var
  temp,temp_costno,temp_detailno,temp_changeno,temp_reminder,temp_typeid:string;
  i:integer;
  temp_mincost:double;
begin
  {************************************************************************************************}

  if (edt_CostSum.Text ='') or (edt_DiscountSum.Text ='') then
  begin
    MessageBox(handle,'顾客没有进行消费或者消费金额格式不对,请重试!','提示',mb_ok+mb_iconinformation);
    exit;
  end;

  if radiogroup1.itemindex=0 then
  if(edt_Payment.Text='') or (edt_change.Text='') then
  begin
    MessageBox(handle,'已经收入金额没有输入,请重试!','提示',mb_ok+mb_iconinformation);
    exit;
  end;

  for i:=1 to sg_Item.rowcount-2 do
  begin
    if (sg_Item.Cells[0,i]<>'') and (sg_Item.Cells[3,i]='') then
    begin
      MessageBox(handle,'请选择提供服务的员工编号!','提示',mb_ok+mb_iconinformation);
      exit;
    end;
  end;

  for i:=1 to sg_Meal.rowcount-2 do
  begin
    if (sg_Meal.Cells[0,i]<>'') and (sg_Meal.Cells[3,i]='') then
    begin
      MessageBox(handle,'请选择提供服务的员工编号!','提示',mb_ok+mb_iconinformation);
      exit;
    end;
  end;

  if radiogroup1.ItemIndex =1 then
  if StrToFloat(edt_CostMoney.Text)>StrToFloat(edt_Curcurrency.Text) then
  begin
    MessageBox(handle,'卡内金额不足以支付本次消费,请先充值!','提示',mb_ok+mb_iconinformation);
    exit;
  end;
  {************************************************************************************************}
  //进行用户验证
  if radiogroup1.ItemIndex =1 then
    begin
      if edt_Password.Text ='' then begin MessageBox(handle,'请输入用户密码,进行用户验证!','提示',mb_ok+mb_iconinformation); edt_password.SetFocus ;exit; end;

      with dmod.qrydata do
      begin
        close;
        SQL.Text :='select password from CustomerCard where card_no='+#39+trim(edt_CardNo.Text)+#39;
        Open;
        if trim(edt_password.Text)<>FieldByName('password').AsString then
        begin
          MessageBox(self.handle,'用户密码验证失败,请重试!','提示',mb_ok+mb_iconinformation);
          edt_password.SetFocus ;
          exit;
        end;
    end;
  end;

  try
    dmod.Database.StartTransaction ;
    with dmod.qrydata do
    begin
      //插入消费记录到CustomerCost;
      temp := GetDateString('DBMeirong');
      temp := copy(temp,1,4) + copy(temp,6,2) + copy(temp,9,2);
      temp_costno := GetNo('DBMeirong','CustomerCost','','','cost_no',temp,2);

      Close;
      SQL.Text :='insert into CustomerCost(cost_no,cus_no,emp_no,cost_sum,discount,discount_sum,payment,change,check_type,cost_date) '+
                 ' values(:costno,:cusno,:empno,:costsum,:discount,:discountsum,:payment,:change,:checktype,:costdate)';
      ParamByName('costno').AsString := temp_costno;
      if trim(edt_CusNo1.Text)<>'' then
         ParamByName('cusno').AsString  := trim(edt_CusNo1.Text)
      else
         ParamByName('cusno').AsString  := '散客';
      ParamByName('empno').AsString := edt_Empno.Text ;
      ParamByName('costsum').AsFloat := StrToFloat(trim(edt_CostSum.Text));
      ParamByName('discount').AsFloat := StrToFloat(trim(edt_Discount.Text));
      ParamByName('discountsum').AsFloat := StrToFloat(trim(edt_DiscountSum.Text));
      if radiogroup1.itemindex=0 then begin
        ParamByName('payment').AsFloat := StrToFloat(trim(edt_Payment.text));
        ParamByName('change').AsFloat := StrToFloat(trim(edt_Change.Text));
        ParamByName('checktype').AsString:='0';
      end else if radiogroup1.ItemIndex =1 then begin
        ParamByName('payment').AsFloat := StrToFloat(trim(edt_CardMoney.text));
        ParamByName('change').AsFloat := StrToFloat(trim(edt_LatestMoney.Text));
        ParamByName('checktype').AsString:='1';
      end;

      ParamByName('costdate').AsDate := Date;
      ExecSQL;

      //如果用现金消费,更新顾客卡中的消费总额和消费积分,散客消费者不进行更新
      if (trim(edt_CusNo1.Text)<>'0000000001') and (radiogroup1.itemindex=0) then
      begin
        Close;
        SQL.Text :='update CustomerCard set total_cost=total_cost+'+#39+trim(edt_DiscountSum.Text)+#39+
                   ',cost_score=cost_score+'+#39+trim(edt_DiscountSum.Text)+#39+
                   ' where cus_no='+#39+trim(edt_CusNo1.Text)+#39;
        ExecSQL;
      end;

      //如果用顾客卡消费,更新顾客卡中的消费总额、消费积分和最新余额、散客消费者不进行更新
      //并且将顾客卡金额的变动记录到表CustomerCardCurrencyChange
      if (trim(edt_CusNo1.Text)<>'0000000001') and (radiogroup1.itemindex=1) then
      begin
        Close;
        SQL.Text :='update CustomerCard set total_cost=total_cost+'+#39+trim(edt_DiscountSum.Text)+#39+
                   ',cost_score=cost_score+'+#39+trim(edt_DiscountSum.Text)+#39+
                   ',cur_currency=cur_currency-'+#39+trim(edt_CostMoney.text)+#39+
                   ' where cus_no='+#39+trim(edt_CusNo1.Text)+#39;
        ExecSQL;

        temp_changeno:= GetNo('DBMeirong','CustomerCardCurrencyChange','','','change_no',temp,2);

        Close;
        SQL.text:='insert into CustomerCardCurrencyChange(change_no,card_no,cus_no,emp_no,change_date,last_currency,currency_reduced,total_currency,add_or_reduced) '+
                  ' values(:changeno,:cardno,:cusno,:empno,:changedate,:lastcurrency,:currencyreduced,:totalcurrency,:addorreduced)';
        ParamByName('changeno').AsString:=temp_changeno;
        ParamByName('cardno').AsString:=edt_CardNo.Text ;
        ParamByName('cusno').AsString:=edt_CusNo1.Text ;
        ParamByName('empno').AsString:=edt_EmpNo.Text ;
        ParamByName('changedate').AsDate:=Date;
        ParamByName('lastcurrency').AsFloat:=StrToFloat(edt_Curcurrency.text);
        ParamByName('currencyreduced').AsFloat:=StrToFloat(trim(edt_CostMoney.Text));
        ParamByName('totalcurrency').AsFLoat:=StrToFloat(trim(edt_latestMoney.Text));
        ParamByName('addorreduced').AsString:='1';
         
        ExecSQL;
      end;


      //插入消费详细记录到CustomerCostDetail
      for i:=1 to sg_Item.RowCount-2 do
      begin
        temp_detailno := GetNo('DBMeirong','CustomerCostDetail','','','detail_no',temp,2);

        Close;
        SQL.Text :='insert into CustomerCostDetail(detail_no,cost_no,item_id,type_id,itemortype,emp_no,price) '+
                   ' values(:detailno,:costno,:itemid,:typeid,:itemortype,:empno,:price)';

        ParamByName('detailno').AsString:=temp_detailno;
        ParamByName('costno').AsString  :=temp_costno;
        ParamByName('itemid').AsString  :=sg_Item.Cells[0,i];
        ParamByName('typeid').AsString  :='';
        ParamByName('itemortype').AsString  :='0';
        ParamByName('empno').AsString   :=sg_Item.cells[3,i];
        ParamByName('price').AsFloat    :=StrToFloat(sg_Item.Cells[2,i]);

        ExecSQL;
      end;

      for i:=1 to sg_Meal.RowCount-2 do
      begin
        temp_detailno := GetNo('DBMeirong','CustomerCostDetail','','','detail_no',temp,2);

        Close;
        SQL.Text :='insert into CustomerCostDetail(detail_no,cost_no,item_id,type_id,itemortype,emp_no,price) '+
                   ' values(:detailno,:costno,:itemid,:typeid,:itemortype,:empno,:price)';
        ParamByName('detailno').AsString:=temp_detailno;
        ParamByName('costno').AsString  :=temp_costno;
        ParamByName('itemid').AsString  :='';
        ParamByName('typeid').AsString  :=sg_Meal.Cells[0,i];
        ParamByName('itemortype').AsString  :='1';
        ParamByName('empno').AsString   :=sg_Meal.cells[3,i];
        ParamByName('price').AsFloat    :=StrToFloat(sg_Meal.Cells[2,i]);

        ExecSQL;
      end;
      //判断是否自动更新用户办卡类型
      if trim(edt_CusNo1.Text)<>'0000000001' then
      begin
        Close;
        SQL.Text :='select total_cost,mincost from Customercard cc,membercardtype mct '+
                   ' where cc.card_type=mct.type_id and cus_no='+#39+trim(edt_CusNo1.Text)+#39;
        Open;
        if FieldByName('total_cost').AsFloat > FieldByName('mincost').AsFloat then
        begin
          temp_reminder:='顾客消费已达'+FloatToStr(FieldByName('total_cost').AsFloat)+',可以享受更多的优惠,需要系统自动更新其顾客卡类型吗?';
          if MessageBox(self.handle,Pchar(temp_reminder),'询问',mb_yesno+mb_iconquestion)=IDYES then
          begin
            temp_mincost:=FieldByName('mincost').AsFloat;
            Close;
            SQL.Text :='select type_id from membercardtype where mincost>'+#39+FloatToStr(temp_mincost)+#39+' order by orderby';
            Open;
            //总是得到大于mincost记录的最先一条
            if not eof then
            begin
               temp_typeid:=FieldByName('type_id').AsString;
               Close;
               SQL.Text :='update customercard set card_type='+#39+temp_typeid+#39;
               ExecSQL;
            end;
          end;
        end;
      end;
      
    end;
  finally
    try
      dmod.Database.Commit ;

      StringGridInsert(sg_CostList);
      with sg_CostList do
      begin
        cells[0,1]:=temp_costno;
        cells[1,1]:=edt_CusNo1.Text ;
        cells[2,1]:=edt_CusName.Text ;
        cells[3,1]:=edt_CostSum.Text ;
        cells[4,1]:=edt_DiscountSum.Text ;
        if radiogroup1.ItemIndex =0 then
        begin
          cells[5,1]:=edt_Payment.text;
          cells[6,1]:=edt_change.text;
        end else if radiogroup1.ItemIndex =1 then
        begin
          cells[5,1]:=edt_CardMoney.text;
          cells[6,1]:=edt_LatestMoney.text;
        end;
        cells[7,1]:=radiogroup1.Items[radiogroup1.ItemIndex];
      end;
      ClearCustomerCost;
      RefreshCustomerCost;
      if MessageBox(handle,'是否打印顾客消费凭条?','询问',mb_yesno+mb_iconquestion)=idyes then
        sbtn_printClick(nil);
    except
      dmod.Database.Rollback ;
    end;
  end;
end;

procedure Tfrm_frontcheck.edt_PaymentExit(Sender: TObject);
begin
  if edt_Payment.text='' then exit;
  edt_change.text:= FloatToStr(StrToFloat(edt_payment.text)-StrToFloat(edt_Discountsum.text));
end;

procedure Tfrm_frontcheck.edt_PaymentKeyPress(Sender: TObject;
  var Key: Char);
begin
  if key=#13 then edt_change.setfocus;
end;

procedure Tfrm_frontcheck.edt_changeKeyPress(Sender: TObject;
  var Key: Char);
begin
  if key=#13 then sbtn_saveClick(nil);
end;

procedure Tfrm_frontcheck.SpeedButton9Click(Sender: TObject);
begin
  close;
end;

procedure Tfrm_frontcheck.sbtn_addEmp1Click(Sender: TObject);
begin
  DoChooseEmployee('0');
end;

procedure Tfrm_frontcheck.sbtn_addEmp2Click(Sender: TObject);
begin
  DoChooseEmployee('0');
end;

procedure Tfrm_frontcheck.sbtn_OtherClick(Sender: TObject);
begin
  //散客特用顾客编号 
  edt_CusNo1.Text :='00000001';
  edt_CusName.Text :='散客';
  edt_CusType.Text :='无';
  edt_Discount.Text :='100';
end;

procedure Tfrm_frontcheck.RadioGroup1Click(Sender: TObject);
begin
  if radiogroup1.ItemIndex =0 then
  begin
    pnlCash.Visible :=true;
    pnlCard.Visible :=false;
  end else begin
    if (edt_CusNo1.Text ='') then
    begin
      MessageBox(handle,'无法选择,请先输入客户编号','提示',mb_ok+mb_iconinformation);
      radiogroup1.ItemIndex :=0;
      RadioGroup1Click(nil);
      exit;
    end;

    if (edt_CusNo1.Text ='0000000001') or (edt_CusName.Text ='散客') then
    begin
      MessageBox(handle,'散客无法用顾客卡进行消费','提示',mb_ok+mb_iconinformation);
      radiogroup1.ItemIndex :=0;
      RadioGroup1Click(nil);
      exit;
    end;

    if edt_CostSum.Text ='' then
    begin
      MessageBox(handle,'当前没有服务消费,无法继续','提示',mb_ok+mb_iconinformation);
      radiogroup1.ItemIndex :=0;
      RadioGroup1Click(nil);
      exit;
    end;
    
    pnlCash.Visible :=false;
    pnlCard.Visible :=true;
    
    edt_CardMoney.Text := edt_Curcurrency.Text ;
    edt_CostMoney.Text := edt_DiscountSum.Text ;
    edt_LatestMoney.Text := FloatToStr(StrToFloat(edt_Curcurrency.Text)-StrToFloat(edt_DiscountSum.Text));
  end;
end;

procedure Tfrm_frontcheck.sbtn_CardClick(Sender: TObject);
begin
  DoCardManager;
end;

procedure Tfrm_frontcheck.sbtn_AttendClick(Sender: TObject);
begin
  DoNormalAttend;
end;

procedure Tfrm_frontcheck.SpeedButton2Click(Sender: TObject);
begin
  DoChooseCustomer;
end;

procedure Tfrm_frontcheck.sbtn_printClick(Sender: TObject);
begin
  DoReportReceipt;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -