migrate to new git

This commit is contained in:
2025-08-29 01:27:25 +08:00
parent 946eb9961e
commit af2c152ef6
8623 changed files with 1000453 additions and 1 deletions

View File

@@ -0,0 +1,392 @@
<%@ Page Title="後端管理" Language="C#" MasterPageFile="~/admin/Templates/TBS5ADM001/MasterPage.master" AutoEventWireup="true" EnableEventValidation="false" CodeFile="index.aspx.cs" Inherits="admin_supplier_index" %>
<%@ Register Src="~/admin/_uc/alert.ascx" TagPrefix="uc1" TagName="alert" %>
<asp:Content ID="Content1" ContentPlaceHolderID="page_header" runat="Server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="page_nav" runat="Server">
<div class="mb-2 mb-sm-0">
<a href="reg.aspx" class="btn btn-primary">
<i class="mdi mdi-plus"></i>新增
</a>
<a @click="deleteAll" class="btn btn-outline-danger" title="刪除勾選的資料" ><i class="mdi mdi-trash-can"></i> 刪除勾選</a>
</div>
<div class="">
<asp:LinkButton ID="excel" runat="server" CssClass="btn btn-outline-success" OnClick="excel_Click"><span class="fa-solid fa-file-excel"></span> 匯出Excel</asp:LinkButton>
</div>
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="footer_script" runat="Server">
<script>
Vue.filter('timeString', function (value, myFormat) {
return value == null || value == "" ? "" : moment(value).format(myFormat || 'YYYY-MM-DD, HH:mm:ss');
});
let VueApp=new Vue({
el: '#app',
vuetify: new Vuetify(vuetify_options),
data() {
return {
options: { multiSort: false },
data_table: {
loading: true,
list: [],
selected: [],
singleSelect: false,
count: 0,
page: 1,
pageSize: 10,
header: [
{ text: '供應商編號', value: 's_number' },
{ text: '供應商名稱/聯絡人', value: 'u_name'},
{ text: '分類', value: 'kindsTxt'},
{ text: '', value: 'slot_btn', sortable: false, align: 'end' },
],
footer: {
showFirstLastPage: true,
itemsPerPageOptions:[5,10,20,30],
},
},
search: {
kind: '',
u_name: '',
s_number: '',
}//
,
search_dialog: {
controls: {
search1: {
id: 'search1',
title: '分類',
text_prop: 'kind',
value_prop: 'num',
keys: [
{ id: 'kind', title: '分類名稱', value: '' },
],
api_url: HTTP_HOST + 'api/supplier/GetKindList',
columns: [
{ id: 'kind', title: '分類名稱', value: '' },
],
selected: {},
select(t,data) {
console.log("select search1", t);
data.search.kind=t.num
}
}
},
show: false,
current: {},
list: [],
count: 0,
page: 1,
loading: false,
footer: {
showFirstLastPage: true,
disableItemsPerPage: true,
itemsPerPageAllText: '',
itemsPerPageText: '',
},
},
snackbar: {
show: false,
text: "",
}
}
}, mounted() {
this.search_dialog.current = this.search_dialog.controls.search1
},
watch: {
options: {
handler() {
this.getDefault()
this.search_get()
console.log("watch2", this.search_dialog, this.search_dialog.page);
},
deep: true,
},
},
methods: {
getDefault(clearpage = false) {
const { sortBy, sortDesc, page, itemsPerPage } = this.options
const params = {
sortBy: sortBy[0], sortDesc: sortDesc[0],
page: clearpage ? '1' : page, pageSize: itemsPerPage
};
this.data_table.loading = true
axios
.post(HTTP_HOST + 'api/supplier/GetList', this.search, { params: params })
.then(response => {
this.data_table.list = response.data.list
this.data_table.count = response.data.count;
this.data_table.loading = false
})
.catch(error => console.log(error))
},
editItem(item) {
console.log("edit", item);
},
deleteItem(item) {
if (confirm('是否確定刪除此筆資料?')) {
const index = this.data_table.list.indexOf(item)
if (index != -1) {
axios
.delete(HTTP_HOST + 'api/supplier/' + item.num)
.then(response => {
console.log("del", item);
this.data_table.list.splice(index, 1);
this.data_table.count = this.data_table.list.length
})
.catch(error => console.log(error))
}
}
},
deleteAll() {
if (confirm('是否確定刪除已勾選的資料?')) {
axios
.delete(HTTP_HOST + 'api/supplier/Delete/' + this.data_table.selected.map(x => x.num))
.then(response => {
//console.log("delAll");
//for (var i = 0; i < this.data_table.selected.length; i++) {
// const index = this.data_table.list.indexOf(this.data_table.selected[i]);
// this.data_table.list.splice(index, 1);
//}
//this.data_table.selected = [];
//this.data_table.count = this.data_table.list.length
location.reload();
})
.catch(error => console.log(error))
}
},
btn_search() {
this.getDefault(true)
},
btn_all() {
clearObjProps(this.search);
this.btn_search()
},//===
search_show(curr) {
//console.log("btn_click:", curr, curr.api_url);
this.search_dialog.current = curr;
this.search_clear()
//this.search_get()//清除完自動會重抓, 故取消
this.search_dialog.show = true;
},
search_clear() {
if (!this.search_dialog.current.keys) return;
this.search_dialog.current.keys.forEach((t, i) => { t.value = '' })
this.search_get()
},
search_get() {
if (!this.search_dialog.current.keys) return;
let api_url = this.search_dialog.current.api_url;
let keys = this.search_dialog.current.keys;
//const { page, itemsPerPage } = this.options
//const { sortBy, sortDesc, page, itemsPerPage } = this.options
this.search_dialog.page = this.options.page ?? 1
let params = { page: this.search_dialog.page, pageSize: 10 };//url params
var search = {};//post body
keys.forEach((t, i) => {
search[t.id] = t.value;
});
console.log("search_get", api_url, search, params, this.options);
this.search_dialog.loading = true
axios.post(api_url, search, { params: params })
.then(response => {
this.search_dialog.list = response.data.list
this.search_dialog.count = response.data.count
this.search_dialog.loading = false
})
.catch(error => {
console.log(error)
this.search_dialog.list = []
this.search_dialog.count = 0
this.search_dialog.loading = false
this.snackbar.text = "錯誤:" + error
this.snackbar.show = true
})
},
search_headers() {
if (!this.search_dialog.current.columns) return;
r = [];
this.search_dialog.current.columns.forEach((t, i) => {
r.push({
text: t.title,
align: 'start',
sortable: false,
value: t.id,
})
})
return r
},
search_select(row) {
let curr = this.search_dialog.current;
let target = $(`[data-search-control=${curr.id}]`);
curr.selected = row;
target.children("input.search-text").val(curr.selected[curr.text_prop])//text
target.children("input:hidden").val(curr.selected[curr.value_prop])//value
if (curr.select instanceof Function) {
curr.select(row,this);
}
this.search_dialog.show = false;
},
},
computed: {
pageCount() {
return Math.ceil(this.data_table.count / this.data_table.pageSize)
},
},
})
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<uc1:alert runat="server" ID="L_msg" Text="" />
<div id="content" class="container-fluid">
<v-data-table
v-model="data_table.selected"
:items="data_table.list"
:search-props="search"
item-key="num"
:options.sync="options"
:headers="data_table.header"
:footer-props="data_table.footer"
:server-items-length="data_table.count"
:loading="data_table.loading"
:single-select="data_table.singleSelect"
show-select
hide-default-footer
:page.sync="data_table.page"
:items-per-page.sync="data_table.pageSize"
class="elevation-1">
<template #item.slot_btn="{ item }">
<a :href="'reg.aspx?num='+item.num" class="btn btn-outline-secondary btn-sm"><i class="mdi mdi-pencil-box-outline"></i>修改</a>
<a @click="deleteItem(item)" class="btn btn-outline-secondary btn-sm"><i class="mdi mdi-trash-can"></i>刪除</a>
</template>
</v-data-table>
<v-container>
<v-row class="align-baseline" wrap>
<v-col cols="12" md="9">
<v-pagination
v-model="data_table.page"
:length="pageCount">
</v-pagination>
</v-col>
<v-col class="text-truncate text-right" cols="12" md="2">
共 {{ data_table.count }} 筆, 頁數:
</v-col>
<v-col cols="6" md="1">
<v-text-field
v-model="data_table.page"
type="number"
hide-details
dense
min="1"
:max="pageCount"
@input="data_table.page = parseInt($event, 10)"
></v-text-field>
</v-col>
</v-row>
</v-container>
</div>
<div id="print_data">
</div>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="offCanvasRight" runat="Server">
<div id="search_panel" alt="查詢公告資料">
<div class="mb-3">
<label class="form-label">供應商名稱/聯絡人 </label>
<input type="text" v-model="search.u_name" class="form-control" placeholder="可輸入關鍵字查詢" id="u_name" runat="server">
</div>
<div class="mb-3">
<label class="form-label">供應商編號 </label>
<input type="text" v-model="search.s_number" class="form-control" placeholder="可輸入關鍵字查詢" id="s_number" runat="server">
</div>
<div class="mb-3">
<label class="form-label">分類</label>
<asp:DropDownList ID="s_kind" runat="server" CssClass="form-select" v-model="search.kind" >
<asp:ListItem Value="" Text="請選擇"></asp:ListItem>
</asp:DropDownList>
<%-- 測試--%>
<div class="input-group mb-3" data-search-control="search1" @click="search_show(search_dialog.controls.search1)">
<input class="form-control search-text" type="text" readonly
id="kind_txt" runat="server" placeholder="分類" value="">
<input type="hidden" v-model="search.kind">
<button class="btn btn-outline-secondary" type="button">
<i class="mdi mdi-view-list-outline"></i>
</button>
</div>
<%-- 測試--%>
</div>
<div class="mb-3 p-2 border-top">
<a @click="btn_search" class="btn btn-outline-primary"><i class="mdi mdi-filter"></i> 搜尋</a>
<a class="btn btn-outline-secondary" @click="btn_all"><i class="mdi mdi-filter-remove"></i> 所有資料</a>
</div>
<v-dialog v-model="search_dialog.show" max-width="500px">
<v-card>
<v-card-title class="justify-space-between grey lighten-2">
查詢:{{search_dialog.current.title}}
<v-btn icon @click="search_dialog.show=false"><v-icon>mdi-close</v-icon></v-btn>
</v-card-title>
<v-card-text >
<v-row>
<v-col v-for="item in search_dialog.current.keys"
:cols="search_dialog.current.keys.length>1?6:12" >
<v-text-field v-model="item.value" :label="item.title"></v-text-field>
</v-col>
<v-col cols="12" class="text-end">
<v-btn color="primary" elevation="0" @click="search_get()">查詢</v-btn>
<v-btn elevation="0" @click="search_clear()">清除條件</v-btn>
</v-col>
</v-row>
<v-data-table
:headers="search_headers()"
:items="search_dialog.list"
:footer-props="search_dialog.footer"
:items-per-page="10"
:server-items-length="search_dialog.count"
:page.sync="search_dialog.page"
:options.sync="options"
@click:row="search_select"
></v-data-table>
</v-card-text>
<v-card-actions>
</v-card-actions>
</v-card>
</v-dialog>
<v-snackbar
v-model="snackbar.show"
timeout="2000"
>
{{ snackbar.text }}
<template v-slot:action="{ attrs }">
<v-btn
text
v-bind="attrs"
@click="snackbar.show = false"
>
關閉
</v-btn>
</template>
</v-snackbar>
</div>
</asp:Content>

