Beispiel #1
0
        public bool UpdateFinance(Finance element)
        {
            string sql = "update TF_Finance set 项目='" + element.项目 + "', 金额=" + element.金额 + ", 是否进账=" + (element.是否进账 ? "1" : "0") + ", 余款=" + element.余款 + ", 日期='" + element.日期 + "', 经手人='" + element.经手人 + "', 接收人='" + element.接收人 + "', Detail='" + element.Detail + "' where ID=" + element.ID;
            int    r   = sqlHelper.ExecuteSql(sql);

            return(r > 0);
        }
Beispiel #2
0
        private void LoadFinanceDetails()
        {
            List <FinanceDetail> elements = FinanceDetailLogic.GetInstance().GetAllFinanceDetails();

            comboBox1.Items.Clear();
            foreach (FinanceDetail element in elements)
            {
                comboBox1.Items.Add(element);
            }
            if (id > 0)
            {
                Finance f = FinanceLogic.GetInstance().GetFinance(id);
                if (f != null)
                {
                    string ids = "ID=0";
                    if (!string.IsNullOrEmpty(f.Detail))
                    {
                        ids = "ID in (" + f.Detail + ")";
                    }
                    dataGridView1.DataSource = FinanceDetailLogic.GetInstance().GetFinanceDetails(ids);
                }
            }
            else
            {
                dataGridView1.DataSource = FinanceDetailLogic.GetInstance().GetFinanceDetails(string.Empty);
            }
        }
Beispiel #3
0
        public List <Finance> GetAllFinances()
        {
            List <Finance> elements = new List <Finance>();
            string         sql      = "select * from TF_Finance";
            DataTable      dt       = sqlHelper.Query(sql);

            if (dt != null && dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    Finance element = new Finance();
                    element.ID     = Convert.ToInt32(dt.Rows[i]["ID"]);
                    element.项目     = dt.Rows[i]["项目"].ToString();
                    element.金额     = Convert.ToDecimal(dt.Rows[i]["金额"]);
                    element.是否进账   = Convert.ToBoolean(dt.Rows[i]["是否进账"]);
                    element.余款     = Convert.ToDecimal(dt.Rows[i]["余款"]);
                    element.日期     = Convert.ToDateTime(dt.Rows[i]["日期"]);
                    element.经手人    = dt.Rows[i]["经手人"].ToString();
                    element.接收人    = dt.Rows[i]["接收人"].ToString();
                    element.Detail = dt.Rows[i]["Detail"].ToString();
                    elements.Add(element);
                }
            }
            return(elements);
        }
Beispiel #4
0
        public bool DeleteFinance(Finance element)
        {
            string sql = "delete from TF_Finance where ID=" + element.ID;
            int    r   = sqlHelper.ExecuteSql(sql);

            return(r > 0);
        }
Beispiel #5
0
        public int AddFinance(Finance element)
        {
            string sql = "insert into TF_Finance (项目, 金额, 是否进账, 余款, 日期, 经手人, 接收人, Detail) values ('" + element.项目 + "', " + element.金额 + ", " + (element.是否进账 ? "1" : "0") + ", " + element.余款 + ", '" + element.日期 + "', '" + element.经手人 + "', '" + element.接收人 + "', '" + element.Detail + "'); select SCOPE_IDENTITY()";
            object obj = sqlHelper.ExecuteSqlReturn(sql);
            int    R;

            if (obj != null && obj != DBNull.Value && int.TryParse(obj.ToString(), out R))
            {
                return(R);
            }
            else
            {
                return(0);
            }
        }
