using com.hnshituo.core.webapp.vo;
using Common;
using Infragistics.Win;
using Infragistics.Win.UltraWinGrid;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace RailMeterSystem
{
    public partial class frmMotoriaTareSave : Form
    {
        public frmMotoriaTareSave()
        {
            InitializeComponent();
        }

        private void frmMotoriaTareSave_Load(object sender, EventArgs e)
        {
            txtCarNum.Value = iCnt;
            txtWgtPj.Value = (decimal)getDt.railwayWeight.Value;
            txtWgt.Value = (decimal)dWgt;

            ValueList vlistSpot = new ValueList();
            vlistSpot.ValueListItems.Add("001019002", "动态轨道衡");
            cbSpotType.ValueList = vlistSpot;
            cbSpotType.Value = "001019002";

            //cbCalibrationType
            string sql = @"SELECT base_code baseCode,base_name baseName,memo FROM Com_Base_Info where p_base_code='001032' and valid_Flag='1' and memo='" + getDt.tareType + "'";
            PbModelDbService<List<ComBaseInfo>> pb = new PbModelDbService<List<ComBaseInfo>>();
            RESTfulResult<List<ComBaseInfo>> rmType = pb.executeSqlDataWf(sql);
            if (rmType.Succeed && rmType.Data != null && rmType.Data.Count > 0)
            {
                ValueList vlist = new ValueList();
                foreach (ComBaseInfo cbi in rmType.Data) 
                {
                    vlist.ValueListItems.Add(cbi.baseCode, cbi.baseName);
                }
                cbCalibrationType.ValueList = vlist;

                cbCalibrationType.SelectedIndex = 0;
            }
            else
            {
                MessageBox.Show("留皮类型获取失败!");
            }
        }

        public MeterBaseRailwayWeight getDt { get; set; }
        public decimal dWgt = 0;
        public int iCnt = 0;

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        MeterBaseRailwayWeightService baseRailwayWgt = new MeterBaseRailwayWeightService();
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (cbCalibrationType.Text.Trim() == "" || cbCalibrationType.Value == null)
            {
                MessageBox.Show("请选择留皮类型");
                return;
            }

            DialogResult dr = MessageBox.Show("确认进行保存吗？", "提示", MessageBoxButtons.OKCancel);
            if (dr == DialogResult.OK)
            {
                getDt.tareTypeNo = cbCalibrationType.Value.ToString();
                getDt.tareTypeName = cbCalibrationType.Text.Trim();
                getDt.railwayWeight = txtWgtPj.Value * 1000;
                btnSave.Enabled = false;
                List<MeterBaseRailwayWeight> lt = new List<MeterBaseRailwayWeight>();
                lt.Add(getDt);
                RESTfulResult<string> rm = baseRailwayWgt.doSaveWf(lt);

                if (rm.Succeed)
                {
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
                else
                {
                    MessageBox.Show("保存失败，请稍后重试或联系管理员" + rm.Message);
                    btnSave.Enabled = true;
                }
            }
        }


    }
}