View File

@@ -0,0 +1,169 @@
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 DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Spreadsheet;
using static TreeView;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Information;
using MyWeb;
public partial class admin_supplier_index : MyWeb.config
{
private Model.ezEntities _db = new Model.ezEntities();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BuildKind();
}
}
#region
public void BuildKind()
{
//倉庫
s_kind.Items.Clear();
s_kind.Items.Add(new ListItem("請選擇", ""));
//buildMultiKind(s_kind, "supplier_kind", 0, "", 1, Model.supplier.KindLevelMax);
var qry1 = new TreeView().get_data2(_db.supplier_kind.Select(o => new TreeItem()
{
kind = o.kind,
num = o.num,
root = o.root,
range = o.range,
}).OrderBy(x => x.root).ThenBy(x => x.kind).ToList(), 0, 0);
if (qry1.Count() > 0)
foreach (var qq in qry1)
s_kind.Items.Add(new ListItem(new TreeView().RptDash(qq.Level) + qq.kind, qq.num.ToString()));
}
#endregion
#region Excel
protected void excel_Click(object sender, EventArgs e)
{
var memoryStream = new MemoryStream();
using (var doc = SpreadsheetDocument.Create(memoryStream, SpreadsheetDocumentType.Workbook))
{
var wb = doc.AddWorkbookPart();
wb.Workbook = new Workbook();
var sheets = wb.Workbook.AppendChild(new Sheets());
//建立第一個頁籤
var ws = wb.AddNewPart<WorksheetPart>();
ws.Worksheet = new Worksheet();
sheets.Append(new Sheet()
{
Id = wb.GetIdOfPart(ws),
SheetId = 1,
Name = "供應商​"
});
//設定欄寬
var cu = new Columns();
cu.Append(
new Column { Min = 1, Max = 3, Width = 15, CustomWidth = true },
new Column { Min = 4, Max = 4, Width = 25, CustomWidth = true },
new Column { Min = 5, Max = 5, Width = 15, CustomWidth = true },
new Column { Min = 6, Max = 7, Width = 10, CustomWidth = true }
);
ws.Worksheet.Append(cu);
//建立資料頁
var sd = new SheetData();
ws.Worksheet.AppendChild(sd);
//第一列資料
var tr = new Row();
tr.Append(
new Cell() { CellValue = new CellValue("供應商編號"), DataType = CellValues.String },
new Cell() { CellValue = new CellValue("統一編號"), DataType = CellValues.String },
new Cell() { CellValue = new CellValue("分類"), DataType = CellValues.String },
new Cell() { CellValue = new CellValue("供應商名稱/聯絡人"), DataType = CellValues.String },
new Cell() { CellValue = new CellValue("地址"), DataType = CellValues.String },
new Cell() { CellValue = new CellValue("聯絡電話1"), DataType = CellValues.String },
new Cell() { CellValue = new CellValue("聯絡電話2"), DataType = CellValues.String },
new Cell() { CellValue = new CellValue("傳真"), DataType = CellValues.String },
new Cell() { CellValue = new CellValue("E-MAIL"), DataType = CellValues.String },
new Cell() { CellValue = new CellValue("型錄連結"), DataType = CellValues.String },
new Cell() { CellValue = new CellValue("備註​"), DataType = CellValues.String }
);
sd.AppendChild(tr);
//查詢要匯出的資料
var qry = _db.suppliers.AsEnumerable();
if (!string.IsNullOrEmpty(s_kind.SelectedValue))
qry = qry.Where(o => o.kind == Convert.ToInt32(s_kind.SelectedValue));
if (!string.IsNullOrEmpty(s_number.Value))
qry = qry.Where(o => (o.s_number ?? "").Contains(s_number.Value.Trim()));
qry = qry.OrderByDescending(o => o.num);
var list = qry.ToList();
if (list.Count > 0)
{
MyWeb.encrypt encrypt = new MyWeb.encrypt();
foreach (var item in list)
{
//新增資料列
tr = new Row();
tr.Append(
new Cell() { CellValue = new CellValue(item.s_number ), DataType = CellValues.String },
new Cell() { CellValue = new CellValue(item.c_num ), DataType = CellValues.String },
new Cell() { CellValue = new CellValue(item.kind.HasValue ? item.supplier_kind.kind : ""), DataType = CellValues.String },
new Cell() { CellValue = new CellValue(item.u_name), DataType = CellValues.String },
new Cell() { CellValue = new CellValue(item.address), DataType = CellValues.String },
new Cell() { CellValue = new CellValue(encrypt.DecryptAutoKey(item.phone1)), DataType = CellValues.String },
new Cell() { CellValue = new CellValue(encrypt.DecryptAutoKey(item.phone2)), DataType = CellValues.String },
new Cell() { CellValue = new CellValue(encrypt.DecryptAutoKey(item.fax)), DataType = CellValues.String },
new Cell() { CellValue = new CellValue(item.email), DataType = CellValues.String },
new Cell() { CellValue = new CellValue(item.url), DataType = CellValues.String },
new Cell() { CellValue = new CellValue(item.demo), DataType = CellValues.String }
);
sd.AppendChild(tr);
}
Model.admin_log admin_log = new Model.admin_log();
admin_log.writeLog(admin.info.u_id, (int)Model.admin_log.Systems.Supplier, (int)Model.admin_log.Status.Excel, admin_log.LogViewBtn(list.Select(x => x.s_number + x.u_name).ToList()));
}
}
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=供應商.xlsx");
HttpContext.Current.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
HttpContext.Current.Response.BinaryWrite(memoryStream.ToArray());
HttpContext.Current.Response.End();
}
#endregion
}

