using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace LYFZ.Software.MainBusiness.FinancialManagement.OtherIncome
{
    public partial class FrmOtherIncomeEntry : LYFZ.Software.UI.FinancialManagement.OtherIncome.FrmOtherIncomeEntry
    {
        LYFZ.BLL.BLL_ErpOtherIncomeAndExpenses oiebll = new BLL.BLL_ErpOtherIncomeAndExpenses();
        public FrmOtherIncomeEntry()
        {

        }
        /// <summary>
        /// 是否保存
        /// </summary>
        public bool IsSaveed = false;
        /// <summary>
        /// 窗体加载事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected override void FrmOtherIncomeEntry_Load(object sender, EventArgs e)
        {
            LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.BindComboBoxTreeView_PaymentMethod(this.cmbPay_PaymentMethod, IsShowAll: false);
            this.txtOiae_IEDatetime.Text = SDateTime.Now.ToString();
            this.txtOiae_PersonHandling.Text = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_Name;

            ///控制财务管理扫码支付的版本权
            List<Control> hideControl = new List<Control>();
            hideControl.Add(cmbPay_PaymentMethod);
            LYFZ.Software.MainBusiness.VersionControl.StaticVersion.BindVersionShowHideControl(VersionControl.VersionFunctionEnum.财务管理扫码支付, hideControl, null, null);
        }
        /// <summary>
        /// 设置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected override void btnSet_Click(object sender, EventArgs e)
        {
            LYFZ.Software.MainBusiness.InitialSet.FrmSystemSet set = new InitialSet.FrmSystemSet();
            set.TypeName = "BEBACCAFCCEAGAIHH";
            set.Version = "Version";
            if (set.ShowDialog() == DialogResult.OK)
            { LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.BindComboBoxTreeView_PaymentMethod(this.cmbPay_PaymentMethod, IsShowAll: false); }
        }
        /// <summary>
        /// 输入框设置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected override void txtOiae_Money_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!Char.IsNumber(e.KeyChar) && !Char.IsPunctuation(e.KeyChar) && !Char.IsControl(e.KeyChar))
            { e.Handled = true; }
            else if (Char.IsPunctuation(e.KeyChar))
            {
                if (e.KeyChar == '.')
                {
                    if (((System.Windows.Forms.TextBox)sender).Text.LastIndexOf('.') != -1)
                    { e.Handled = true; }
                }
                else
                { e.Handled = true; }
            }
        }
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected override void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                #region 判断不能为空
                if (string.IsNullOrEmpty(this.txtOiae_ThePayer.Text))
                { MessageBoxCustom.Show("付款人不能为空!"); return; }
                if (string.IsNullOrEmpty(this.txtOiae_ProjectName.Text))
                { MessageBoxCustom.Show("项目名称不能为空!"); return; }
                if (string.IsNullOrEmpty(this.txtOiae_Money.Text))
                { MessageBoxCustom.Show("金额不能为空!"); return; }
                if (string.IsNullOrEmpty(this.cmbPay_PaymentMethod.Text))
                { MessageBoxCustom.Show("支付方式不能为空!"); return; }
                if (string.IsNullOrEmpty(this.txtOiae_IEDatetime.DateValue))
                { MessageBoxCustom.Show("日期不能为空!"); return; }
                if (string.IsNullOrEmpty(this.txtOiae_PersonHandling.Text))
                { MessageBoxCustom.Show("经手人不能为空!"); return; }
                #endregion

                #region 2017-03-24 杨云奕 添加 判断是否接入微信支付宝的接口
                FinancialPayApiControl PayApi = new FinancialPayApiControl();
                int intCode = PayApi.PayApiControl("其他收入", this.cmbPay_PaymentMethod.Text.Trim(), Convert.ToDecimal(this.txtOiae_Money.Text));
                string serialnumber = "";
                if (intCode == 1)
                {
                    serialnumber = PayApi.SerialNumber;
                }
                else if (intCode == -1)
                {
                    //MessageBoxCustom.Show("取消微信刷卡支付,保存取消");
                    return;
                }
                #endregion

                LYFZ.Model.Model_ErpOtherIncomeAndExpenses model = new Model.Model_ErpOtherIncomeAndExpenses();
                model.Oiae_DividedShop = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetLocalCompanyInfoID();
                model.Oiae_Type = "收入";
                model.Oiae_SerialNumber = serialnumber;
                model.Oiae_ProjectName = this.txtOiae_ProjectName.Text;
                model.Oiae_Money = Convert.ToDecimal(this.txtOiae_Money.Text);
                model.Oiae_IEDatetime = Convert.ToDateTime(this.txtOiae_IEDatetime.DateTimeValue);
                model.Oiae_PersonHandling = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID;
                model.Oiae_ThePayer = this.txtOiae_ThePayer.Text;
                model.Oiae_Invoice = "";
                model.Oiae_SourceType = 0;
                model.Oiae_OrderNumber = "";
                model.Oiae_Remark = this.txtOiae_Remark.Text;
                model.Oiae_CreateDateTime = SDateTime.Now;
                model.Oiae_PaymentMethod = this.cmbPay_PaymentMethod.Tag.ToString();
                model.Oiae_FinancialAuditState = "未审核";
                model.Oiae_ManagerAuditState = "未审核";
                model.Oiae_CEOAuditState = "未审核";
                if (oiebll.Add(model))
                {
                    MessageBoxCustom.Show("保存成功!可继续录入资料!");
                    this.txtOiae_ThePayer.Text = "";
                    this.txtOiae_ProjectName.Text = "";
                    this.txtOiae_Money.Text = "";
                    this.cmbPay_PaymentMethod.Text = "";
                    this.txtOiae_Remark.Text = "";
                    this.txtOiae_IEDatetime.Text = SDateTime.Now.ToString();
                    this.txtOiae_PersonHandling.Text = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_Name;
                    this.txtOiae_IEDatetime.Enabled = false;
                    this.IsSaveed = true;
                }
                else
                { MessageBoxCustom.Show("保存失败!"); }
            }
            catch (Exception ex)
            { MessageBoxCustom.Show(ex.Message); }
        }
        /// <summary>
        /// 取消
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected override void btnCanle_Click(object sender, EventArgs e)
        { this.Close(); }
        /// <summary>
        /// 修改时间
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected override void btnUpdateTime_Click(object sender, EventArgs e)
        {
            if (LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.OrdersReceivablesCompetence, CustomAttributes.OperatingAuthority.UpdatePaymentTime))
            { this.txtOiae_IEDatetime.Enabled = true; }
            else
            {
                LYFZ.Software.MainBusiness.DoorCityProcess.SuperSmallForm.AuthorizeLoginSuperSmallForm frm = new DoorCityProcess.SuperSmallForm.AuthorizeLoginSuperSmallForm("OrdersReceivablesCompetence", CustomAttributes.OperatingAuthority.UpdatePaymentTime);
                if (frm.ShowDialog() == DialogResult.OK)
                {
                    if (LYFZ.BLL.BLL_ErpUser.GetRights(frm.CurrentAuthorizeUserRights.OrdersReceivablesCompetence, CustomAttributes.OperatingAuthority.UpdatePaymentTime, frm.User_BelongRoles))
                    {
                        frm.SetAuthorizationResult();
                        this.txtOiae_IEDatetime.Enabled = true;
                    }
                    else {
                        frm.SetAuthorizationResult(String.Format("授权失败,授权人没有'{0}'权限", LYFZ.Software.MainBusiness.DoorCityProcess.SuperSmallForm.AuthorizeLoginSuperSmallForm.ConvertEnumToDescription(CustomAttributes.OperatingAuthority.UpdatePaymentTime).ToString()));
                    }
                }
            }
        }
    }
}