249 lines
9.0 KiB
C#
249 lines
9.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;
|
|
using static publicFun;
|
|
|
|
public partial class admin_activity_item_reg : MyWeb.config
|
|
{
|
|
private Model.ezEntities _db = new Model.ezEntities();
|
|
public int prod_bom_num = 0;
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
|
|
InitEnumsOptions<Model.activity.category>(category);
|
|
|
|
|
|
if (isStrNull(Request["num"]))
|
|
{
|
|
BuildKind();
|
|
status.Checked = true;
|
|
bom_panel.Visible = false;
|
|
}
|
|
else
|
|
{
|
|
int _num = Val(Request["num"]);
|
|
//var qry = _db.actItems.AsEnumerable();
|
|
var prod = _db.actItems.Where(q => q.num == _num).FirstOrDefault();
|
|
|
|
if (prod != null)
|
|
{
|
|
|
|
BuildKind();
|
|
subject.Text = prod.subject;
|
|
print_init.Text = prod.print_init;
|
|
PARTNO.Text = prod.partno;
|
|
//kind.SelectedValue = prod.kind.ToString();
|
|
if (prod.kind.HasValue)
|
|
{
|
|
kind_txt.Value = prod.actItem_kind.kind;
|
|
kind.Value = prod.kind.ToString();
|
|
}
|
|
|
|
if (prod.category.HasValue) category.SelectedValue = prod.category.ToString();
|
|
if(!isStrNull(prod.demo))
|
|
demo.Text = prod.demo.ToString();
|
|
|
|
status.Checked = ValString(prod.status).Equals("Y");
|
|
extend.Checked = ValString(prod.extend).Equals("Y");
|
|
is_reconcile_item.Checked = ValString(prod.is_reconcile).Equals("Y");
|
|
setCycle();
|
|
if (prod.price.HasValue)
|
|
price.Text = prod.price.Value.ToString();
|
|
if (prod.cycle.HasValue)
|
|
cycle.Text = prod.cycle.Value.ToString();
|
|
|
|
customize_data.Text = prod.customize_data?.ToString();
|
|
|
|
|
|
edit.Visible = true;
|
|
goback.Visible = true;
|
|
add.Visible = false;
|
|
|
|
//檢查prod有沒有對應的act_bom項目
|
|
var prodBom = prod.act_bom.FirstOrDefault();
|
|
setBom.Visible = prodBom == null;//沒有對應的act_bom項目才能新增
|
|
saveBom.Visible = prodBom != null;//有對應的act_bom項目才能儲存
|
|
//bom_qty.Enabled = prodBom != null;//有對應的act_bom項目..
|
|
bom_qty.Text = (prodBom?.qty??0).ToString();
|
|
bom_memo.Text = (prodBom?.memo ?? "");
|
|
packageNum.Value=(prodBom?.num.ToString());
|
|
prod_bom_num = prodBom?.num ?? 0;
|
|
}
|
|
else
|
|
{
|
|
Response.Redirect("index2.aspx");
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
protected void goback_Click(object sender, EventArgs e)
|
|
{
|
|
Response.Redirect("index2.aspx?page=" + Convert.ToString(Request["page"]));
|
|
}
|
|
|
|
#region 分類
|
|
|
|
|
|
|
|
public void BuildKind()
|
|
{
|
|
//kind.Items.Clear();
|
|
//kind.Items.Add(new ListItem("請選擇", ""));
|
|
|
|
|
|
//buildMultiKind(kind, "actItem_kind", 0, "", 1, Model.activity.ItemLevelMax,null ,true);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 資料新增
|
|
|
|
protected void add_Click(object sender, EventArgs e)
|
|
{
|
|
if (Page.IsValid) {
|
|
L_msg.Text = "";
|
|
|
|
Model.actItem actItem = new Model.actItem();//新增
|
|
actItem.subject = subject.Text;
|
|
actItem.print_init = print_init.Text;
|
|
actItem.partno = PARTNO.Text;
|
|
//if (!isStrNull(kind.SelectedValue)) { actItem.kind = Val(kind.SelectedValue); } else { actItem.kind = null; }
|
|
if (!isStrNull(category.SelectedValue)) { actItem.category = Val(category.SelectedValue); } else { actItem.category = null; }
|
|
if (!isStrNull(kind.Value)) { actItem.kind = Val(kind.Value); } else { actItem.kind = null; }
|
|
if (!isStrNull(price.Text)) { actItem.price = ValFloat(price.Text); } else { actItem.price = null; }
|
|
if (extend.Checked && !isStrNull(cycle.Text)) { actItem.cycle = Val(cycle.Text); } else { actItem.cycle = null; }
|
|
actItem.status = status.Checked ? "Y" : "N";
|
|
actItem.extend = extend.Checked ? "Y" : "N";
|
|
actItem.is_reconcile = is_reconcile_item.Checked ? "Y" : "N";
|
|
actItem.demo = demo.Text;
|
|
actItem.customize_data = customize_data.Text;
|
|
|
|
_db.actItems.Add(actItem);
|
|
_db.SaveChanges();
|
|
int _id = actItem.num;
|
|
if( _id > 0)
|
|
{
|
|
Model.admin_log admin_log = new Model.admin_log();
|
|
admin_log.writeLog(admin.info.u_id, (int)Model.admin_log.Systems.Item, (int)Model.admin_log.Status.Insert, subject.Text);
|
|
|
|
Response.Redirect("index2.aspx");
|
|
}
|
|
else
|
|
{
|
|
L_msg.Type = alert_type.danger;
|
|
L_msg.Text = "Error";
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 資料修改
|
|
|
|
protected void edit_Click(object sender, EventArgs e)
|
|
{
|
|
if (Page.IsValid)
|
|
{
|
|
L_msg.Text = "";
|
|
|
|
int _num = Val(Request["num"]);
|
|
Model.actItem actItem = _db.actItems.Where(q => q.num == _num).FirstOrDefault();//修改
|
|
if (actItem != null)
|
|
{
|
|
actItem.subject = subject.Text;
|
|
actItem.print_init = print_init.Text;
|
|
actItem.partno = PARTNO.Text;
|
|
//if (!isStrNull(kind.SelectedValue)) { actItem.kind = Val(kind.SelectedValue); } else { actItem.kind = null; }
|
|
if (!isStrNull(category.SelectedValue)) { actItem.category = Val(category.SelectedValue); } else { actItem.category = null; }
|
|
if (!isStrNull(kind.Value)) { actItem.kind = Val(kind.Value); } else { actItem.kind = null; }
|
|
if (!isStrNull(price.Text)) { actItem.price = ValFloat(price.Text); } else { actItem.price = null; }
|
|
if (extend.Checked && !isStrNull(cycle.Text)) { actItem.cycle = Val(cycle.Text); } else { actItem.cycle = null; }
|
|
actItem.status = status.Checked ? "Y" : "N";
|
|
actItem.extend = extend.Checked ? "Y" : "N";
|
|
actItem.is_reconcile = is_reconcile_item.Checked ? "Y" : "N";
|
|
actItem.demo = demo.Text;
|
|
actItem.customize_data = customize_data.Text;
|
|
|
|
_db.SaveChanges();
|
|
Model.admin_log admin_log = new Model.admin_log();
|
|
admin_log.writeLog(admin.info.u_id, (int)Model.admin_log.Systems.Item, (int)Model.admin_log.Status.Update, subject.Text);
|
|
|
|
Response.Redirect("index2.aspx?page=" + Convert.ToString(Request["page"]));
|
|
}
|
|
else
|
|
{
|
|
L_msg.Type = alert_type.danger;
|
|
L_msg.Text = "查無資料";
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
#region 收費週期
|
|
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
setCycle();
|
|
}
|
|
protected void setCycle()
|
|
{
|
|
cyclePlaceHolder.Visible = extend.Checked;
|
|
}
|
|
#endregion
|
|
|
|
|
|
protected void setBom_Click(object sender, EventArgs e)
|
|
{
|
|
//新增本頁品項, 對應的actItem
|
|
if (!isStrNull(Request["num"]))
|
|
{
|
|
int _num = Val(Request["num"]);
|
|
var prod = _db.actItems.Where(q => q.num == _num).FirstOrDefault();
|
|
var prodBom = prod.act_bom.FirstOrDefault();
|
|
if (prod != null && prodBom == null)
|
|
{
|
|
Model.act_bom actBom = new Model.act_bom();
|
|
actBom.item_num = _num;
|
|
actBom.qty = Val(bom_qty.Text);
|
|
actBom.memo = bom_memo.Text;
|
|
_db.act_bom.Add(actBom);
|
|
_db.SaveChanges();
|
|
Response.Redirect("item_reg.aspx?num=" + _num);
|
|
}
|
|
}
|
|
}
|
|
|
|
protected void saveBom_Click(object sender, EventArgs e)
|
|
{
|
|
//儲存本頁品項, 對應的actItem
|
|
if (!isStrNull(Request["num"]))
|
|
{
|
|
int _num = Val(Request["num"]);
|
|
var prod = _db.actItems.Where(q => q.num == _num).FirstOrDefault();
|
|
var prodBom = prod.act_bom.FirstOrDefault();
|
|
if (prod != null && prodBom != null)
|
|
{
|
|
prodBom.qty = Val(bom_qty.Text);
|
|
prodBom.memo = bom_memo.Text;
|
|
_db.SaveChanges();
|
|
//Response.Redirect("item_reg.aspx?num=" + _num);
|
|
}
|
|
}
|
|
}
|
|
} |