View File

@@ -0,0 +1,83 @@
<%@ Page Title="後端管理" Language="C#" MasterPageFile="~/admin/Templates/TBS5ADM001/MasterPage.master" AutoEventWireup="true" CodeFile="kind_reg.aspx.cs" Inherits="admin_supplier_kind_reg" %>
<%@ Register Src="~/admin/_uc/alert.ascx" TagPrefix="uc1" TagName="alert" %>
<asp:Content ID="Content1" ContentPlaceHolderID="footer_script" runat="Server">
<link href="../../App_Script/bootstrap_toggle/css/bootstrap-toggle.min.css" rel="stylesheet" />
<script src="../../App_Script/bootstrap_toggle/js/bootstrap-toggle.min.js"></script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="page_nav" runat="Server">
<nav class="mb-1">
<asp:LinkButton ID="ImageButton4" runat="server" CausesValidation="False" OnClick="ImageButton4_Click" CssClass="btn btn-primary"><i class="mdi mdi-plus"></i> 新增主分類</asp:LinkButton>
</nav>
<nav class="mb-1">
<asp:Button ID="edit" runat="server" Text="修改" Visible="false" OnClick="edit_Click" CssClass="btn btn-primary" />
<asp:Button ID="add" runat="server" Text="新增" Visible="false" OnClick="add_Click" CssClass="btn btn-primary" />
<asp:PlaceHolder ID="down_table" runat="server">
<asp:LinkButton ID="ImageButton5" runat="server" OnClick="ImageButton5_Click" CssClass="btn btn-outline-secondary" CausesValidation="False"><i class="mdi mdi-arrow-down-right"></i> 建立下一層選項</asp:LinkButton>
<asp:LinkButton ID="ImageButton6" runat="server" OnClientClick="return msgconfirm('是否確定刪除這筆資料?<br>注意!資料刪除後將一併刪除此資料的子選項!',this);" OnClick="ImageButton6_Click" CssClass="btn btn-outline-secondary"><i class="mdi mdi-trash-can"></i> 刪除</asp:LinkButton>
</asp:PlaceHolder>
</nav>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<uc1:alert runat="server" ID="L_msg" Text="" />
<div id="content" class="container-fluid pb-4">
<div class="row">
<div class="col-sm-4">
<div class="card shadow-sm my-2" id="sec1">
<div class="card-header">選擇分類</div>
<div class="card-body">
<asp:TreeView ID="TreeView2" runat="server" CssClass="aspxTree" ImageSet="Arrows"
SkipLinkText="" ShowLines="false" EnableTheming="False" ShowExpandCollapse="True">
</asp:TreeView>
</div>
</div>
</div>
<div class="col-sm-8">
<asp:Panel ID="table" runat="server" CssClass="card shadow-sm my-2">
<div class="card-header">
<div>
<asp:Label ID="start" runat="server" CssClass="text-danger" Display="Dynamic"></asp:Label>
</div>
<div>
<asp:Label ID="title_msg" runat="server" CssClass="" ForeColor=""></asp:Label>
</div>
</div>
<div class="card-body form-horizontal label-sm-right " role="form">
<div>
<div class="form-text text-muted">以下 * 欄位為必填欄位</div>
</div>
<div class="row mb-1">
<label class="col-sm-2 col-lg-3 col-form-label">* 分類名稱</label>
<div class="col-sm-10 col-lg-9">
<asp:TextBox ID="item_name" runat="server" CssClass="form-control" MaxLength="100" placeholder="請輸入分類名稱"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="item_name" ErrorMessage="必填!" Display="Dynamic" SetFocusOnError="true"></asp:RequiredFieldValidator>
</div>
</div>
<div class="row mb-1">
<label class="col-sm-2 col-lg-3 col-form-label">備註</label>
<div class="col-sm-10 col-lg-9">
<asp:TextBox ID="demo" runat="server" CssClass="form-control" TextMode="MultiLine" Rows="3" placeholder="請輸入備註"></asp:TextBox>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-md-offset-2 col-sm-9 col-md-10">
<asp:HiddenField ID="HiddenField1" runat="server" />
</div>
</div>
</div>
</asp:Panel>
</div>
</div>
</div>
</asp:Content>

