public List<Model_科目管理> GetChildSubjectData(string parent_id)
 {
     string sql = "select a.*,b.fee from " + DBTablesName.T_SUBJECT
         + " a left join t_yearfee b on a.subject_id=b.subject_id  where b.bookid='"
         + CommonInfo.账薄号 + "' "
         +"and a.SUBJECT_TYPE in ('100','1000','10000') AND a.parent_id LIKE '" + parent_id + "%'"
         +" order by a.subject_id";
     DataTable dt = db.Query(sql).Tables[0];
     List<Model_科目管理> list = new List<Model_科目管理>();
     for (int i = 0; i < dt.Rows.Count; i++)
     {
         Model_科目管理 m = new Model_科目管理();
         DataRow d = dt.Rows[i];
         m.ID = Convert.ToInt32(d[0].ToString());
         m.科目编号 = d[1].ToString();
         m.类别 = d[2].ToString();
         m.科目名称 = d[3].ToString();
         m.父ID = d[4].ToString();
         m.借贷标记 = (d["Borrow_Mark"].ToString()=="1");
         m.年初金额 = d["FEE"].ToString();
         list.Add(m);
     }
     return list;
 }
 private void DataGrid_科目设置_Row_MouseDoubleClick(object sender, RoutedEventArgs e)
 {
     string header = DataGrid_科目设置.CurrentCell.Column.Header.ToString();
     if (header == "是否启用" || header == "借贷方向" || header == "年初数")
     {
         return;
     }
     if (DataGrid_科目设置.SelectedCells.Count > 0)
     {
         Model_科目管理 m = new Model_科目管理();
         m = DataGrid_科目设置.SelectedCells[0].Item as Model_科目管理;
         DoubleClickSubject = m.科目编号;
         Windows.Win_子细目 w = new Windows.Win_子细目(m.科目编号, m.科目名称, m.借贷标记);
         w.ShowDialog();
     }
 }
 private void DataGrid_科目设置_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
 {
     Model_科目管理 m = new Model_科目管理();
     m = e.Row.Item as Model_科目管理;
     m.Used_mark = m.是否启用 == true ? 1 : 0;
     lm.Add(m);
 }
 private void CheckBox_启用_Click(object sender, RoutedEventArgs e)
 {
     if (DataGrid_科目设置.SelectedCells.Count > 0)
     {
         CheckBox b = sender as CheckBox;
         Model_科目管理 m = new Model_科目管理();
         m = DataGrid_科目设置.SelectedCells[0].Item as Model_科目管理;
         m.Used_mark = b.IsChecked == true ? 0 : 1;
         new ViewModel_科目管理().UpdateUsedMark(m);
     }
 }
 private void CheckBox_借贷方向_Click(object sender, RoutedEventArgs e)
 {
     if (DataGrid_科目设置.SelectedCells.Count > 0)
     {
         CheckBox cb = sender as CheckBox;
         Model_科目管理 m = new Model_科目管理();
         m = DataGrid_科目设置.SelectedCells[0].Item as Model_科目管理;
         m.借贷标记 = (bool)cb.IsChecked;
         new ViewModel_科目管理().UpdateBorrowMark(m);
     }
 }
 private void Button_编辑子细目_Click(object sender, RoutedEventArgs e)
 {
     Model_科目管理 m = new Model_科目管理();
     try
     {
         m = DataGrid_科目设置.SelectedCells[0].Item as Model_科目管理;
     }
     catch (Exception ex)
     {
         Log.Write(ex.Message);
     }
     if (m.科目编号 != null)
     {
         Windows.Win_子细目 w = new Windows.Win_子细目(m.科目编号, m.科目名称, m.借贷标记);
         w.ShowDialog();
     }
     else
     {
         MessageBoxCommon.Show("请选择科目!");
     }
 }
 public bool UpdateUsedMark(Model_科目管理 m)
 {
     string sql = "update " + DBTablesName.T_SUBJECT + " set used_mark="
         + m.Used_mark + " where SUBJECT_ID=" + m.科目编号 + " or PARENT_ID=" + m.科目编号 + " OR PARENT_ID LIKE '" + m.科目编号 + "%'";
     return db.Excute(sql);
 }
 public bool UpdateBorrowMark(Model_科目管理 m)
 {
     string sql = "update " + DBTablesName.T_SUBJECT + " set Borrow_Mark="
         + ((m.借贷标记) ? 1 : -1) + " where SUBJECT_ID=" + m.科目编号 + " or PARENT_ID=" + m.科目编号 + " OR PARENT_ID LIKE '" + m.科目编号 + "%'";
     return db.Excute(sql);
 }
 public List<Model_科目管理> GetSujectData(int type)
 {
     string sql = "select a.fee,b.* from " + DBTablesName.T_SUBJECT
         + " b left join t_yearfee a on a.bookid='" + CommonInfo.账薄号
         + "' and a.subject_id=b.subject_id where  b.subject_type=" + type
         + " order by b.id,b.used_mark";
     DataTable dt = db.Query(sql).Tables[0];
     List<Model_科目管理> list = new List<Model_科目管理>();
     for (int i = 0; i < dt.Rows.Count; i++)
     {
         Model_科目管理 m = new Model_科目管理();
         DataRow d = dt.Rows[i];
         m.ID = Convert.ToInt32(d[1].ToString());
         m.序号 = "" + (i + 1);
         m.科目编号 = d[2].ToString();
         m.科目名称 = d[4].ToString();
         m.年初金额 = d[0].ToString();
         m.Used_mark = Convert.ToInt32(d[6].ToString());
         m.是否启用 = m.Used_mark == 0 ? true : false;
         int 借贷标记result = 1;
         int.TryParse(d[7].ToString(), out 借贷标记result);
         m.借贷标记 = (借贷标记result == 1) ? true : false;
         list.Add(m);
     }
     return list;
 }
        private void Button_Del_Click(object sender, RoutedEventArgs e)
        {
            if (DataGrid_子细目.SelectedItems.Count == 0)
            {
                return;
            }
            string messageBoxText = "是否删除这些数据?";
            string caption = "注意";
            bool? result = MessageBoxDel.Show(caption, messageBoxText);
            if (result == false)
            {
                return;
            }
            List<Model_科目管理> list = new List<Model_科目管理>();
            for (int i = 0; i < DataGrid_子细目.SelectedItems.Count; i++)
            {
                Model_科目管理 m = new Model_科目管理();
                try
                {
                    m = DataGrid_子细目.SelectedItems[i] as Model_科目管理;
                    //m.父ID = SubjectNum;
                }
                catch (Exception)
                {

                }
                list.Add(m);
            }
            vm.Delete(list);
            list.Clear();
            check();
        }
 /// <summary>
 /// Lugia
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Button_New_Add子细目_Click(object sender, RoutedEventArgs e)
 {
     string Number = this.TextBox_New_子细目编号.Text;
     string Name   = this.TextBox_New_子细目名称.Text;
     string Money  = this.TextBox_New_年初数.Text;
     if (string.IsNullOrEmpty(Number) || string.IsNullOrEmpty(Name))
     {
         MessageBoxCommon.Show("数据不能为空");
         return;
     }
     if (string.IsNullOrEmpty(Money))
     {
         Money = "0";
     }
     string ParentsID = this.ComboBox_New_父ID.Text;
     List<Model_科目管理> details = new List<Model_科目管理>();
     Model_科目管理 detail = new Model_科目管理();
     detail.科目编号 = Number;
     detail.科目名称 = Name;
     detail.年初金额 = Money;
     if (this.ComboBox_New_父ID.Text.Length <= 3)
     {
         detail.类别 = "100";
     }
     else if (this.ComboBox_New_父ID.Text.Length <= 5)
     {
         detail.类别 = "1000";
     }
     else
     {
         detail.类别 = "10000";
     }
     detail.父ID = ParentsID;
     detail.借贷标记 = BorrowMark;
     details.Add(detail);
     bool flag = vm.Insert(details);
     if (flag)
     {
         this.TextBox_New_子细目名称.Text = "";
         this.TextBox_New_年初数.Text = "";
         check();
     }
     else
     {
         MessageBoxCommon.Show("添加不成功,请检查编号是否唯一!");
     }
 }