chore: 首次簽入 Thinkyu ASP.NET 專案
- 加入 Visual Studio / ASP.NET .gitignore - 排除建置輸出、IDE 設定、NuGet packages、大型 MSI 安裝檔
This commit is contained in:
@@ -0,0 +1,420 @@
|
||||
/******************************************************************************
|
||||
* 程式名稱:fmBprj 客戶專案處理
|
||||
* 作 者:楊樹人
|
||||
* 日 期:2007/12/06
|
||||
******************************************************************************/
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using System.Web.Security;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.HtmlControls;
|
||||
using System.Web.UI.WebControls;
|
||||
using System.Web.UI.WebControls.WebParts;
|
||||
using Wellan.Common;
|
||||
using Wellan.Data;
|
||||
|
||||
/// <summary>
|
||||
/// 客戶專案處理
|
||||
/// </summary>
|
||||
public partial class forms_customer_fmBprj : Wellan.Web.UI.WUserControlBase
|
||||
{
|
||||
private string _BPNUM = "";
|
||||
private string _BPPNM = "";
|
||||
private string _BPPME = "";
|
||||
//private string _CurrentBPNUM = "";
|
||||
//private string _CurrentBPPNM = "";
|
||||
private string select = "SELECT *, (SELECT TOP 1 BPYER FROM BPAA WHERE BPAA.BPPNM = BPRJ.BPPNM ORDER BY BPYER DESC) LAST_YEAR ";
|
||||
private string from = " FROM BPRJ ";
|
||||
private string where = " WHERE 1=1 ";
|
||||
private string order = " ORDER BY LAST_YEAR DESC";
|
||||
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
_BPNUM = ViewState["BPNUM"] != null ? ViewState["BPNUM"].ToString() : "";
|
||||
_BPPNM = ViewState["BPPNM"] != null ? ViewState["BPPNM"].ToString() : "";
|
||||
_BPPME = ViewState["BPPME"] != null ? ViewState["BPPME"].ToString() : "";
|
||||
//_CurrentBPNUM = ViewState["CurrentBPNUM"] != null ? ViewState["CurrentBPNUM"].ToString() : "";
|
||||
//_CurrentBPPNM = ViewState["CurrentBPPNM"] != null ? ViewState["CurrentBPPNM"].ToString() : "";
|
||||
//if (IsPostBack)
|
||||
// gvBPRJ.DataBind();
|
||||
}
|
||||
|
||||
protected override void OnInit(EventArgs e)
|
||||
{
|
||||
base.OnInit(e);
|
||||
dsBPRJForm.ConnectionString = ConnectionString;
|
||||
dsBPRJGrid.ConnectionString = ConnectionString;
|
||||
|
||||
_BPNUM = ForwardSource != "" ? GetStringParam("BCNUM") : _BPNUM;
|
||||
|
||||
GetGridViewRowColor(gvBPRJ);
|
||||
|
||||
switch (MultiView1.ActiveViewIndex)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
if (ForwardSource != "")
|
||||
{
|
||||
btnCancel.Text = "C.返回客戶資料";
|
||||
btnCancel.Width = new Unit(105);
|
||||
}
|
||||
SetClientFocus(txtBPPNM);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
Search();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 查詢畫面的查詢按鈕
|
||||
protected void btnSearch_Click(object sender, EventArgs e)
|
||||
{
|
||||
ViewState["BPNUM"] = txtBPNUM.Text;
|
||||
ViewState["BPPNM"] = txtBPPNM.Text;
|
||||
ViewState["BPPME"] = txtBPPME.Text;
|
||||
|
||||
_BPNUM = txtBPNUM.Text;
|
||||
_BPPNM = txtBPPNM.Text;
|
||||
_BPPME = txtBPPME.Text;
|
||||
|
||||
if (_BPNUM.Length == 0 &&
|
||||
_BPPNM.Length == 0 &&
|
||||
_BPPME.Length == 0)
|
||||
{
|
||||
cvMessage.ErrorMessage = GetString("NOSRHCOND");
|
||||
cvMessage.IsValid = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
MultiView1.ActiveViewIndex = 1;
|
||||
|
||||
Search();
|
||||
|
||||
gvBPRJ.PageIndex = 0;
|
||||
gvBPRJ.SelectedIndex = 0;
|
||||
gvBPRJ.DataBind();
|
||||
}
|
||||
}
|
||||
|
||||
// 查詢畫面的新增按鈕
|
||||
protected void btnInsert_Click(object sender, EventArgs e)
|
||||
{
|
||||
gvBPRJ.Visible = false;
|
||||
fvBPRJ.ChangeMode(FormViewMode.Insert);
|
||||
MultiView1.ActiveViewIndex = 1;
|
||||
}
|
||||
|
||||
// 查詢畫面的取消按鈕
|
||||
protected void btnCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
MultiView1.ActiveViewIndex = 1;
|
||||
if (ForwardSource != "")
|
||||
DoAfterCommand("BCUS");
|
||||
}
|
||||
|
||||
// 查詢動作
|
||||
private new void Search()
|
||||
{
|
||||
StringBuilder sql = new StringBuilder();
|
||||
sql.Append(select);
|
||||
sql.Append(from);
|
||||
sql.Append(where);
|
||||
dsBPRJGrid.SelectParameters.Clear();
|
||||
AddSearch(sql, dsBPRJGrid, "BPNUM", _BPNUM, "", true);
|
||||
AddSearch(sql, dsBPRJGrid, "BPPNM", _BPPNM, "", true);
|
||||
AddSearch(sql, dsBPRJGrid, "BPPME", "%" + _BPPME, "", true);
|
||||
sql.Append(order);
|
||||
dsBPRJGrid.SelectCommand = sql.ToString();
|
||||
}
|
||||
|
||||
protected string GetBtmeName(object bptme)
|
||||
{
|
||||
var btmestr = (bptme == null || bptme == DBNull.Value) ? null : bptme.ToString();
|
||||
var dv = dsBTME.Select() as List<BtmeItem>;
|
||||
if (dv == null) { return btmestr; }
|
||||
var btmeItem = dv.FirstOrDefault(p => p.BTTID == btmestr);
|
||||
if (btmeItem != null) { return btmeItem.BTNME; }
|
||||
return btmestr;
|
||||
}
|
||||
|
||||
protected void gvBPRJ_DataBound(object sender, EventArgs e)
|
||||
{
|
||||
GridView_DataBound(sender, e);
|
||||
if (gvBPRJ.SelectedIndex == -1)
|
||||
gvBPRJ.SelectedIndex = 0;
|
||||
|
||||
// 返回時,回到之前選擇的那一筆
|
||||
if (ParamList.ContainsKey("BPNUM") && ParamList.ContainsKey("BPPNM"))
|
||||
{
|
||||
string bpnum = WDAC.GetStringValue(ParamList["BPNUM"]);
|
||||
string bppnm = WDAC.GetStringValue(ParamList["BPPNM"]);
|
||||
|
||||
DataView dv = dsBPRJGrid.Select(new DataSourceSelectArguments()) as DataView;
|
||||
dv.RowFilter = String.Format("BPNUM='{0}' and BPPNM='{1}'", bpnum, bppnm);
|
||||
if (dv.Count > 0)
|
||||
{
|
||||
int rowIndex = dv.Table.Rows.IndexOf(dv[0].Row);
|
||||
gvBPRJ.PageIndex = (rowIndex / gvBPRJ.PageSize);
|
||||
gvBPRJ.SelectedIndex = rowIndex - gvBPRJ.PageIndex * gvBPRJ.PageSize;
|
||||
}
|
||||
|
||||
ParamList.Remove("BPNUM");
|
||||
ParamList.Remove("BPPNM");
|
||||
}
|
||||
|
||||
fvBPRJ.DataBind();
|
||||
}
|
||||
|
||||
protected void gvBPRJ_PageIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
Search();
|
||||
gvBPRJ.SelectedIndex = 0;
|
||||
gvBPRJ.DataBind();
|
||||
}
|
||||
|
||||
// 資料擷取完後的事件
|
||||
protected void dsBPRJGrid_Selected(object sender, SqlDataSourceStatusEventArgs e)
|
||||
{
|
||||
// 沒有資料,回到查詢畫面
|
||||
if (e.AffectedRows == 0)
|
||||
{
|
||||
if (MultiView1.ActiveViewIndex != 0)
|
||||
MultiView1.ActiveViewIndex = 0;
|
||||
|
||||
if (ForwardSource == "")
|
||||
cvMessage.ErrorMessage = GetString("NODATA");
|
||||
else
|
||||
{
|
||||
cvMessage.ErrorMessage = "此客戶沒有專案資料,請重新輸入條件查詢";
|
||||
btnCancel.Text = "C.返回客戶資料";
|
||||
btnCancel.Width = new Unit(105);
|
||||
}
|
||||
|
||||
SetClientFocus(txtBPPNM);
|
||||
cvMessage.IsValid = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected void fvBPRJ_ItemCommand(object sender, FormViewCommandEventArgs e)
|
||||
{
|
||||
switch (e.CommandName)
|
||||
{
|
||||
case "Search":
|
||||
MultiView1.ActiveViewIndex = 0;
|
||||
SetClientFocus(txtBPPNM);
|
||||
break;
|
||||
case "Cancel":
|
||||
Search();
|
||||
fvBPRJ.ChangeMode(FormViewMode.ReadOnly);
|
||||
fvBPRJ_ModeChanged(sender, e);
|
||||
break;
|
||||
case "BPAA":
|
||||
case "BPRM":
|
||||
fvBPRJ.DataBind();
|
||||
|
||||
if (fvBPRJ.DataItem != null)
|
||||
{
|
||||
DataRowView rv = fvBPRJ.DataItem as DataRowView;
|
||||
// ParamList.Clear();
|
||||
ParamList.Add("BPNUM", rv["BPNUM"]);
|
||||
ParamList.Add("BPPNM", rv["BPPNM"]);
|
||||
DoAfterCommand(e.CommandName);
|
||||
}
|
||||
break;
|
||||
case "BCUS":
|
||||
DoAfterCommand("BCUS");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected void fvBPRJ_ItemDeleted(object sender, FormViewDeletedEventArgs e)
|
||||
{
|
||||
Search();
|
||||
gvBPRJ.DataBind();
|
||||
if (gvBPRJ.SelectedIndex > gvBPRJ.Rows.Count - 1)
|
||||
{
|
||||
gvBPRJ.SelectedIndex = gvBPRJ.Rows.Count - 1;
|
||||
gvBPRJ.DataBind();
|
||||
}
|
||||
fvBPRJ.DataBind();
|
||||
}
|
||||
|
||||
protected void fvBPRJ_ItemInserted(object sender, FormViewInsertedEventArgs e)
|
||||
{
|
||||
Search();
|
||||
}
|
||||
|
||||
protected void fvBPRJ_ItemUpdated(object sender, FormViewUpdatedEventArgs e)
|
||||
{
|
||||
Search();
|
||||
}
|
||||
|
||||
// FormView 模式切換後的事件
|
||||
protected void fvBPRJ_ModeChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (fvBPRJ.CurrentMode == FormViewMode.ReadOnly)
|
||||
{
|
||||
gvBPRJ.Visible = true;
|
||||
gvBPRJ.DataBind();
|
||||
if (gvBPRJ.Rows.Count > 0 && gvBPRJ.SelectedIndex == -1)
|
||||
{
|
||||
gvBPRJ.SelectedIndex = 0;
|
||||
}
|
||||
|
||||
if (OldMode == FormViewMode.Insert)
|
||||
{
|
||||
gvBPRJ.PageIndex = gvBPRJ.PageCount - 1;
|
||||
gvBPRJ.DataBind();
|
||||
gvBPRJ.SelectedIndex = gvBPRJ.Rows.Count - 1;
|
||||
}
|
||||
|
||||
fvBPRJ.DataBind();
|
||||
}
|
||||
else
|
||||
{
|
||||
gvBPRJ.Visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected void fvBPRJ_ModeChanging(object sender, FormViewModeEventArgs e)
|
||||
{
|
||||
OldMode = (sender as FormView).CurrentMode;
|
||||
}
|
||||
|
||||
protected void fvBPRJ_DataBound(object sender, EventArgs e)
|
||||
{
|
||||
if (fvBPRJ.CurrentMode == FormViewMode.Insert || fvBPRJ.CurrentMode == FormViewMode.Edit)
|
||||
{
|
||||
RegisterLookupEvent(fvBPRJ, "btnBPRJ_BPNUM_WQRY", "txtBPRJ_BPNUM", "txtBPRJ_BPNUM,lbBPRJ_BPNUMX", "BCUS");
|
||||
|
||||
switch (fvBPRJ.CurrentMode)
|
||||
{
|
||||
case FormViewMode.Edit:
|
||||
SetControlFocus(fvBPRJ, "txtBPRJ_BPPME");
|
||||
break;
|
||||
case FormViewMode.Insert:
|
||||
SetControlFocus(fvBPRJ, "txtBPRJ_BPPNM");
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SetControlEnabled(fvBPRJ, "btnBPRM", CheckRight("FMBPRM", WRightName.Execute));
|
||||
}
|
||||
}
|
||||
|
||||
protected void CalcFields(System.Collections.Specialized.IOrderedDictionary values)
|
||||
{
|
||||
//values["BPSSB"] = (fvBPRJ.FindControl("cbBPRJ_BPSSB") as CheckBox).Checked ? "Y" : "N";
|
||||
values["BPWTN"] = (fvBPRJ.FindControl("cbBPRJ_BPWTN") as CheckBox).Checked ? "Y" : "N";
|
||||
}
|
||||
|
||||
// 新增存檔前
|
||||
protected void fvBPRJ_ItemInserting(object sender, FormViewInsertEventArgs e)
|
||||
{
|
||||
CalcFields(e.Values);
|
||||
// 取消自動編號 2011-01-11 SRYANG
|
||||
// string _bprjTrd = (fvBPRJ.FindControl("ddlTrade") as DropDownList).SelectedValue;
|
||||
// string _bcusHdr = e.Values["BPNUM"].ToString().Substring(0, 2);
|
||||
// e.Values["BPPNM"] = WGuard1.WNextRen(DateTime.UtcNow.AddHours(8), "BPRJ", "BPPNM", String.Format("\"{0}{1}\"<999>", _bcusHdr, _bprjTrd), "");
|
||||
}
|
||||
|
||||
// 更正存檔前
|
||||
protected void fvBPRJ_ItemUpdating(object sender, FormViewUpdateEventArgs e)
|
||||
{
|
||||
CalcFields(e.NewValues);
|
||||
}
|
||||
|
||||
// 刪除前
|
||||
protected void fvBPRJ_ItemDeleting(object sender, FormViewDeleteEventArgs e)
|
||||
{
|
||||
// 刪除前檢查
|
||||
// 檢查是否有專案預算資料
|
||||
DbCommand cmd = Query.NewCommand("SELECT COUNT(1) FROM BPAA WHERE BPPNM=@BPPNM");
|
||||
cmd.Parameters.Add(Query.NewParameter("BPPNM", e.Keys["BPPNM"]));
|
||||
object o = Query.ExecuteScalar(cmd);
|
||||
if (o != null && Convert.ToInt32(o) > 0)
|
||||
{
|
||||
cvMessage.IsValid = false;
|
||||
cvMessage.ErrorMessage = "此專案有專案預算資料,不可刪除";
|
||||
e.Cancel = true;
|
||||
}
|
||||
|
||||
// TODO: 檢查是否有專案派遣資料
|
||||
// TODO: 檢查是否有專案核銷資料
|
||||
}
|
||||
|
||||
protected void cvBPNUM_ServerValidate(object source, ServerValidateEventArgs args)
|
||||
{
|
||||
CustomValidator v = source as CustomValidator;
|
||||
|
||||
// 檢查客戶編號是否輸入,是否存在
|
||||
if (args.Value == "")
|
||||
{
|
||||
args.IsValid = false;
|
||||
v.Text = "請輸入客戶編號";
|
||||
}
|
||||
|
||||
DbCommand cmd = Query.NewCommand("SELECT COUNT(1) FROM BCUS WHERE BCNUM=@BCNUM");
|
||||
cmd.Parameters.Add(Query.NewParameter("BCNUM", args.Value));
|
||||
object o = Query.ExecuteScalar(cmd);
|
||||
if (o == null || Convert.ToInt32(o) == 0)
|
||||
{
|
||||
args.IsValid = false;
|
||||
v.Text = "客戶編號不存在!請重新輸入。";
|
||||
}
|
||||
|
||||
args.IsValid = true;
|
||||
}
|
||||
|
||||
protected void MultiView1_ActiveViewChanged(object sender, EventArgs e)
|
||||
{
|
||||
switch (MultiView1.ActiveViewIndex)
|
||||
{
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected void gvBPRJ_RowDataBound(object sender, GridViewRowEventArgs e)
|
||||
{
|
||||
SetGridViewMouseBehavier(sender as GridView, e.Row);
|
||||
//GridView_RowDataBound_Shrink_ViewState(sender, e);
|
||||
}
|
||||
|
||||
protected void gvBPRJ_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
foreach (GridViewRow row in (sender as GridView).Rows)
|
||||
SetGridViewMouseBehavier(sender as GridView, row);
|
||||
}
|
||||
|
||||
protected void cvOverTime_ServerValidate(object source, ServerValidateEventArgs args)
|
||||
{
|
||||
CustomValidator cv = source as CustomValidator;
|
||||
double i;
|
||||
args.IsValid = args.Value != "" && double.TryParse(args.Value, out i) && i >= 0d && i <= 3d;
|
||||
}
|
||||
|
||||
protected void cvBPPNM_ServerValidate(object source, ServerValidateEventArgs args)
|
||||
{
|
||||
// 新增時 專案編號 重複檢查
|
||||
DbCommand cmd = Query.NewCommand("SELECT COUNT(1) FROM BPRJ WHERE BPPNM=@BPPNM");
|
||||
cmd.Parameters.Add(Query.NewParameter("BPPNM", args.Value));
|
||||
object o = Query.ExecuteScalar(cmd);
|
||||
args.IsValid = o == null || Convert.ToInt32(o) == 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user