View File

@@ -0,0 +1,305 @@
using System;
using System.Data;
using System.Data.OleDb;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Linq;
using System.Data.Entity.Infrastructure;
public partial class admin_supplier_kind_reg : MyWeb.config
{
DataTable treeDt = new DataTable();
const int LevelMax = Model.supplier.KindLevelMax; //分類層數
private Model.ezEntities _db = new Model.ezEntities();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) {
BuildTreeView();
if (!isStrNull(Request["num"]))
{
int _num = Val(Request["num"]);
var prod = _db.supplier_kind.AsEnumerable().Where(q => q.num == _num).OrderBy(q => q.kind).FirstOrDefault();
if (prod != null)
{
title_msg.Text = "修改<span class=\"text-primary\">【" + prod.kind + "】</span>的分類名稱";
item_name.Text = prod.kind;
demo.Text = prod.demo;
HiddenField1.Value = prod.kind;
}
else
{
Response.Redirect(Request.Url.AbsolutePath );
}
edit.Visible = true;
add.Visible = false;
down_table.Visible = true;
start.Visible = false;
}
else
{
table.Visible = false;
down_table.Visible = false;
if (Convert.ToString(Request["msg"]) == "A") { start.Text = "【資料修改成功】"; }
else if (Convert.ToString(Request["msg"]) == "B") { start.Text = "【資料新增成功】"; }
else if (Convert.ToString(Request["msg"]) == "C") { start.Text = "【資料刪除成功】"; }
else { start.Text = "【請點選下方欲新增、修改或刪除的分類】"; }
}
}
}
#region
protected void TreeTopology()
{
MyWeb.sql sql = new MyWeb.sql();
OleDbConnection sqlConn = sql.conn(db, p_name);
try
{
sqlConn.Open();
OleDbCommand sqlCmd = new OleDbCommand("", sqlConn);
sqlCmd.CommandText = "SELECT num,kind,root FROM supplier_kind ORDER BY kind,root, range";
treeDt = sql.dataTable(sqlCmd);
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
sqlConn.Close();
sqlConn.Dispose();
}
}
public void BuildTreeView()
{
TreeView2.Nodes.Clear();
TreeTopology();
BuildChild(0, TreeView2.Nodes);
treeDt.Dispose();
}
public void BuildChild(int RootUid, TreeNodeCollection Nodes, int Level=1)
{
DataTable dt = treeDt;
foreach (DataRow row in dt.Rows)
{
if (row["root"].ToString() == RootUid.ToString())
{
TreeNode NewNode = new TreeNode();
if (Convert.ToString(Request["num"]) == row["num"].ToString() & HiddenField1.Value != "AddMainItem")
{
NewNode.Text = "<b><span style=\"color:blue\">" + row["kind"].ToString() + "</span></b>";
if (Level +1 > LevelMax)
{
ImageButton5.Visible = false;
}
}
else
{
NewNode.Text = row["kind"].ToString();
}
NewNode.NavigateUrl = Request.Url.AbsolutePath + "?num=" + row["num"].ToString() ;
NewNode.Expand();
Nodes.Add(NewNode);
if (Level + 1 <= LevelMax)
{
BuildChild((int)row["num"], NewNode.ChildNodes, Level + 1);
}
}
}
}
#endregion
#region
protected void ImageButton5_Click(object sender, EventArgs e)
{
title_msg.Text = "於<span class=\"text-primary\">【" + HiddenField1.Value + "】</span>分類下,新增次分類";
item_name.Text = "";
demo.Text = "";
add.Visible = true;
edit.Visible = false;
down_table.Visible = false;
start.Visible = false;
}
protected void ImageButton4_Click(object sender, EventArgs e)
{
title_msg.Text = "<span class=\"text-primary\">於根目錄下,新增主分類</span>";
table.Visible = true;
item_name.Text = "";
demo.Text = "";
add.Visible = true;
edit.Visible = false;
down_table.Visible = false;
start.Visible = false;
HiddenField1.Value = "AddMainItem";
BuildTreeView();
}
#endregion
#region
protected void edit_Click(object sender, EventArgs e)
{
L_msg.Text = "";
int _num = Val(Request["num"]);
try
{
Model.supplier_kind supplier_kind = _db.supplier_kind.Where(q => q.num == _num).FirstOrDefault();//修改
if (supplier_kind != null)
{
supplier_kind.kind = item_name.Text;
supplier_kind.demo = demo.Text;
_db.SaveChanges();
Model.admin_log admin_log = new Model.admin_log();
admin_log.writeLog(admin.info.u_id, (int)Model.admin_log.Systems.Supplier, (int)Model.admin_log.Status.Update, "分類:" + item_name.Text);
L_msg.Type = alert_type.success;
L_msg.Text = "操作成功";
}
else
{
L_msg.Type = alert_type.danger;
L_msg.Text = "無此資料";
}
}
catch (DbUpdateConcurrencyException)
{
L_msg.Type = alert_type.danger;
L_msg.Text = "Error";
throw;
}
BuildTreeView();
}
#endregion
#region
protected void add_Click(object sender, EventArgs e)
{
L_msg.Text = "";
int range = 1;
int root = 0;
if (HiddenField1.Value != "AddMainItem")
{
root = Convert.ToInt32(Request["num"]);
}
try
{
var prod = _db.supplier_kind.AsEnumerable().Where(q => q.root == root).OrderByDescending(q => q.range).FirstOrDefault();
if (prod != null)
if (prod.range.HasValue)
range = prod.range.Value + 1;
Model.supplier_kind supplier_kind = new Model.supplier_kind();//新增
supplier_kind.kind = item_name.Text;
supplier_kind.root = root;
supplier_kind.range = range;
supplier_kind.demo = demo.Text;
_db.supplier_kind.Add(supplier_kind);
_db.SaveChanges();
Model.admin_log admin_log = new Model.admin_log();
admin_log.writeLog(admin.info.u_id, (int)Model.admin_log.Systems.Supplier, (int)Model.admin_log.Status.Insert, "分類:" + item_name.Text);
L_msg.Type = alert_type.success;
L_msg.Text = "操作成功";
}
catch (DbUpdateConcurrencyException)
{
throw;
}
BuildTreeView();
}
#endregion
#region
protected void ImageButton6_Click(object sender, EventArgs e)
{
int num = Val(Request["num"]);
//del_product(num);
var prod = _db.supplier_kind.AsEnumerable().Where(q => q.num == num).FirstOrDefault(); //刪除該筆資料
if (prod != null)
{
_db.supplier_kind.Remove(prod);
_db.SaveChanges(); //執行
}
Del_Ohter_Items(Val(Request["num"]));
Model.admin_log admin_log = new Model.admin_log();
admin_log.writeLog(admin.info.u_id, (int)Model.admin_log.Systems.Supplier, (int)Model.admin_log.Status.Delete, "分類:" + item_name.Text);
Response.Redirect(Request.Url.AbsolutePath + "?msg=C");
}
public void Del_Ohter_Items(int d_num)
{
var prod = _db.supplier_kind.AsEnumerable().Where(q => q.root == d_num).ToList();
if (prod.Count > 0)
{
foreach (var row in prod)
{
//del_product(row.num);
Del_Ohter_Items(row.num);
}
//查詢結果全部刪除
_db.supplier_kind.RemoveRange(prod);
_db.SaveChanges();
}
}
public void del_product(int num)
{
var prod = _db.suppliers.AsEnumerable().Where(q => q.kind == num).ToList();
if (prod.Count > 0)
{
////查詢結果全部刪除
//_db.suppliers.RemoveRange(prod);
//_db.SaveChanges();
//清空分類
foreach (var item in prod)
item.kind = null;
_db.SaveChanges();
}
}
#endregion
}

