221 lines
8.0 KiB
C#
221 lines
8.0 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.OleDb;
|
|
using System.Web;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
using System.Configuration;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Globalization;
|
|
|
|
|
|
public partial class admin_accounting_new_reg : MyWeb.config
|
|
{
|
|
private Model.ezEntities _db = new Model.ezEntities();
|
|
public float _t = 0;
|
|
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
|
|
|
|
InitEnumsOptions<Model.accounting.type>(category); //收支類別
|
|
|
|
if (isStrNull(Request["num"]))
|
|
{
|
|
uptime.Text = DateTime.Now.ToString("yyyy-MM-dd");
|
|
}
|
|
else
|
|
{
|
|
int _num = Val(Request["num"]);
|
|
var qry = _db.accountings.AsEnumerable();
|
|
var prod = qry.Where(q => q.num == _num).FirstOrDefault();
|
|
if (prod != null)
|
|
{
|
|
|
|
|
|
try
|
|
{
|
|
foreach (Control obj in cardBodyPanel.Controls)
|
|
{
|
|
|
|
if (obj is TextBox)
|
|
{
|
|
var ObjValue = prod.GetType().GetProperty(obj.ID).GetValue(prod, null);
|
|
if (!isStrNull(ObjValue))
|
|
{
|
|
var textBox = (TextBox)obj;
|
|
if (textBox.TextMode == TextBoxMode.Date)
|
|
{
|
|
textBox.Text = Convert.ToDateTime(ObjValue).ToString("yyyy-MM-dd");
|
|
}
|
|
else
|
|
{
|
|
textBox.Text = ObjValue.ToString();
|
|
}
|
|
}
|
|
}
|
|
else if (obj is DropDownList && ((DropDownList)obj).SelectedIndex == 0)
|
|
{
|
|
var ObjValue = prod.GetType().GetProperty(obj.ID).GetValue(prod, null);
|
|
if (!isStrNull(ObjValue))
|
|
{
|
|
var dropDown = (DropDownList)obj;
|
|
dropDown.SelectedValue = ObjValue.ToString();
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
}
|
|
if (prod.kind.HasValue)
|
|
{
|
|
kind_txt.Value = prod.accounting_kind.kind.ToString();
|
|
kind.Value = prod.kind.ToString();
|
|
}
|
|
if (prod.kind2.HasValue)
|
|
{
|
|
kind2_txt.Value = prod.accounting_kind2.kind.ToString();
|
|
kind2.Value = prod.kind2.ToString();
|
|
}
|
|
if (prod.activity_num.HasValue)
|
|
{
|
|
activity_num_txt.Value = prod.activity.subject.ToString();
|
|
activity_num.Value = prod.activity_num.ToString();
|
|
}
|
|
if (prod.mem_num.HasValue)
|
|
{
|
|
mem_num_txt.Value = prod.member.u_name.ToString();
|
|
mem_num.Value = prod.mem_num.ToString();
|
|
}
|
|
|
|
if (prod.reg_time.HasValue)
|
|
{
|
|
timePanel1.Visible = true;
|
|
reg_time.Text = prod.reg_time.Value.ToString("yyyy/MM/dd HH:mm:ss");
|
|
}
|
|
_t = ((prod.price.HasValue) ? ValFloat(prod.price.Value) : 0) + ((prod.tax.HasValue) ? ValFloat(prod.tax.Value) : 0);
|
|
|
|
edit.Visible = true;
|
|
goback.Visible = true;
|
|
add.Visible = false;
|
|
}
|
|
else
|
|
{
|
|
Response.Redirect("index.aspx");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
protected void goback_Click(object sender, EventArgs e)
|
|
{
|
|
Response.Redirect("index.aspx?page=" + Convert.ToString(Request["page"]));
|
|
}
|
|
|
|
|
|
|
|
#region 資料新增
|
|
|
|
protected void add_Click(object sender, EventArgs e)
|
|
{
|
|
if (Page.IsValid) {
|
|
L_msg.Text = "";
|
|
|
|
Model.accounting accounting = new Model.accounting();
|
|
if (!isStrNull(uptime.Text)) { accounting.uptime = ValDate(uptime.Text); }
|
|
accounting.category = Val(category.SelectedValue);
|
|
|
|
if (!isStrNull(kind.Value)) { accounting.kind = Val(kind.Value); }
|
|
if (!isStrNull(kind2.Value)) { accounting.kind2 = Val(kind2.Value); }
|
|
if (!isStrNull(tax.Text)) { accounting.tax = Val(tax.Text); }
|
|
if (!isStrNull(price.Text)) { accounting.price = ValFloat(price.Text); }
|
|
if (!isStrNull(activity_num.Value)) { accounting.activity_num = Val(activity_num.Value); }
|
|
if (!isStrNull(mem_num.Value)) { accounting.mem_num = Val(mem_num.Value); }
|
|
accounting.debtor = debtor.Text;
|
|
accounting.demo = demo.Text;
|
|
accounting.excerpt = excerpt.Text;
|
|
accounting.reg_time = DateTime.Now;
|
|
|
|
try
|
|
{
|
|
_db.accountings.Add(accounting);
|
|
_db.SaveChanges();
|
|
Model.admin_log admin_log = new Model.admin_log();
|
|
admin_log.writeLog(admin.info.u_id, (int)Model.admin_log.Systems.Accounting, (int)Model.admin_log.Status.Insert, uptime.Text + kind2_txt.Value);
|
|
|
|
Response.Redirect("index.aspx");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
L_msg.Text = ex.Message;
|
|
L_msg.Type = alert_type.danger;
|
|
//L_msg.Text = "操作失敗";
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 資料修改
|
|
|
|
protected void edit_Click(object sender, EventArgs e)
|
|
{
|
|
if (Page.IsValid)
|
|
{
|
|
L_msg.Text = "";
|
|
int _num = Val(Request["num"]);
|
|
|
|
Model.accounting accounting = _db.accountings.Where(q => q.num == _num).FirstOrDefault();
|
|
if (accounting != null)
|
|
{
|
|
//if (!isStrNull(uptime.Text)) { accounting.uptime = ValDate(uptime.Text); }
|
|
//accounting.category = Val(category.SelectedValue);
|
|
|
|
//if (!isStrNull(kind.Value)) { accounting.kind = Val(kind.Value); }
|
|
//if (!isStrNull(kind2.Value)) { accounting.kind2 = Val(kind2.Value); }
|
|
//if (!isStrNull(tax.Text)) { accounting.tax = Val(tax.Text); }
|
|
//if (!isStrNull(price.Text)) { accounting.price = ValFloat(price.Text); }
|
|
//if (!isStrNull(activity_num.Value)) { accounting.activity_num = Val(activity_num.Value); }
|
|
//if (!isStrNull(mem_num.Value)) { accounting.mem_num = Val(mem_num.Value); }
|
|
//accounting.debtor = debtor.Text;
|
|
accounting.demo = demo.Text;
|
|
accounting.excerpt = excerpt.Text;
|
|
|
|
}
|
|
|
|
try
|
|
{
|
|
_db.SaveChanges();
|
|
Model.admin_log admin_log = new Model.admin_log();
|
|
admin_log.writeLog(admin.info.u_id, (int)Model.admin_log.Systems.Accounting, (int)Model.admin_log.Status.Update, uptime.Text+ kind2_txt.Value);
|
|
|
|
Response.Redirect("index.aspx?page=" + Convert.ToString(Request["page"]));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
L_msg.Type = alert_type.danger;
|
|
//L_msg.Text = ex.InnerException.Message;
|
|
L_msg.Text = "操作失敗";
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
} |