ApplyAdd.aspx.cs
上传用户:simon2hong
上传日期:2021-11-18
资源大小:16746k
文件大小:10k
- using System;
- using System.Data;
- using System.Configuration;
- using System.Collections;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- using System.Text;
- public partial class Vehicles_ApplyAdd : System.Web.UI.Page
- {
- /// <summary>
- /// 车牌号
- /// </summary>
- public string StrHtmlCPH = "";
- /// <summary>
- /// 厂牌型号
- /// </summary>
- public string StrHtmlCPXH = "";
- /// <summary>
- /// 车辆类型
- /// </summary>
- public string StrHtmlCLLX = "";
- /// <summary>
- /// 驾驶员
- /// </summary>
- public string StrHtmlJSY = "";
- /// <summary>
- /// 预定情况
- /// </summary>
- public string StrHtmlYDQK = "";
- /// <summary>
- /// 当前状态
- /// </summary>
- public string StrHtmlDQZT = "";
- /// <summary>
- /// 图片
- /// </summary>
- public string StrHtmlCLTPPath = "<center>暂无照片</center>";
- //模板
- Model.CarUse MCU = new Model.CarUse();
- Model.Cars MC = new Model.Cars();
- //业务
- BLL.CarUse BCU = new BLL.CarUse();
- BLL.Cars BC = new BLL.Cars();
- protected void Page_Load(object sender, EventArgs e)
- {
- LoginLogic.MatchLoad("../", "Vehicles_ApplyAdd");
- if (!IsPostBack)
- {
- DropLoadSet();
- }
- }
- /// <summary>
- /// 数据绑定
- /// </summary>
- public void DropLoadSet()
- {
- #region 车牌号
- KeyValue_CPH.DataTextField = "CPH";
- KeyValue_CPH.DataValueField = "Id";
- KeyValue_CPH.DataSource = EnumGet.CarNumberGetEnum();
- KeyValue_CPH.DataBind();
- ListItem linone = new ListItem();
- linone.Text = "--请选择--";
- linone.Value = "0";
- KeyValue_CPH.Items.Add(linone);
- KeyValue_CPH.SelectedIndex = KeyValue_CPH.Items.Count - 1;
- #endregion
- #region 用车部门
- KeyValue_YCBM.DataTextField = "DeptName";
- KeyValue_YCBM.DataValueField = "Id";
- KeyValue_YCBM.DataSource = EnumGet.DepartmentGetEnum();
- KeyValue_YCBM.DataBind();
- ListItem linone2 = new ListItem();
- linone2.Text = "--请选择--";
- linone2.Value = "0";
- KeyValue_YCBM.Items.Add(linone2);
- KeyValue_YCBM.SelectedIndex = KeyValue_YCBM.Items.Count - 1;
- #endregion
- #region 调度员
- KeyValue_DDY.DataTextField = "DDY";
- KeyValue_DDY.DataValueField = "Id";
- KeyValue_DDY.DataSource = EnumGet.DiaoDuYuanGetEnum();
- KeyValue_DDY.DataBind();
- ListItem linone3 = new ListItem();
- linone3.Text = "--请选择--";
- linone3.Value = "0";
- KeyValue_DDY.Items.Add(linone3);
- KeyValue_DDY.SelectedIndex = KeyValue_DDY.Items.Count - 1;
- #endregion
- #region 申请人
- KeyValue_SQR.Text = SessionInclude.SessionId;
- #endregion
- }
- public void DropLoadSet(int Id)
- {
- if (Id > 0)
- {
- MC = BC.GetModel(Id);
- StrHtmlCPH = EnumGet.GetCarNumberName(Id);
- StrHtmlCPXH = MC.CPXH;
- StrHtmlCLLX = EnumGet.GetCarTypeName(MC.CLLX);
- StrHtmlJSY = MC.JSY;
- StrHtmlYDQK = YDXX(Id);
- #region 当前状态
- //string condition = "CPH = 'lvs' and SYZT = '已准' and convert(varchar(10),KSSJ,120) = '今天' and (KSSJ < '现在时间' and JSSJ > '现在时间')";
- string condition = "CPH = '" + Id.ToString() + "' and SYZT = '" + States.SupplyState_Agree + "' and convert(varchar(10),KSSJ,120) = '" + DateTime.Now.ToString("yyyy-MM-dd") + "' and (KSSJ < '" + DateTime.Now.ToString() + "' and JSSJ > '" + DateTime.Now.ToString() + "')";
- if (BCU.GetCount(condition) > 0)
- {
- StrHtmlDQZT = States.UseState_Busy;
- }
- else
- {
- StrHtmlDQZT = States.UseState_Free;
- }
- #endregion
- #region 图片加载
- StringBuilder sb = new StringBuilder();
- if (BC.GetCount("CLTPPath = '" + MC.CLTPPath + "' and ID = " + Id.ToString()) <= 0)
- {
- sb.Append("<center>暂无照片</center>");
- StrHtmlCLTPPath = sb.ToString();
- }
- if (String.IsNullOrEmpty(MC.CLTPPath))
- {
- sb.Append("<center>暂无照片</center>");
- StrHtmlCLTPPath = sb.ToString();
- }
- else
- {
- sb.Append("<img src='upload/" + MC.CLTPPath + "' width='250' height='150' />");
- StrHtmlCLTPPath = sb.ToString();
- }
- #endregion
- }
- }
- /// <summary>
- /// 预定情况
- /// </summary>
- /// <param name="Id">车牌号ID</param>
- /// <returns></returns>
- public string YDXX(int Id)
- {
- StringBuilder sb = new StringBuilder();
- if (Id > 0)
- {
- //string condtion = "CPH = 'lvs' and SYZT = '待批' and convert(varchar(10),KSSJ,120) = '今天'";
- string condition = "CPH = '" + Id.ToString() + "' and SYZT = '" + States.SupplyState_Wait + "' and convert(varchar(10),KSSJ,120) = '" + DateTime.Now.ToString("yyyy-MM-dd") + "'";
- string Rtstr = "当前共 " + BCU.GetCount(condition).ToString() + " 条预定信息";
- //sb.Append("<a href='VehicleWait.aspx?TiaoJian=" + condition + "' title='点击查看详情'><span style='color: #0000ff; text-decoration: underline'>" + Rtstr + "</span></a>");
- if (BCU.GetCount(condition) > 0)
- {
- sb.Append("<a href='" + "VehicleWait.aspx?id=" + Id.ToString() + "' title='点击查看详情'><span style='color: #0000ff; text-decoration: underline'>" + Rtstr + "</span></a>");
- }
- else
- {
- sb.Append("<a href='#' title='点击查看详情'><span style='color: #0000ff; text-decoration: underline'>" + Rtstr + "</span></a>");
- }
- }
- else
- {
- sb.Append("");
- }
- return sb.ToString();
- }
- protected void KeyValue_CPH_SelectedIndexChanged(object sender, EventArgs e)
- {
- DropLoadSet(int.Parse(KeyValue_CPH.SelectedValue));
- }
- protected void Button1_Click(object sender, EventArgs e)
- {
- try
- {
- if (KeyValue_CPH.SelectedValue == "0")
- {
- throw new Exception("请选择车牌号!");
- }
- if (String.IsNullOrEmpty(KeyValue_SJ.Text.Trim()))
- {
- throw new Exception("司机不能为空!");
- }
- if (String.IsNullOrEmpty(KeyValue_YCR.Text.Trim()))
- {
- throw new Exception("用车人不能为空!");
- }
- if (KeyValue_YCBM.SelectedValue == "0")
- {
- throw new Exception("请选择用车部门!");
- }
- #region 起始时间
- if (String.IsNullOrEmpty(KeyValue_KSSJ.Text.Trim()))
- {
- throw new Exception("起始时间不能为空!");
- }
- if (DateTime.Compare(Convert.ToDateTime(KeyValue_KSSJ.Text),DateTime.Now) <= 0)
- {
- throw new Exception("起始时间必须大于当前时间!");
- }
- #endregion
- #region 结束时间
- if (String.IsNullOrEmpty(KeyValue_JSSJ.Text.Trim()))
- {
- throw new Exception("结束时间不能为空!");
- }
- if (DateTime.Compare(Convert.ToDateTime(KeyValue_JSSJ.Text), Convert.ToDateTime(KeyValue_KSSJ.Text)) <= 0)
- {
- throw new Exception("结束时间必须大于起始时间!");
- }
- #endregion
- if (String.IsNullOrEmpty(KeyValue_MDD.Text.Trim()))
- {
- throw new Exception("目的地不能为空!");
- }
- double DKeyValue_LC = 0;
- if (!double.TryParse(KeyValue_LC.Text, out DKeyValue_LC))
- {
- throw new Exception("里程不正确!");
- }
- if (String.IsNullOrEmpty(KeyValue_SQR.Text.Trim()))
- {
- throw new Exception("申请人不能为空!");
- }
- if (KeyValue_DDY.SelectedValue == "0")
- {
- throw new Exception("请选择调度员!");
- }
- if (String.IsNullOrEmpty(KeyValue_SY.Text.Trim()))
- {
- throw new Exception("事由不能为空!");
- }
- MCU.CPH = KeyValue_CPH.SelectedValue;
- MCU.YCR = KeyValue_YCR.Text;
- MCU.SY = KeyValue_SY.Text;
- MCU.KSSJ = Convert.ToDateTime(Convert.ToDateTime(KeyValue_KSSJ.Text).ToString("yyyy-MM-dd HH:mm:ss"));
- MCU.SYZT = States.SupplyState_Wait;
- MCU.JSSJ = Convert.ToDateTime(Convert.ToDateTime(KeyValue_JSSJ.Text).ToString("yyyy-MM-dd HH:mm:ss"));
- MCU.BZ = KeyValue_BZ.Text;
- MCU.MDD = KeyValue_MDD.Text;
- MCU.LC = DKeyValue_LC;
- MCU.SJ = KeyValue_SJ.Text;
- MCU.YCBM = int.Parse(KeyValue_YCBM.SelectedValue);
- MCU.SQR = KeyValue_SQR.Text;
- MCU.DDY = KeyValue_DDY.SelectedValue;
- BCU.Add(MCU);
- MessageBox.Show("车辆申请添加成功!");
- DropLoadSet();
- KeyValue_SJ.Text = "";
- KeyValue_YCR.Text = "";
- KeyValue_KSSJ.Text = "";
- KeyValue_JSSJ.Text = "";
- KeyValue_MDD.Text = "";
- KeyValue_LC.Text = "";
- KeyValue_SY.Text = "";
- KeyValue_BZ.Text = "";
- }
- catch (Exception exp)
- {
- MessageBox.Show(exp.Message);
- DropLoadSet(int.Parse(KeyValue_CPH.SelectedValue));
- }
- }
- }