ChargeDetailMaterial.aspx.cs
上传用户:tiancihang
上传日期:2014-03-12
资源大小:21387k
文件大小:17k
源码类别:
.net编程
开发平台:
C#
- using System;
- using System.Data;
- using System.Configuration;
- using System.Collections;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.SessionState;
- using System.ComponentModel;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- using System.Data.SqlClient;
- using com.etong.BusinessRule.Zwf;
- using com.etong.DAL.FC;
- using com.etong.Inform;
- public partial class Workflow_ChargeDetailMaterial : System.Web.UI.Page
- {
- protected int projectid = -1;
- protected void Page_Load(object sender, EventArgs e)
- {
- Response.Buffer = true;
- Response.ExpiresAbsolute = System.DateTime.Now;
- Response.Expires = 0;
- Response.CacheControl = "no-cache";
- string project = Request.QueryString["projectid"].ToString();
- //string project = "22";
- if (project != "")
- projectid = Convert.ToInt32(project);
- else
- {
- ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('系统提示:您尚未登录或您登录已超时,请重新登录');location.href='../../login.aspx'</script>");
- return;
- }
- if (!IsPostBack)
- {
- ((HtmlInputHidden)Page.FindControl("status")).Value = "0"; //不可见状态
- ((HtmlInputHidden)Page.FindControl("TxtSeacher")).Value = "1";
- PanelAdd.Visible = false;
- EtongFlyChouWFNM EFlyNM = new EtongFlyChouWFNM();
- EFlyNM.Prj = projectid;
- EFlyNM.sstatus = 1;
- DataView dv = new DataView();
- try
- {
- dv=EFlyNM.ProMaterialGetByPrjId();
- }
- catch (Exception ex)
- {
- this.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('" + ex.Message.Replace("'", "").Replace("rn", "").Replace("n", "") + "');</script>");
- return;
- }
- GridView1.DataSource = dv;
- GridView1.DataBind();
- BindParent();
- RBL_Type.Attributes.Add("onclick", "javascript:return DBLChange()");
- TB_SearchContent.Attributes.Add("onkeypress", "EnterTextBox()");
- }
- }
- protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
- {
- if (e.Row.RowIndex == 0)
- {
- ((HtmlInputHidden)Page.FindControl("HjCount")).Value = "0";
- }
- if (e.Row.RowType == DataControlRowType.DataRow)
- {
- decimal p = decimal.Parse(e.Row.Cells[5].Text.Trim());
- int n = Convert.ToInt32(e.Row.Cells[6].Text.Trim());
- //e.Row.Cells[7].Text = Convert.ToString((decimal.Parse(e.Row.Cells[4].Text.Trim()) - p));
- //e.Row.Cells[8].Text = Convert.ToString(p * n);
- //e.Row.Cells[0].Text = MeterialName[0].ToString().Trim();
- //e.Row.Cells[1].Text = MeterialName[1].ToString().Trim();
- decimal count = decimal.Parse(((HtmlInputHidden)Page.FindControl("HjCount")).Value.Trim());
- ((HtmlInputHidden)Page.FindControl("HjCount")).Value = Convert.ToString(count + decimal.Parse(e.Row.Cells[8].Text.Trim()));
- }
- }
- protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
- {
- int materialid = Convert.ToInt16(GridView1.DataKeys[e.RowIndex].Value.ToString());
- EtongFlyChouWFNM EFlyNM = new EtongFlyChouWFNM();
- EFlyNM.CommID = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString());
- EFlyNM.sstatus = 1;
- //CheckUserInfo UInfo = (CheckUserInfo)Session["checkuserinfo"];
- //EFlyNM.UserName = UInfo.EmpName;
- try
- {
- EFlyNM.ProMaterialDelete();
- }
- catch (Exception ex)
- {
- this.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('" + ex.Message.Replace("'", "").Replace("rn", "").Replace("n", "") + "');</script>");
- return;
- }
- //bool bl = false;
- //EtongZwf etongzwf = new EtongZwf();
- //bl=etongzwf.ProMaterialDelete(materialid);
- //if (bl == false)
- //{
- // this.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('系统提示:删除失败!');", true);
- // return;
- //}
- this.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('系统提示:删除成功!');", true);
- EFlyNM.Prj = projectid;
- EFlyNM.sstatus = 1;
- DataView dv = EFlyNM.ProMaterialGetByPrjId();
- GridView1.DataSource = dv;
- GridView1.DataBind();
- }
- protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
- {
- PanelAdd.Visible = true;
- ((HtmlInputHidden)Page.FindControl("status")).Value = "2"; //编辑状态
- dListParent.Items.FindByValue(dListParent.SelectedValue).Selected = false;
- dListParent.Items.FindByValue(GridView1.Rows[e.NewEditIndex].Cells[2].Text.Trim().Substring(0, 4)).Selected = true;
- //dListParent.SelectedItem.Text = GridView1.Rows[e.NewEditIndex].Cells[2].Text.Trim();
- string dListParentid = dListParent.SelectedValue;
- BindChild(dListParentid);
- dListChild.Items.FindByValue(dListChild.SelectedValue).Selected = false;
- dListChild.Items.FindByValue(GridView1.Rows[e.NewEditIndex].Cells[2].Text.Trim()).Selected = true;
- //dListChild.SelectedItem.Text = GridView1.Rows[e.NewEditIndex].Cells[1].Text.Trim();
- TBWZ.Text = GridView1.Rows[e.NewEditIndex].Cells[2].Text.Trim();
- TB_UnitName.Text = GridView1.Rows[e.NewEditIndex].Cells[3].Text.Trim();
- TB_BudGetPrice.Text = GridView1.Rows[e.NewEditIndex].Cells[4].Text.Trim();
- TB_MarketPrice.Text = GridView1.Rows[e.NewEditIndex].Cells[5].Text.Trim();
- TB_Number.Text = GridView1.Rows[e.NewEditIndex].Cells[6].Text.Trim();
- TB_count.Text = GridView1.Rows[e.NewEditIndex].Cells[7].Text.Trim(); //单位差价
- TB_DifferencePriceSum.Text = GridView1.Rows[e.NewEditIndex].Cells[8].Text.Trim();
- ((HtmlInputHidden)Page.FindControl("equipmentid")).Value = GridView1.DataKeys[e.NewEditIndex].Value.ToString().Trim(); // DataKeyNames;
- }
- protected void BT_Confirm_Click(object sender, ImageClickEventArgs e)
- {
- PanelAdd.Visible = false;
- string MaterialName = dListParent.SelectedItem.Text.Trim(); //材料名称
- string MaterialSize = dListChild.SelectedItem.Text.Trim(); //材料规格
- int MaterialWZID = Convert.ToInt32(TBWZ.Text); //材料代码
- string UnitName = TB_UnitName.Text.Trim(); //生产单位
- int Number; //数量
- try
- {
- Number = Convert.ToInt32(TB_Number.Text.Trim());
- }
- catch
- {
- Number = 0;
- this.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('系统提示:数量必需大于零,新增失败!');", true);
- return;
- }
- decimal BudGetPrice = 0; //预算原价
- try
- {
- BudGetPrice = decimal.Parse(TB_BudGetPrice.Text.Trim());
- }
- catch
- {
- BudGetPrice = 0;
- }
- decimal MarketPrice = 0; //市场价
- try
- {
- MarketPrice = decimal.Parse(TB_MarketPrice.Text.Trim());
- }
- catch
- {
- MarketPrice = 0;
- this.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('系统提示:市场价必需大于零,新增失败!');", true);
- return;
- }
- decimal DifferencePrice = 0; // 差价(小计)
- try
- {
- DifferencePrice = decimal.Parse(txtcount.Value.Trim());
- }
- catch
- {
- DifferencePrice = 0;
- }
- decimal DifferencePriceSum = 0; //实际总价
- try
- {
- DifferencePriceSum = decimal.Parse(txtsum.Value.Trim());
- }
- catch
- {
- DifferencePriceSum = 0;
- }
- string status = ((HtmlInputHidden)Page.FindControl("status")).Value;
- EtongZwf etongzwf = new EtongZwf();
- EtongFlyChouWFNM EFlyNM = new EtongFlyChouWFNM();
- EFlyNM.Bud = BudGetPrice;
- EFlyNM.Diff = DifferencePrice;
- EFlyNM.DiffSum = DifferencePriceSum;
- EFlyNM.Mark = MarketPrice;
- EFlyNM.CommName = MaterialName;
- EFlyNM.WZ = MaterialWZID;
- EFlyNM.CommSize = MaterialSize;
- EFlyNM.Num = Number;
- EFlyNM.Unit = UnitName;
- EFlyNM.Prj = projectid;
- CheckUserInfo UInfo = (CheckUserInfo)Session["checkuserinfo"];
- EFlyNM.UserName = UInfo.EmpName;
- if (status == "1") // 新增
- {
- int err = 1;
- EFlyNM.status = 1;
- try
- {
- err=EFlyNM.ProMaterialInsert();
- }
- catch (Exception ex)
- {
- this.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('" + ex.Message.Replace("'", "").Replace("rn", "").Replace("n", "") + "');</script>");
- return;
- }
- if (err == -1)
- {
- this.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('系统提示:新增失败,不能新增相同物资材料代码!');", true);
- return;
- }
- else
- this.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('系统提示:新增成功!');", true);
- }
- else if (status == "2") //编辑
- {
- EFlyNM.status = 2;
- HtmlInputHidden txt_equipmentid = ((HtmlInputHidden)Page.FindControl("equipmentid"));
- EFlyNM.CommID = Convert.ToInt32(txt_equipmentid.Value.Trim());
- EFlyNM.sstatus = 1;
- int err = 0;
- try
- {
- err=EFlyNM.ProMaterialUpdate();
- }
- catch (Exception ex)
- {
- this.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('" + ex.Message.Replace("'", "").Replace("rn", "").Replace("n", "") + "');</script>");
- return;
- }
- if (err == -1)
- this.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('系统提示:更新成功!');", true);
- else if (err == 1) this.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('未找到要更新的内容,请查证后再试!');", true);
- else if (err == 2) this.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('未发生变化无需更新,请查证后再试!');", true);
- }
- //this.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('系统提示:操作成功!');", true);
- DataView dv = new DataView();
- EFlyNM.sstatus = 1;
- try
- {
- dv=EFlyNM.ProMaterialGetByPrjId();
- }
- catch (Exception ex)
- {
- this.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('" + ex.Message.Replace("'", "").Replace("rn", "").Replace("n", "") + "');</script>");
- return;
- }
- GridView1.DataSource = dv;
- GridView1.DataBind();
- ((HtmlInputHidden)Page.FindControl("status")).Value = "0"; //不可见状态
- ClearText();
- }
- protected void ClearText()
- {
- TB_UnitName.Text = "";
- // TB_BudGetPrice.Text = "";
- TB_Number.Text = "1";
- TB_MarketPrice.Text = "0";
- TB_DifferencePriceSum.Text = "0";
- TB_count.Text = "0";
- }
- protected void BT_Cancel_Click(object sender, ImageClickEventArgs e)
- {
- PanelAdd.Visible = false;
- ((HtmlInputHidden)Page.FindControl("status")).Value = "0"; //不可见状态
- ClearText();
- }
- protected void dListParent_SelectedIndexChanged(object sender, EventArgs e)
- {
- string dListParentid = dListParent.SelectedValue;
- BindChild(dListParentid);
- }
- protected void BindParent()
- {
- DataView dv = new DataView();
- EtongFlyChouWFNM EFlyNM = new EtongFlyChouWFNM();
- dv = EFlyNM.GetBigWZList();
- for (int i = 0; i < dv.Table.Rows.Count; i++)
- {
- dListParent.Items.Add(new ListItem(dv.Table.Rows[i][2].ToString(), dv.Table.Rows[i][0].ToString() + dv.Table.Rows[i][1].ToString()));
- }
- dListParent.Items[0].Selected = true;
- string str1 = dListParent.SelectedValue;
- BindChild(str1);
- }
- protected void BindChild(string str)
- {
- str = "material_name where wz_id like '" + str + "%'";
- EtongFlyChouCode EFlyCode = new EtongFlyChouCode();
- DataView dv = EFlyCode.BStringSelect("wz_id,wz_spec", str, 2);
- dListChild.DataSource = dv;
- dListChild.DataTextField = "wz_spec";
- dListChild.DataValueField = "wz_id";
- dListChild.DataBind();
- TBWZ.Text = dListChild.SelectedValue.ToString();
- }
- protected void dListChild_SelectedIndexChanged(object sender, EventArgs e)
- {
- string dListChildid = dListChild.SelectedValue.Trim();
- EtongFlyChouWFNM EFlyNM = new EtongFlyChouWFNM();
- EFlyNM.WZ = Convert.ToInt32(dListChildid);
- string budgetprice = EFlyNM.ProBudGetPriceGetByWzId();
- if (budgetprice == "")
- TB_BudGetPrice.Text = "0";
- else
- TB_BudGetPrice.Text = budgetprice;
- TBWZ.Text = dListChildid;
- }
- protected void IB_Search_Click(object sender, ImageClickEventArgs e)
- {
- int iSearch;
- try
- {
- iSearch = Convert.ToInt32(RBL_Type.SelectedValue.Trim());
- }
- catch
- {
- iSearch = 0;
- }
- string strContent = TB_SearchContent.Text.Trim();
- string sFiled = "wz_id,wz_name,wz_spec,wz_plan";
- string sTable = "material_name where ";
- DataView dv = new DataView();
- EtongFlyChouCode EFlyCode = new EtongFlyChouCode();
- if (iSearch == 1)
- {
- Int64 iContent;
- try
- {
- iContent = Convert.ToInt64(strContent);
- }
- catch
- {
- iContent = -1;
- }
- sTable = sTable + "wz_id=" + iContent.ToString();
- dv = EFlyCode.BStringSelect(sFiled, sTable, 2);
- if (dv.Table.Rows.Count > 0)
- {
- if (iSearch == 1)
- {
- if (((HtmlInputHidden)Page.FindControl("status")).Value == "0") ((HtmlInputHidden)Page.FindControl("status")).Value = "1";
- PanelAdd.Visible = true;
- dListParent.Items.FindByValue(dListParent.SelectedValue).Selected = false;
- dListParent.Items.FindByValue(dv.Table.Rows[0][0].ToString().Substring(0, 4)).Selected = true;
- BindChild(dv.Table.Rows[0][0].ToString().Substring(0, 4));
- dListChild.Items.FindByValue(dListChild.SelectedValue).Selected = false;
- dListChild.Items.FindByValue(dv.Table.Rows[0][0].ToString()).Selected = true;
- TBWZ.Text = dv.Table.Rows[0][0].ToString();
- TB_BudGetPrice.Text = dv.Table.Rows[0][3].ToString();
- }
- }
- else
- {
- this.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('系统提示:未找到对应的物资代码!');", true);
- }
- }//isercher 1
- else if (iSearch == 2)
- {
- if (((HtmlInputHidden)Page.FindControl("status")).Value == "0") ((HtmlInputHidden)Page.FindControl("status")).Value = "1";
- PanelAdd.Visible = true;
- dListParent.Items.FindByValue(dListParent.SelectedValue).Selected = false;
- dListParent.Items.FindByValue(TxtWZ.Value.ToString().Substring(0, 4)).Selected = true;
- BindChild(TxtWZ.Value.ToString().Substring(0, 4));
- dListChild.Items.FindByValue(dListChild.SelectedValue).Selected = false;
- dListChild.Items.FindByValue(TxtWZ.Value.ToString()).Selected = true;
- TBWZ.Text = TxtWZ.Value.ToString();
- EtongFlyChouWFNM EFlyNM = new EtongFlyChouWFNM();
- EFlyNM.WZ = Convert.ToInt32(TxtWZ.Value.Trim());
- TB_BudGetPrice.Text = EFlyNM.ProBudGetPriceGetByWzId();
- }
- }
- protected void IB_Add_Click(object sender, ImageClickEventArgs e)
- {
- PanelAdd.Visible = true;
- ((HtmlInputHidden)Page.FindControl("status")).Value = "1"; //新增状态
- }
- }