/// <summary>
 /// Deprecated Method for adding a new object to the ds_codinh EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddTods_codinh(ds_codinh ds_codinh)
 {
     base.AddObject("ds_codinh", ds_codinh);
 }
 /// <summary>
 /// Create a new ds_codinh object.
 /// </summary>
 /// <param name="so_dt">Initial value of the so_dt property.</param>
 public static ds_codinh Createds_codinh(global::System.String so_dt)
 {
     ds_codinh ds_codinh = new ds_codinh();
     ds_codinh.so_dt = so_dt;
     return ds_codinh;
 }
        void SaveData()
        {
            if (App.id_goicuoc == "" && cmbgoith.SelectedIndex != -1)
            {
                MessageBox.Show("Chưa chọn thuê bao tích hợp !");
                return;
            }
            try
            {
                // get_hopdong(App.ma_huyen + "/" + this.dngayhd.DateTime.Year.ToString().Substring(2, 2));
                ds_codinh ds = new ds_codinh
                {
                    so_dt = this.txtsdt.Text,
                    ten_dktb = this.txttentb.Text.Trim(),
                    ten_dkdb = this.txttendb.Text.Trim(),
                    dia_chitb = this.txtdctb.Text.Trim(),
                    dc_tbld = this.txtdcld.Text.Trim(),
                    tuyen_tc = "",
                    ma_tram = cmbtramvt.GetKeyValue(cmbtramvt.SelectedIndex).ToString(),
                    pl = Getplkhachhang(cmbnhom.GetKeyValue(cmbnhom.SelectedIndex).ToString().Trim()),
                    tien_tb = 0,
                    tienno = 0,
                    tb_dv = 0,
                    ngay_ld = null,
                    village = "",
                    ngay_mo = null,
                    may_ngung = "M",
                    ngay_ngung = null,
                    keo_may = false,
                    mo_may = false,
                    ma_nghe = cmbnganh.GetKeyValue(cmbnganh.SelectedIndex).ToString(),
                    ma_huyen = App.ma_huyen,
                    stt = 0,
                    sohopdong = this.txtsohd.Text.Trim(),
                    ngay_hd = this.dngayhd.DateTime,
                    thangbd = "",
                    inct = false,
                    ma_kh = this.txtmakh.Text,
                    ngay_kn = dngaykn.Text.Trim()=="" ? D_null : this.dngaykn.DateTime,
                    note_ngay_kn = this.txtghichu.Text.Trim(),
                    dau = false,
                    tenkhkd = FunAndPro.KhongDau(this.txttentb.Text.Trim()),
                    dckd = FunAndPro.KhongDau(this.txtdctb.Text.Trim()),
                    ms_thue = FunAndPro.ma_st(this.txtmst.Text.Trim()),
                    khg_vat = false,
                    cuoc = 0,
                    ngay = null,
                    duong = App.duong,
                    xa_phuong = App.phuong,
                    khom_ap = App.khom,
                    duongld = App.duongld,
                    xa_phuongld = App.phuongld,
                    khom_apld = App.khomld,
                    tbdc = false,                   
                    ma_nhom = cmbnhom.GetKeyValue(cmbnhom.SelectedIndex).ToString(),
                    socmnd = this.txtcmnd.Text.Trim(),
                    noi_cap = this.txtnoicap.Text.Trim(),
                    ngay_cap = this.dngaycap.DateTime,
                    ngan_hang = this.txtNH.Text.Trim(),
                    e_mail = this.txtemail.Text.Trim(),
                    camket=Convert.ToInt16(this.spcamket.Text),
                    ma_km = cmbkm.GetKeyValue(cmbkm.SelectedIndex).ToString(),
                    ma_nvcs = cmbcbcs.SelectedIndex==-1? S_null : cmbcbcs.GetKeyValue(cmbcbcs.SelectedIndex).ToString(),
                    ma_nvkt = cmbcbkt.SelectedIndex == -1 ? S_null : cmbcbkt.GetKeyValue(cmbcbkt.SelectedIndex).ToString(),
                    dt_lh = this.txtdtlh.Text.Trim(),
                    so_nha = App.sonha,
                    so_nhald = App.sonhald,
                    goi_th = cmbgoith.SelectedIndex == -1 ? S_null : this.cmbgoith.GetKeyValue(cmbgoith.SelectedIndex).ToString().Trim(),
                    id_goicuoc=App.id_goicuoc
                };
                dstb.ds_codinhs.Add(ds);

                codinh_log dsl = new codinh_log
                {
                    so_dt = this.txtsdt.Text.Trim(),
                    ten_dktb = this.txttentb.Text.Trim(),
                    ten_dkdb = this.txttendb.Text.Trim(),
                    dia_chitb = this.txtdctb.Text.Trim(),
                    dc_tbld = this.txtdcld.Text.Trim(),
                    tuyen_tc = null,
                    ma_tram = cmbtramvt.GetKeyValue(cmbtramvt.SelectedIndex).ToString(),
                    pl = Getplkhachhang(cmbnhom.GetKeyValue(cmbnhom.SelectedIndex).ToString().Trim()),
                    may_ngung = "M",
                    ma_huyen = App.ma_huyen,
                    sohopdong = this.txtsohd.Text,
                    ngay_hd = this.dngayhd.DateTime,
                    ma_kh = this.txtmakh.Text,
                    ngay_kn = dngaykn.Text.Trim() == "" ? D_null : this.dngaykn.DateTime,
                    note_ngay_kn = this.txtghichu.Text.Trim(),
                    ms_thue = FunAndPro.ma_st(this.txtmst.Text.Trim()),
                    socmnd = this.txtcmnd.Text.Trim(),
                    noi_cap = this.txtnoicap.Text.Trim(),
                    ngay_cap = this.dngaycap.DateTime,
                    e_mail = this.txtemail.Text.Trim(),
                    thoi_gian = App.Current_d,
                    camket = Convert.ToInt16(this.spcamket.Text),
                    ma_km = cmbkm.GetKeyValue(cmbkm.SelectedIndex).ToString(),
                    ma_nhom = cmbnhom.GetKeyValue(cmbnhom.SelectedIndex).ToString(),
                    ma_nghe = cmbnganh.GetKeyValue(cmbnganh.SelectedIndex).ToString(),
                    ma_nvcs = cmbcbcs.SelectedIndex == -1 ? S_null : cmbcbcs.GetKeyValue(cmbcbcs.SelectedIndex).ToString(),
                    ma_nvkt = cmbcbkt.SelectedIndex == -1 ? S_null : cmbcbkt.GetKeyValue(cmbcbkt.SelectedIndex).ToString(),
                    users = App.User_name,
                    dt_lh = this.txtdtlh.Text.Trim(),
                    so_nha = App.sonha,
                    so_nhald = App.sonhald,
                    goi_th = cmbgoith.SelectedIndex == -1 ? S_null : this.cmbgoith.GetKeyValue(cmbgoith.SelectedIndex).ToString().Trim(),
                    id_goicuoc = App.id_goicuoc
                };

                dstb.codinh_logs.Add(dsl);
                dstb.SubmitChanges(OnSubmitCompleted,true);               
            }
            catch(Exception e)
            {
                MessageBox.Show(string.Format("Exception Failed: {0}",e));
            }
        }