| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using CoreFS.CA03;
- using CoreFS.CA04;
- using CoreFS.CA06;
- using System.Collections;
- using Infragistics.Win.UltraWinGrid;
- using Core.Mes.Client.Comm.Server;
- using Core.Mes.Client.Comm.Control;
- using Core.Mes.Client.Comm.Tool;
- namespace Core.StlMes.Client.SaleBase
- {
- public partial class frmSaleRegion : FrmBase
- {
- public frmSaleRegion()
- {
- InitializeComponent();
- }
- private void frmSaleRegion_Load(object sender, EventArgs e)
- {
- bindSaleRegion();
- doGetSaleOrg();
- bindDeparTRegion(UserInfo.GetDeptid().Substring(0, UserInfo.GetDeptid().Length-3));
- doQuery();
- }
- protected override void OnLoad(EventArgs e)
- {
- try
- {
- base.OnLoad(e);
- ultraGrid2.DisplayLayout.Override.FilterUIType = Infragistics.Win.UltraWinGrid.FilterUIType.FilterRow;
- ultraGrid2.DisplayLayout.Override.FilterOperatorDefaultValue = Infragistics.Win.UltraWinGrid.FilterOperatorDefaultValue.Contains;
- //ultraGrid2.DisplayLayout.Override.CellClickAction = Infragistics.Win.UltraWinGrid.CellClickAction.RowSelect;
- }
- catch (System.Exception ex)
- { }
- }
- /// <summary>
- /// 根据登录账户,判断所属部门。
- /// </summary>
- private void doGetSaleOrg()
- {
- UserInfo.SaleOrg = ClsBaseInfo.GetSaleOrg(UserInfo.GetDeptid());
- cmbSaleRegionName.Value = UserInfo.SaleOrg;
- }
-
- /// <summary>
- /// 重写基类方法
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="ToolbarKey"></param>
- public override void ToolBar_Click(object sender, string ToolbarKey)
- {
- //if (UserInfo.SaleOrg.Equals("NONE"))
- //{
- // MessageBox.Show("未授权,不允许查看!");
- // return;
- //}
- switch (ToolbarKey)
- {
- case "doQuery":
- doQuery();
- break;
- case "doAdd":
- doAdd();
- break;
- case "doUpdate":
- doUpdate();
- break;
- case "doDelete":
- this.doDeleteOrRecovery(true);
- break;
- case "doRecovery":
- this.doDeleteOrRecovery(false);
- break;
- case "doClose":
- this.Close();
- break;
- }
- }
- /// <summary>
- /// 绑定销售组织数据源。
- /// </summary>
- private void bindSaleRegion()
- {
- DataTable dt = ServerHelper.GetData("com.steering.pss.sale.base.CoreSaleRegion.GetSaleRegion", null, this.ob);
-
- //编辑区域销售组织数据源绑定,不提供空值。
- cmbSaleRegionName.DataSource = dt;
- cmbSaleRegionName.DisplayMember = "BASENAME";
- cmbSaleRegionName.ValueMember = "BASECODE";
- cmbSaleRegionName.DataBind();
- }
- /// <summary>
- /// 绑定销售组织科室名称数据源。
- /// </summary>
- private void bindDeparTRegion(string departId)
- {
- if (string.IsNullOrEmpty(departId))
- {
- return;
- }
- DataTable dt = null;
- if ("100101".Equals(departId))
- {
- departId = "002001042001";
- dt = ServerHelper.GetData("com.steering.pss.sale.base.CoreSaleRegion.GetDEPARTNAME", new Object[] { departId }, this.ob);
- }
- if ("100102".Equals(departId))
- {
- departId = "002001042002";
- dt = ServerHelper.GetData("com.steering.pss.sale.base.CoreSaleRegion.GetDepartNameLike", new Object[] { departId }, this.ob);
- }
- if ("100103".Equals(departId))
- {
- departId = "002001042003";
- dt = ServerHelper.GetData("com.steering.pss.sale.base.CoreSaleRegion.GetDEPARTNAME", new Object[] { departId }, this.ob);
- }
- if ("100105".Equals(departId))
- {
- departId = "002023";
- dt = ServerHelper.GetData("com.steering.pss.sale.base.CoreSaleRegion.GetDEPARTNAME", new Object[] { departId }, this.ob);
- }
- //DataRow drTh = dt.NewRow();
- //drTh["id"] = "C";
- //drTh["name"] = "其它";
- //dt.Rows.Add(drTh);
- //编辑区域销售组织科室名称数据源绑定,不提供空值。
- if (dt == null)
- {
- return;
- }
- ultraComboDepar.DataSource = dt;
- ultraComboDepar.DisplayMember = "DEPARTNAME";
- ultraComboDepar.ValueMember = "DEPARTID";
- ultraComboDepar.Value = UserInfo.GetDeptid();
- ultraComboDepar.DataBind();
- }
- /// <summary>
- /// 查询
- /// </summary>
- private void doQuery()
- {
- bool validFlag = chkValid.Checked;
- string titleName = UserInfo.SaleOrg;
- if (UserInfo.GetUserName() == "admin")
- titleName = "100101";
- DataTable dt = ServerHelper.GetData("com.steering.pss.sale.base.CoreSaleRegion.doQuery", new Object[] { validFlag, titleName }, this.ob);
- GridHelper.CopyDataToDatatable(ref dt, ref this.dataTable1, true);
- //不同颜色区分是否有效数据
- Infragistics.Win.UltraWinGrid.UltraGridRow row = null;
- for (int i = 0; i < ultraGrid2.Rows.Count; i++)
- {
- row = ultraGrid2.Rows[i];
- if (!row.Cells["VALIDFLAG"].Value.ToString().Equals("1"))
- {
- row.Cells["VALIDFLAG"].Value = false;
- row.Appearance.ForeColor = Color.Red;
- }
- else
- {
- row.Cells["VALIDFLAG"].Value = true;
- row.Appearance.ForeColor = Color.Black;
- }
- }
- //列自适应
- GridHelper.RefreshAndAutoSizeExceptRows(ultraGrid2, new UltraGridColumn[] {
- ultraGrid2.DisplayLayout.Bands[0].Columns["MEMO"]
- });
- }
- /// <summary>
- /// 验证非空字段。
- /// </summary>
- /// <returns></returns>
- private bool ValidInput()
- {
- if (cmbSaleRegionName.SelectedItem == null)
- {
- MessageBox.Show("销售组织不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return false;
- }
- if (ultraComboDepar.SelectedItem == null)
- {
- MessageBox.Show("销售科室不能为空,若不存在请先维护组织信息!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return false;
- }
- if (string.IsNullOrEmpty(txtAreaDesc.Text.Trim()))
- {
- MessageBox.Show("请输入业务片区!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return false;
- }
- return true;
- }
- /// <summary>
- /// 业务片区是否重复。
- /// </summary>
- /// <param name="name"></param>
- /// <returns></returns>
- private bool isRepeatName(string name,string saleOrg,string dept)
- {
- DataTable dt = new DataTable();
- string saleRegionCode = cmbSaleRegionName.Value.ToString();
- dt = ServerHelper.GetData("com.steering.pss.sale.base.CoreSaleRegion.isRepeatName", new Object[] { name, saleOrg, dept }, this.ob);
- if (dt.Rows.Count > 0)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- /// <summary>
- /// 自动生成业务片区编号
- /// </summary>
- /// <returns></returns>
- private int GetMaxCode()
- {
- //判断当前销售组织下是否有记录存在。
- string saleRegionCode = cmbSaleRegionName.Value.ToString();
- DataTable dt = ServerHelper.GetData("com.steering.pss.sale.base.CoreSaleRegion.GetMaxCode", new Object[] { saleRegionCode }, this.ob);
- string maxCode = "";
- int autoCode = 0;
- if (dt.Rows.Count > 0)
- {
- if (!"".Equals(dt.Rows[0][0].ToString()))
- {
- maxCode = dt.Rows[0][0].ToString();
- if (StringUtil.IsNumber(maxCode))
- {
- autoCode = Convert.ToInt32(maxCode) + 1;
- }
- else
- {
- return 0;
- }
- }
- else
- {
- maxCode = saleRegionCode + "01";
- autoCode = Convert.ToInt32(maxCode);
- }
- }
- return autoCode;
- }
- /// <summary>
- /// 新增
- /// </summary>
- private void doAdd()
- {
- if (ValidInput())
- {
- try
- {
- //验证描述不允许重复,必须依据销售组织。
- string name = txtAreaDesc.Text.Trim();
- //获取销售组织名称,用于明确提示信息。
- string saleRegionName = cmbSaleRegionName.Value.ToString();
- string dept = ultraComboDepar.Value.ToString();
- if (isRepeatName(name, saleRegionName, dept))
- {
- //国贸公司业务片区"东部"已存在,请重新输入!
- MessageBox.Show(cmbSaleRegionName.Text + "-业务片区\"" + name + "\"已存在,请重新输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- ArrayList parm = new ArrayList();
- int areaCode = GetMaxCode();
- //自动生成编号
- if (areaCode == 0)
- {
- MessageBox.Show("编码格式有误,由于直接操作数据库导致,请与系统管理员联系。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- parm.Add(cmbSaleRegionName.Value.ToString());
- parm.Add(areaCode);
- parm.Add(name);
- parm.Add(txtMemo.Text);
- parm.Add(this.UserInfo.GetUserName());
-
- parm.Add(ultraComboDepar.Value.ToString());
- CoreClientParam ccp = new CoreClientParam();
- ccp.ServerName = "com.steering.pss.sale.base.CoreSaleRegion";
- ccp.MethodName = "doAdd";
- ccp.ServerParams = new object[] { parm };
- ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
- if (ccp.ReturnCode == -1) return;
- doQuery();
- //高亮显示新增的数据
- Infragistics.Win.UltraWinGrid.UltraGridRow row = null;
- for (int i = 0; i < ultraGrid2.Rows.Count; i++)
- {
- row = ultraGrid2.Rows[i];
- if (row.Cells["SALE_AREA_NO"].Value.ToString().Equals(areaCode.ToString()))
- {
- row.Activate();
- break;
- }
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- }
- }
- /// <summary>
- /// 修改
- /// </summary>
- private void doUpdate()
- {
- if (ultraGrid2.ActiveRow == null)
- {
- MessageBox.Show("请选择需要修改的数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- Boolean validflagStr = Convert.ToBoolean(ultraGrid2.ActiveRow.Cells["VALIDFLAG"].Value);
- //无效数据不允许修改
- if (!validflagStr)
- {
- MessageBox.Show("无效数据不支持修改操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- if (ValidInput())
- {
- //验证描述不允许重复。
- string name = txtAreaDesc.Text.Trim();
- string saleOrg = cmbSaleRegionName.Value.ToString();
- string dept = ultraComboDepar.Value.ToString();
- if (!VName.Equals(name))
- {
- if (isRepeatName(name,saleOrg,dept))
- {
- //国贸公司业务片区"东部"已存在,请重新输入!
- MessageBox.Show(cmbSaleRegionName.Text + "-业务片区\"" + name + "\"已存在,请重新输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- }
- //确认修改吗?
- if (MessageBox.Show("是否确认修改选中的数据!", "提示", MessageBoxButtons.YesNo) == DialogResult.No)
- {
- return;
- }
- ArrayList parm = new ArrayList();
- string saleAreaCode = ultraGrid2.ActiveRow.Cells["SALE_AREA_NO"].Value.ToString();
- parm.Add(name);
- parm.Add(txtMemo.Text);
- parm.Add(this.UserInfo.GetUserName());
- parm.Add(ultraComboDepar.Value.ToString());
- parm.Add(saleAreaCode);
- CoreClientParam ccp = new CoreClientParam();
- ccp.ServerName = "com.steering.pss.sale.base.CoreSaleRegion";
- ccp.MethodName = "doUpdate";
- ccp.ServerParams = new object[] { parm };
- ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
- if (ccp.ReturnCode == -1) return;
- doQuery();
- //高亮显示新增的数据
- Infragistics.Win.UltraWinGrid.UltraGridRow row = null;
- for (int i = 0; i < ultraGrid2.Rows.Count; i++)
- {
- row = ultraGrid2.Rows[i];
- if (row.Cells["SALE_AREA_NO"].Value.ToString().Equals(saleAreaCode))
- {
- row.Activate();
- break;
- }
- }
- }
- }
- /// <summary>
- /// 用于验证修改时,描述是否已存在
- /// </summary>
- private static string VName = "";
- /// <summary>
- /// GRID ROW激活时信息带至编辑区
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void ultraGrid2_AfterRowActivate(object sender, EventArgs e)
- {
- Infragistics.Win.UltraWinGrid.UltraGridRow row = ultraGrid2.ActiveRow;
- if (row != null)
- {
- cmbSaleRegionName.Value = row.Cells["SALE_ORG"].Value.ToString();
- VName = row.Cells["SALE_AREA_DESC"].Value.ToString();
- txtAreaDesc.Text = VName;
- ultraComboDepar.Value = row.Cells["DEPARTID"].Value.ToString();
- txtMemo.Text = row.Cells["memo"].Value.ToString();
- }
- }
- /// <summary>
- /// 废除或恢复
- /// </summary>
- /// <param name="isDelete">true废除 false恢复</param>
- private void doDeleteOrRecovery(bool isDelete)
- {
- if (ultraGrid2.ActiveRow == null)
- {
- MessageBox.Show("请选择需要" + (isDelete ? "废除" : "恢复") + "的数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- Boolean validflagStr = Convert.ToBoolean(ultraGrid2.ActiveRow.Cells["VALIDFLAG"].Value);
- if (isDelete)
- {
- //无效数据不允许删除。
- if (!validflagStr)
- {
- MessageBox.Show("无效数据不支持废除操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- }
- else
- {
- //有效数据不允许恢复
- if (validflagStr)
- {
- MessageBox.Show("有效数据不支持恢复操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- }
- ArrayList param = new ArrayList();
- string saleAreaCode = ultraGrid2.ActiveRow.Cells["SALE_AREA_NO"].Value.ToString();
- param.Add(saleAreaCode);
- if (param.Count > 0 && MessageBox.Show("是否确认" + (isDelete ? "废除" : "恢复") + "选中的数据!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- try
- {
- int count = ServerHelper.SetData("com.steering.pss.sale.base.CoreSaleRegion.deleteLineInfo", new Object[] { param, UserInfo.GetUserName(), isDelete }, this.ob);
- if (count > 0)
- {
- doQuery();
- Infragistics.Win.UltraWinGrid.UltraGridRow rowD = null;
- for (int i = 0; i < ultraGrid2.Rows.Count; i++)
- {
- rowD = ultraGrid2.Rows[i];
- if (rowD.Cells["SALE_AREA_NO"].Value.ToString().Equals(saleAreaCode))
- {
- rowD.Activate();
- break;
- }
- }
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- }
- }
- private void cmbSaleRegionName_ValueChanged(object sender, EventArgs e)
- {
- if (cmbSaleRegionName.Value == null)
- {
- return;
- }
- bindDeparTRegion(cmbSaleRegionName.Value.ToString());
- }
-
- }
- }
|