356
web/admin/supplier/reg.aspx Normal file
View File

@@ -0,0 +1,356 @@
<%@ Page Title="後端管理" Language="C#" MasterPageFile="~/admin/Templates/TBS5ADM001/MasterPage.master" AutoEventWireup="true" CodeFile="reg.aspx.cs" Inherits="admin_supplier_reg" ValidateRequest="false" %>
<%@ Register Src="~/admin/_uc/alert.ascx" TagPrefix="uc1" TagName="alert" %>
<asp:Content ID="Content1" ContentPlaceHolderID="page_header" runat="Server">
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="footer_script" runat="Server">
<script>
function checkNumber(btn) {
$('#errormsg').hide();
var _txt = $(btn).val();
$.ajax({
method: "POST",
url: "reg.aspx",
data: {
type: 'chkNo',
txt: _txt,
id: '<%= Request["num"]%>'
},
error: function (xhr, status, error) {
var errorMessage = xhr.status + ': ' + xhr.statusText
//alert('Error - ' + errorMessage);
console.log('Error - ' + errorMessage);
}
}).done(function (data) {
if (data.isOk) {
} else {
console.log(data.msg);
$('#errormsg').text(data.msg);
$('#errormsg').show();
}
});
}
</script>
<script>
let VueApp = new Vue({
el: '#app',
vuetify: new Vuetify(vuetify_options),
data() {
return {
news_id: '<%= Request["num"] %>',
options: {},
search_dialog: {
controls: {
search1: {
id: 'search1',
title: '供應商分類',
text_prop: 'kind',
value_prop: 'num',
keys: [
{ id: 'kind', title: '分類名稱', value: '' },
],
api_url: HTTP_HOST + 'api/supplier/GetKindList',
columns: [
{ id: 'kind', title: '分類名稱', value: '' },
],
selected: {},
select(t) {
console.log("select search1", t);
}
},
},
show: false,
current: {},
list: [],
count: 0,
page: 1,
loading: false,
footer: {
showFirstLastPage: true,
disableItemsPerPage: true,
itemsPerPageAllText: '',
itemsPerPageText: '',
},
},
snackbar: {
show: false,
text: "",
}
}
},
mounted() {
this.search_dialog.current = this.search_dialog.controls.search1
//console.log("mounted");
},
watch: {
options: {
handler() {
//console.log("watch1", this.search_dialog, this.search_dialog.page);
this.search_get()
console.log("watch2", this.search_dialog, this.search_dialog.page);
},
deep: true,
},
},
methods: {
search_show(curr) {
//console.log("btn_click:", curr, curr.api_url);
this.search_dialog.current = curr;
this.search_clear()
//this.search_get()//清除完自動會重抓, 故取消
this.search_dialog.show = true;
},
search_clear() {
if (!this.search_dialog.current.keys) return;
this.search_dialog.current.keys.forEach((t, i) => { t.value = '' })
this.search_get()
},
search_get() {
if (!this.search_dialog.current.keys) return;
let api_url = this.search_dialog.current.api_url;
let keys = this.search_dialog.current.keys;
//const { page, itemsPerPage } = this.options
//const { sortBy, sortDesc, page, itemsPerPage } = this.options
this.search_dialog.page = this.options.page ?? 1
let params = { page: this.search_dialog.page, pageSize: 10 };//url params
var search = {};//post body
keys.forEach((t, i) => {
search[t.id] = t.value;
});
//necessary parameter===
if (this.search_dialog.current.id == 'search1') {
search['inTime'] = (this.news_id != '' ? false : true);
}
console.log("search_get", api_url, search, params, this.options);
this.search_dialog.loading = true
axios.post(api_url, search, { params: params })
.then(response => {
this.search_dialog.list = response.data.list
this.search_dialog.count = response.data.count
this.search_dialog.loading = false
})
.catch(error => {
console.log(error)
this.search_dialog.list = []
this.search_dialog.count = 0
this.search_dialog.loading = false
this.snackbar.text = "錯誤:" + error
this.snackbar.show = true
})
},
search_headers() {
if (!this.search_dialog.current.columns) return;
r = [];
this.search_dialog.current.columns.forEach((t, i) => {
r.push({
text: t.title,
align: 'start',
sortable: false,
value: t.id,
})
})
return r
},
search_select(row) {
let curr = this.search_dialog.current;
let target = $(`[data-search-control=${curr.id}]`);
curr.selected = row;
target.children("input.search-text").val(curr.selected[curr.text_prop])//text
target.children("input:hidden").val(curr.selected[curr.value_prop])//value
if (curr.select instanceof Function) {
curr.select(row);
}
this.search_dialog.show = false;
console.log(row, row["u_name"], row["s_number"], curr.id, target);
},
},
computed: {
},
})
</script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="page_nav" runat="Server">
<div class="scroll-nav nav nav-tabs mb-2 mb-sm-0 d-none d-sm-flex">
</div>
<div class="">
<asp:Button ID="add" runat="server" Text="送出" OnClick="add_Click" CssClass="btn btn-primary" />
<asp:Button ID="edit" runat="server" Text="修改" Visible="false" OnClick="edit_Click" CssClass="btn btn-primary" />
<asp:Button ID="goback" runat="server" Text="回列表" Visible="false" CausesValidation="false" OnClick="goback_Click" CssClass="btn btn-outline-secondary" />
</div>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<uc1:alert runat="server" ID="L_msg" Text="" />
<div id="content" class="container-md">
<div class="card shadow-sm my-2" id="sec2">
<div class="card-header py-0">
<nav class="navbar py-0">
<div class="nav nav-tabs">
<button class="nav-link active" id="sec2-tab1" data-bs-toggle="tab" data-bs-target="#sec2-page1"
type="button" role="tab" aria-controls="home" aria-selected="true">
基本資料</button>
</div>
</nav>
</div>
<asp:Panel ID="cardBodyPanel" runat="server" CssClass="card-body">
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="sec2-page1" role="tabpanel" aria-labelledby="sec2-tab1">
<div>
<div class="form-text text-muted">以下 * 欄位為必填欄位</div>
</div>
<div class="row mb-1 label-sm-right">
<label class="col-sm-2 col-lg-1 col-form-label">供應商編號 *</label>
<div class="col-sm-10 col-lg-3">
<asp:TextBox ID="s_number" MaxLength="20" runat="server" CssClass="form-control" onchange="checkNumber(this)" placeholder="請輸入供應商編號(不可重複)"></asp:TextBox>
<span id="errormsg" class="text-danger" style="display: none;"></span>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" ControlToValidate="s_number" runat="server"
ErrorMessage="必填!" Display="Dynamic" SetFocusOnError="true"></asp:RequiredFieldValidator>
</div>
<label class="col-sm-2 col-lg-1 col-form-label">統一編號</label>
<div class="col-sm-10 col-lg-3">
<asp:TextBox ID="c_num" MaxLength="8" runat="server" CssClass="form-control" placeholder="請輸入統一編號"></asp:TextBox>
</div>
<label class="col-sm-2 col-lg-1 col-form-label">分類 *</label>
<div class="col-sm-10 col-lg-3">
<div class="input-group mb-3" data-search-control="search1" @click="search_show(search_dialog.controls.search1)">
<input class="form-control search-text" type="text" readonly
id="kind_txt" runat="server" placeholder="分類" value="">
<asp:HiddenField ID="kind" runat="server" Value="" />
<button class="btn btn-outline-secondary" type="button">
<i class="mdi mdi-view-list-outline"></i>
</button>
</div>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="kind_txt" runat="server" ErrorMessage="必填!" Display="Dynamic" SetFocusOnError="true"></asp:RequiredFieldValidator>
</div>
</div>
<div class="row mb-1 label-sm-right">
<label class="col-sm-2 col-lg-1 col-form-label">供應商名稱/聯絡人 *</label>
<div class="col-sm-10 col-lg-3">
<asp:TextBox ID="u_name" MaxLength="20" runat="server" CssClass="form-control" placeholder="請輸入供應商名稱/聯絡人"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" ControlToValidate="u_name" runat="server"
ErrorMessage="必填!" Display="Dynamic" SetFocusOnError="true"></asp:RequiredFieldValidator>
</div>
<label class="col-sm-2 col-lg-1 col-form-label">電子信箱</label>
<div class="col-sm-10 col-lg-3">
<asp:TextBox ID="email" MaxLength="200" runat="server" CssClass="form-control" placeholder="請輸入E-mail如: taichung@gmail.com"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="email" Display="Dynamic" SetFocusOnError="true"
ErrorMessage="格式有誤!" ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" />
</div>
</div>
<div class="row mb-1 label-sm-right">
<label class="col-sm-2 col-lg-1 col-form-label">聯絡電話1</label>
<div class="col-sm-10 col-lg-3">
<asp:TextBox ID="phone1" MaxLength="15" runat="server" CssClass="form-control" data-encrypt="Y" placeholder="請輸入聯絡電話,如: 04-2237-0000"></asp:TextBox>
<asp:RegularExpressionValidator ControlToValidate="phone1" ErrorMessage="格式有誤" ID="RegularExpressionValidator11" runat="server" ValidationExpression="^[+-]?\d+([+-]?\d*)*$" Display="Dynamic" SetFocusOnError="true" />
</div>
<label class="col-sm-2 col-lg-1 col-form-label">聯絡電話2</label>
<div class="col-sm-10 col-lg-3">
<asp:TextBox ID="phone2" MaxLength="15" runat="server" CssClass="form-control" data-encrypt="Y" placeholder="請輸入聯絡電話,如: 0987-0000-0000"></asp:TextBox>
<asp:RegularExpressionValidator ControlToValidate="phone2" ErrorMessage="格式有誤" ID="RegularExpressionValidator2" runat="server" ValidationExpression="^[+-]?\d+([+-]?\d*)*$" Display="Dynamic" SetFocusOnError="true" />
</div>
<label class="col-sm-2 col-lg-1 col-form-label">傳真</label>
<div class="col-sm-10 col-lg-3">
<asp:TextBox ID="fax" MaxLength="15" runat="server" CssClass="form-control" data-encrypt="Y" placeholder="請輸入聯絡傳真"></asp:TextBox>
</div>
</div>
<div class="row mb-1 label-sm-right">
<label class="col-sm-2 col-lg-1 col-form-label">地址</label>
<div class="col-sm-10 col-lg-7">
<asp:TextBox ID="address" MaxLength="100" runat="server" CssClass="form-control" placeholder="請輸入地址"></asp:TextBox>
</div>
</div>
<div class="row mb-1 label-sm-right">
<label class="col-sm-2 col-lg-1 col-form-label">型錄連結</label>
<div class="col-sm-10 col-lg-7">
<asp:TextBox ID="url" runat="server" CssClass="form-control" placeholder="請輸入型錄連結網址"></asp:TextBox>
</div>
</div>
<div class="row mb-1 label-sm-right">
<label class="col-sm-2 col-lg-1 col-form-label">附件檔</label>
<div class="col-sm-10 col-lg-3">
<asp:FileUpload ID="FileUpload1" runat="server" accept="image/png, image/jpeg, application/pdf" />
<asp:HyperLink ID="picLink" runat="server" CssClass="btn btn-sm btn-default " Visible="false" Target="_blank">查看</asp:HyperLink>
<asp:CheckBox ID="delPic" runat="server" Visible="false" Text="刪除附件" />
</div>
</div>
<hr />
<div class="row mb-1">
<label class="col-form-label">備註</label>
<div class="">
<asp:TextBox ID="demo" runat="server" Rows="5" TextMode="MultiLine" CssClass="form-control" placeholder="請輸入備註"></asp:TextBox>
</div>
</div>
<div class="row mb-1">
<asp:Panel ID="timePanel1" runat="server" CssClass="col-12 text-right text-primary" Visible="false">建檔時間:<asp:Literal ID="reg_time" runat="server"></asp:Literal></asp:Panel>
<asp:Panel ID="timePanel2" runat="server" CssClass="col-12 text-right text-primary" Visible="false">最後修改時間:<asp:Literal ID="modify_time" runat="server"></asp:Literal></asp:Panel>
</div>
</div>
</div>
</asp:Panel>
</div>
<v-dialog v-model="search_dialog.show" max-width="500px">
<v-card>
<v-card-title class="justify-space-between grey lighten-2">
查詢:{{search_dialog.current.title}}
<v-btn icon @click="search_dialog.show=false"><v-icon>mdi-close</v-icon></v-btn>
</v-card-title>
<v-card-text >
<v-row>
<v-col v-for="item in search_dialog.current.keys"
:cols="search_dialog.current.keys.length>1?6:12" >
<v-text-field v-model="item.value" :label="item.title"></v-text-field>
</v-col>
<v-col cols="12" class="text-end">
<v-btn color="primary" elevation="0" @click="search_get()">查詢</v-btn>
<v-btn elevation="0" @click="search_clear()">清除條件</v-btn>
</v-col>
</v-row>
<v-data-table
:headers="search_headers()"
:items="search_dialog.list"
:footer-props="search_dialog.footer"
:items-per-page="10"
:server-items-length="search_dialog.count"
:page.sync="search_dialog.page"
:options.sync="options"
@click:row="search_select"
></v-data-table>
</v-card-text>
<v-card-actions>
</v-card-actions>
</v-card>
</v-dialog>
<v-snackbar
v-model="snackbar.show"
timeout="2000"
>
{{ snackbar.text }}
<template v-slot:action="{ attrs }">
<v-btn
text
v-bind="attrs"
@click="snackbar.show = false"
>
關閉
</v-btn>
</template>
</v-snackbar>
</div>
</asp:Content>