Beispiel #6
0
 private void button3_Click(object sender, EventArgs e)
 {
     if (comboBox1.SelectedIndex > -1)
     {
         if (MessageBox.Show("确定要删除该流水帐?", "删除提醒", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK)
         {
             Finance finance = (Finance)comboBox1.SelectedItem;
             if (FinanceLogic.GetInstance().DeleteFinance(finance))
             {
                 LoadFinances();
             }
         }
     }
     else
     {
         MessageBox.Show("先选定要删除的流水帐!");
     }
 }
Beispiel #7
0
 private void button2_Click(object sender, EventArgs e)
 {
     if (comboBox1.SelectedIndex > -1)
     {
         string  jj = textBox2.Text.Trim();
         string  sj = textBox6.Text.Trim();
         decimal JJ = 0;
         decimal SJ = 0;
         decimal d  = 0;
         if (string.IsNullOrEmpty(jj) || !decimal.TryParse(jj, out d))
         {
             MessageBox.Show("金额必须为数字!");
             textBox2.Focus();
             textBox2.SelectAll();
         }
         JJ = d;
         if (string.IsNullOrEmpty(sj) || !decimal.TryParse(sj, out d))
         {
             MessageBox.Show("余款必须为数字!");
             textBox6.Focus();
             textBox6.SelectAll();
         }
         SJ = d;
         Finance finance = (Finance)comboBox1.SelectedItem;
         finance.项目     = textBox1.Text.Trim();
         finance.金额     = JJ;
         finance.是否进账   = checkBox1.Checked;
         finance.余款     = SJ;
         finance.经手人    = textBox3.Text.Trim();
         finance.接收人    = textBox4.Text.Trim();
         finance.日期     = DateTime.Parse(textBox7.Text.Trim());
         finance.Detail = textBox10.Text;
         FinanceLogic pl = FinanceLogic.GetInstance();
         if (pl.UpdateFinance(finance))
         {
             LoadFinances();
             MessageBox.Show("修改成功!");
         }
     }
     else
     {
         MessageBox.Show("先选定要修改的流水帐!");
     }
 }
Beispiel #8
0
        private void button1_Click(object sender, EventArgs e)
        {
            string  jj = textBox2.Text.Trim();
            string  sj = textBox6.Text.Trim();
            decimal JJ = 0;
            decimal SJ = 0;
            decimal d  = 0;

            if (string.IsNullOrEmpty(jj) || !decimal.TryParse(jj, out d))
            {
                MessageBox.Show("金额必须为数字!");
                textBox2.Focus();
                textBox2.SelectAll();
            }
            JJ = d;
            if (string.IsNullOrEmpty(sj) || !decimal.TryParse(sj, out d))
            {
                MessageBox.Show("余款必须为数字!");
                textBox6.Focus();
                textBox6.SelectAll();
            }
            SJ = d;
            Finance finance = new Finance();

            finance.项目     = textBox1.Text.Trim();
            finance.金额     = JJ;
            finance.是否进账   = checkBox1.Checked;
            finance.余款     = SJ;
            finance.经手人    = textBox3.Text.Trim();
            finance.接收人    = textBox4.Text.Trim();
            finance.日期     = DateTime.Parse(textBox7.Text.Trim());
            finance.Detail = textBox10.Text;
            FinanceLogic pl = FinanceLogic.GetInstance();
            int          id = pl.AddFinance(finance);

            if (id > 0)
            {
                finance.ID = id;
                LoadFinances();
                MessageBox.Show("添加成功!");
            }
        }
Beispiel #9
0
 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (comboBox1.SelectedIndex > -1)
     {
         Finance finance = comboBox1.SelectedItem as Finance;
         if (finance != null)
         {
             textBox1.Text = finance.项目;
             textBox2.Text = finance.金额.ToString();
             textBox3.Text = finance.经手人;
             textBox4.Text = finance.接收人;
             textBox6.Text = finance.余款.ToString();
             monthCalendar1.SelectionStart = finance.日期;
             textBox7.Text     = finance.日期.ToString("yyyy-MM-dd");
             checkBox1.Checked = finance.是否进账;
             textBox10.Text    = finance.Detail;
             textBox10.Tag     = Commons.GetDetailsByStr(finance.Detail);
         }
     }
 }
Beispiel #10
0
        public Finance GetFinance(int id)
        {
            string    sql = "select * from TF_Finance where ID=" + id;
            DataTable dt  = sqlHelper.Query(sql);

            if (dt != null && dt.Rows.Count > 0)
            {
                Finance element = new Finance();
                element.ID     = id;
                element.项目     = dt.Rows[0]["项目"].ToString();
                element.金额     = Convert.ToDecimal(dt.Rows[0]["金额"]);
                element.是否进账   = Convert.ToBoolean(dt.Rows[0]["是否进账"]);
                element.余款     = Convert.ToDecimal(dt.Rows[0]["余款"]);
                element.日期     = Convert.ToDateTime(dt.Rows[0]["日期"]);
                element.经手人    = dt.Rows[0]["经手人"].ToString();
                element.接收人    = dt.Rows[0]["接收人"].ToString();
                element.Detail = dt.Rows[0]["Detail"].ToString();
                return(element);
            }
            return(null);
        }
Beispiel #11
0
 /// <summary>
 /// 在原有的明细基础上添加新的明细
 /// </summary>
 /// <param name="element"></param>
 /// <param name="details"></param>
 /// <returns></returns>
 public bool AddDetail(Finance element, List <FinanceDetail> details)
 {
     if (details != null && details.Count > 0)
     {
         StringBuilder sb = new StringBuilder();
         foreach (FinanceDetail fd in details)
         {
             if (sb.Length == 0)
             {
                 sb.Append(fd.ID);
             }
             else
             {
                 sb.Append("," + fd.ID);
             }
         }
         string sql = "update TF_Finance set Detail='" + sb.ToString() + "' where ID=" + element.ID;
         int    r   = sqlHelper.ExecuteSql(sql);
         return(r > 0);
     }
     return(false);
 }