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,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
}