View File

@@ -0,0 +1,389 @@
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 MyWeb;
using System.Data.SqlTypes;
public partial class admin_supplier_reg : MyWeb.config
{
private Model.ezEntities _db = new Model.ezEntities();
public ArrayList _tmp = new ArrayList();
protected void Page_Load(object sender, EventArgs e)
{
CallAjax();
if (!IsPostBack)
{
if (isStrNull(Request["num"]))
{
}
else
{
var qry = _db.suppliers.AsEnumerable();
int _num = Val(Request["num"]);
var prod = qry.Where(q => q.num == _num).FirstOrDefault();
if (prod != null)
{
MyWeb.encrypt encrypt = new MyWeb.encrypt();
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 if (!isStrNull(textBox.Attributes["data-encrypt"]) && ValString(textBox.Attributes["data-encrypt"]).Equals("Y"))
textBox.Text = !isStrNull(ObjValue)? encrypt.DecryptAutoKey(ObjValue.ToString()) :"";
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)
{
L_msg.Type = alert_type.danger;
L_msg.Text = ex.Message;
}
if (prod.kind.HasValue)
{
kind_txt.Value = prod.supplier_kind.kind.ToString();
kind.Value = prod.kind.ToString();
}
if (prod.reg_time.HasValue)
{
timePanel1.Visible = true;
reg_time.Text= prod.reg_time.Value.ToString("yyyy/MM/dd HH:mm:ss");
}
if (!isStrNull(prod.admin_log))
{
timePanel2.Visible = true;
modify_time.Text = prod.admin_log;
}
if (!isStrNull(prod.pic1))
{
((CheckBox)Master.FindControl("ContentPlaceHolder1").FindControl("delPic")).Visible = true;
ViewState["pic1"] = prod.pic1;
HyperLink pic1Link = (HyperLink)Master.FindControl("ContentPlaceHolder1").FindControl("picLink");
pic1Link.Visible = true;
pic1Link.NavigateUrl = Model.supplier.Dir + "/" + prod.pic1;
}
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 = "";
if (chk_pro_num(s_number.Text))
{
MyWeb.fileSystem fileSystem = new MyWeb.fileSystem();
string[] pic_name = fileSystem.UploadPhoto(Model.supplier.Dir, 800); //縮圖的寬高不得超過800象素如果不是圖片也會傳
MyWeb.encrypt encrypt = new MyWeb.encrypt();
Model.supplier supplier = new Model.supplier();
try
{
foreach (Control obj in cardBodyPanel.Controls)
{
if (obj is TextBox)
{
var ObjValue = supplier.GetType().GetProperty(obj.ID);
var textBox = (TextBox)obj;
if (!isStrNull(textBox.Text))
{
if (textBox.TextMode == TextBoxMode.Date)
ObjValue.SetValue(supplier, selectDate(textBox));
else if (!isStrNull(((TextBox)obj).Attributes["data-encrypt"]) && ValString(textBox.Attributes["data-encrypt"]).Equals("Y"))
ObjValue.SetValue(supplier, encrypt.EncryptAutoKey(textBox.Text.Trim()));
else
ObjValue.SetValue(supplier, ((TextBox)obj).Text.Trim());
}
else
ObjValue.SetValue(supplier, null);
}
}
if (!isStrNull(kind.Value))
{
supplier.kind = Val(kind.Value);
}
supplier.reg_time = DateTime.Now;
supplier.pic1 = pic_name[0];
_db.suppliers.Add(supplier);
_db.SaveChanges();
int _id = supplier.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.Supplier, (int)Model.admin_log.Status.Insert, s_number.Text+ u_name.Text);
Response.Redirect("index.aspx");
}
else
{
L_msg.Type = alert_type.danger;
L_msg.Text = "Error";
}
}
catch (Exception ex)
{
L_msg.Type = alert_type.danger;
L_msg.Text = "操作失敗";
}
}
else
{
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 = "";
if (chk_pro_num(s_number.Text, Val(Request["num"])))
{
MyWeb.fileSystem fileSystem = new MyWeb.fileSystem();
string[] pic_name = fileSystem.UploadPhoto(Model.supplier.Dir, 800); //縮圖的寬高不得超過800象素如果不是圖片也會傳
MyWeb.encrypt encrypt = new MyWeb.encrypt();
int _num = Val(Request["num"]);
Model.supplier supplier = _db.suppliers.Where(q => q.num == _num).FirstOrDefault();//修改
if (supplier != null)
{
try
{
foreach (Control obj in cardBodyPanel.Controls)
{
if (obj is TextBox)
{
var ObjValue = supplier.GetType().GetProperty(obj.ID);
var textBox = (TextBox)obj;
if (!isStrNull(textBox.Text))
{
if (textBox.TextMode == TextBoxMode.Date)
ObjValue.SetValue(supplier, selectDate(textBox));
else if (!isStrNull(((TextBox)obj).Attributes["data-encrypt"]) && ValString(textBox.Attributes["data-encrypt"]).Equals("Y"))
ObjValue.SetValue(supplier, encrypt.EncryptAutoKey(textBox.Text.Trim()));
else
ObjValue.SetValue(supplier, ((TextBox)obj).Text.Trim());
}
else
ObjValue.SetValue(supplier, null);
}
}
for (int i = 1; i <= fileSystem.Count(); i++)
{
CheckBox ck = (CheckBox)Master.FindControl("ContentPlaceHolder1").FindControl("delPic" );
if (pic_name[i - 1] != "" | ck.Checked)
{
supplier.pic1 = pic_name[i - 1];
if (!isStrNull(ViewState["pic1"]))
{
fileSystem.Delete(Model.supplier.Dir + "/" + ViewState["pic1"]);
}
}
}
supplier.admin_log = admin.info.u_id + " " + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
_db.SaveChanges();
Model.admin_log admin_log = new Model.admin_log();
admin_log.writeLog(admin.info.u_id, (int)Model.admin_log.Systems.Supplier, (int)Model.admin_log.Status.Update, s_number.Text + u_name.Text);
Response.Redirect("index.aspx?page=" + Convert.ToString(Request["page"]));
}
catch (Exception ex)
{
L_msg.Type = alert_type.danger;
L_msg.Text = "操作失敗";
L_msg.Text = ex.Message;
}
}
else
{
L_msg.Type = alert_type.danger;
L_msg.Text = "查無資料";
}
}
else
{
L_msg.Type = alert_type.danger;
L_msg.Text = "供應商編號";
}
}
}
#endregion
#region Ajax
protected void CallAjax()
{
if (!isStrNull(Request["type"]))
{
Response.Clear();
Response.ContentType = "application/json";
AjaxInfo info = new AjaxInfo();
info.isOk = false;
info.cDate = "";
info.sign = "";
info.msg = "";
if (ValString(Request["type"]) == "getTxt")
{
if (!isStrNull(Request["date"]) && isDate(Request["date"]))
{
DateTime date = ValDate(Request["date"]);
info.isOk = true;
info.cDate = publicFun.chagenDate(date);
}
else
info.msg = "參數不正確";
}
else if (ValString(Request["type"]) == "chkNo")
{
if (!isStrNull(Request["txt"]))
{
info.isOk = chk_pro_num(ValString(Request["txt"]), !isStrNull(Request["id"]) ? Val(Request["id"]) : 0);
if (!info.isOk)
info.msg = "供應商編號重複";
}
else
{
info.isOk = true;
info.msg = "";
}
}
else
{
info.msg = "參數不正確";
}
Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(info));
Response.End();
}
}
public class AjaxInfo
{
public bool isOk { get; set; }
public string msg { get; set; }
public string cDate { get; set; }
public string sign { get; set; }
}
#endregion
#region
protected bool chk_pro_num(string txt, int num = 0)
{
bool success = false;
var qry = _db.suppliers.AsEnumerable();
qry = qry.Where(q => q.s_number == txt);
if (num > 0)
qry = qry.Where(q => q.num != num);
var prod = qry.FirstOrDefault();
success = (prod == null);
return success;
}
#endregion
}