using System;
using System.Data;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EKETEAM.Data;
using EKETEAM.FrameWork;
using LitJson;

namespace eFrameWork.Customs
{
    public partial class PartOne : System.Web.UI.Page
    {
        public string UserArea = "Application"; //用户登录域-默认值
        public eParentModel model;//取父模块动作及表单数据 
        eUser user;//当前操作用户
        string ID = "";//父级模块的主键编号
        public string dz = ""; //当前模块管理的字段(地址)
        public string gddh = ""; //当前模块管理的字段(电话)

        protected void Page_Load(object sender, EventArgs e)
        {
            ID = eParameters.QueryString("id");//获取当前父级模块的主键编号,也可以使用model.ID
            user = new eUser(eBase.getUserArea(UserArea));
            model = new eParentModel();
            JsonData jd;
            eTable etb ;
            switch (model.Action.ToLower())
            {
                case "insert":
                    jd = model.JSON();//获取主模块数据，1V1数据跟主模块数据同级
                    etb = new eTable("Demo_Customs_PartOne", user);
                    etb.Fields.Add("DZ", jd.getValue("ma_f1"));//添加字段
                    etb.Fields.Add("gddh", jd.getValue("ma_f2"));//添加字段
                    etb.Fields.Add("CustomID", ID);//添加字段
                    etb.Add();//执行添加
                    break;
                case "update":
                    jd = model.JSON();//获取主模块数据，1V1数据跟主模块数据同级
                    etb = new eTable("Demo_Customs_PartOne", user);
                    etb.Fields.Add("DZ", jd.getValue("ma_f1"));//添加更新字段
                    etb.Fields.Add("gddh", jd.getValue("ma_f2"));//添加更新字段
                    etb.Where.Add("CustomID='" + ID + "'"); //添加更新条件
                    etb.Update();//执行更新
                    break;
                case "del":
                    etb = new eTable("Demo_Customs_PartOne", user);
                    etb.Where.Add("CustomID='" + ID + "'"); //添加删除条件
                    etb.Delete();//执行删除
                    break;
                default:
                    #region 读取
                    DataTable dt = eOleDB.getDataTable("select dz,gddh from Demo_Customs_PartOne where CustomID='" + ID + "' and delTag=0");
                    if (dt.Rows.Count > 0)
                    {
                        dz = dt.Rows[0]["DZ"].ToString();
                        gddh = dt.Rows[0]["GDDH"].ToString();
                    }
                    else
                    {
                        #region 没有数据则添加一条
                        etb = new eTable("Demo_Customs_PartOne", user);
                        etb.Fields.Add("CustomID", ID);//添加字段
                        etb.Add();//执行添加
                        #endregion
                    }
                    #endregion
                    break;
            }
        }
    }
}