| | |
| | | using System.Text.RegularExpressions; |
| | | using System.Threading.Tasks; |
| | | using System.Windows.Forms; |
| | | using DevExpress.RichEdit.Export; |
| | | using DevExpress.XtraEditors; |
| | | using DevExpress.XtraEditors.Controls; |
| | | using DevExpress.XtraGrid; |
| | |
| | | using Newtonsoft.Json; |
| | | using Newtonsoft.Json.Linq; |
| | | using static System.Windows.Forms.Control; |
| | | |
| | | |
| | | namespace Gs.DevApp.ToolBox |
| | | { |
| | |
| | | /// <param name="meth">方法名称</param> |
| | | /// <param name="param">参数</param> |
| | | /// <returns></returns> |
| | | public static async Task<string> HttpPostAsync(string url, string meth, string param) |
| | | { |
| | | if (string.IsNullOrEmpty(url)) |
| | | url = WebApiUrl; |
| | | url += meth; |
| | | var request = (HttpWebRequest)WebRequest.Create(url); |
| | | request.Method = "POST"; |
| | | request.ContentType = "application/json"; |
| | | request.Headers.Add("token", GetBasicAuthTicket()); |
| | | request.Accept = "*/*"; |
| | | request.Timeout = 15000; |
| | | request.AllowAutoRedirect = false; |
| | | request.ServicePoint.Expect100Continue = false; |
| | | HttpRequestCachePolicy noCachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore); |
| | | request.CachePolicy = noCachePolicy; |
| | | using (Stream requestStream = await request.GetRequestStreamAsync()) |
| | | { |
| | | byte[] dataBytes = Encoding.UTF8.GetBytes(param); |
| | | await requestStream.WriteAsync(dataBytes, 0, dataBytes.Length); |
| | | } |
| | | //public static async Task<string> HttpPostAsync(string url, string meth, string param) |
| | | //{ |
| | | // if (string.IsNullOrEmpty(url)) |
| | | // url = WebApiUrl; |
| | | // url += meth; |
| | | // var request = (HttpWebRequest)WebRequest.Create(url); |
| | | // request.Method = "POST"; |
| | | // request.ContentType = "application/json"; |
| | | // request.Headers.Add("token", GetBasicAuthTicket()); |
| | | // request.Accept = "*/*"; |
| | | // request.Timeout = 15000; |
| | | // request.AllowAutoRedirect = false; |
| | | // request.ServicePoint.Expect100Continue = false; |
| | | // HttpRequestCachePolicy noCachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore); |
| | | // request.CachePolicy = noCachePolicy; |
| | | // using (Stream requestStream = await request.GetRequestStreamAsync()) |
| | | // { |
| | | // byte[] dataBytes = Encoding.UTF8.GetBytes(param); |
| | | // await requestStream.WriteAsync(dataBytes, 0, dataBytes.Length); |
| | | // } |
| | | |
| | | using (WebResponse response = await request.GetResponseAsync()) |
| | | { |
| | | using (StreamReader reader = new StreamReader(response.GetResponseStream())) |
| | | { |
| | | return await reader.ReadToEndAsync(); |
| | | } |
| | | } |
| | | } |
| | | // using (WebResponse response = await request.GetResponseAsync()) |
| | | // { |
| | | // using (StreamReader reader = new StreamReader(response.GetResponseStream())) |
| | | // { |
| | | // return await reader.ReadToEndAsync(); |
| | | // } |
| | | // } |
| | | //} |
| | | |
| | | /// <summary> |
| | | /// httpPost访问服务 |
| | |
| | | /// <returns></returns> |
| | | public static string HttpPost(string url, string meth, string param) |
| | | { |
| | | if (string.IsNullOrEmpty(url)) |
| | | url = WebApiUrl; |
| | | url += meth; |
| | | var request = (HttpWebRequest)WebRequest.Create(url); |
| | | request.Method = "POST"; |
| | | request.ContentType = "application/json"; |
| | | request.Headers.Add("token", GetBasicAuthTicket()); |
| | | request.Accept = "*/*"; |
| | | request.Timeout = 15000; |
| | | request.AllowAutoRedirect = false; |
| | | request.ServicePoint.Expect100Continue = false; |
| | | HttpRequestCachePolicy noCachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore); |
| | | request.CachePolicy = noCachePolicy; |
| | | DevExpress.Utils.WaitDialogForm wdf = new DevExpress.Utils.WaitDialogForm("拼命加载中,请稍后..." + meth, "友情提示"); |
| | | HttpWebRequest request = null; |
| | | StreamWriter requestStream = null; |
| | | WebResponse response = null; |
| | | string responseStr = null; |
| | | try |
| | | { |
| | | if (string.IsNullOrEmpty(url)) |
| | | url = WebApiUrl; |
| | | url += meth; |
| | | request = (HttpWebRequest)WebRequest.Create(url); |
| | | request.Method = "POST"; |
| | | request.ContentType = "application/json"; |
| | | request.Headers.Add("token", GetBasicAuthTicket()); |
| | | request.Accept = "*/*"; |
| | | request.Timeout = 15000; |
| | | request.AllowAutoRedirect = false; |
| | | request.ServicePoint.Expect100Continue = false; |
| | | wdf.SetCaption("加载进度(10/100)"); |
| | | HttpRequestCachePolicy noCachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore); |
| | | request.CachePolicy = noCachePolicy; |
| | | wdf.SetCaption("加载进度(20/100)"); |
| | | requestStream = new StreamWriter(request.GetRequestStream()); |
| | | requestStream.Write(param); |
| | | requestStream.Close(); |
| | |
| | | //File.WriteAllText(Server.MapPath("~/") + @"\test.txt", responseStr); |
| | | reader.Close(); |
| | | } |
| | | wdf.SetCaption("加载进度(80/100)"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | wdf.Close(); |
| | | LogHelper.Debug(url, param + ":" + ex.Message); |
| | | throw ex; |
| | | } |
| | |
| | | requestStream = null; |
| | | response = null; |
| | | } |
| | | |
| | | wdf.SetCaption("加载进度(90/100)"); |
| | | wdf.Close(); |
| | | return responseStr; |
| | | } |
| | | |
| | |
| | | { |
| | | var dt = new DataTable(); |
| | | foreach (GridColumn col in gv.Columns) |
| | | dt.Columns.Add(col.FieldName, typeof(string)); |
| | | { |
| | | if (col.UnboundDataType == typeof(bool)) |
| | | dt.Columns.Add(col.FieldName, typeof(System.Boolean)); |
| | | else |
| | | { |
| | | dt.Columns.Add(col.FieldName, typeof(string)); |
| | | } |
| | | } |
| | | gc.BindingContext = new BindingContext(); |
| | | gc.DataSource = dt; |
| | | gc.ForceInitialize(); |
| | |
| | | { |
| | | foreach (GridColumn colmn in gv.Columns) |
| | | { |
| | | if (colmn.Name.ToString().Contains("gvMxDel")) |
| | | if (colmn.Name.ToString().Contains("gvMxDel") || colmn.Name.ToString().Contains("gvMxTui")) |
| | | { |
| | | colmn.Visible = !isEdt; |
| | | break; |
| | | // colmn.Visible = !isEdt; |
| | | // break; |
| | | colmn.OptionsColumn.AllowEdit = true; |
| | | } |
| | | else |
| | | colmn.OptionsColumn.AllowEdit = !isEdt; |
| | | } |
| | | gv.OptionsBehavior.Editable = !isEdt; |
| | | //gv.OptionsBehavior.Editable = !isEdt; |
| | | } |
| | | var _btnAry = controls.Find("btnSelect", false); |
| | | if (_btnAry.Length > 0) |
| | |
| | | txt.Enabled = false; |
| | | continue; |
| | | } |
| | | //自定组织 |
| | | if (colType is UcLookOrg) |
| | | { |
| | | var txt = colType as UcLookOrg; |
| | | txt.SetIdOrCode(strVal); |
| | | if (txt.IsReadly == false) |
| | | txt.Enabled = !isEdt; |
| | | else |
| | | txt.Enabled = false; |
| | | continue; |
| | | } |
| | | |
| | | if (colType is SimpleButton) |
| | | { |
| | |
| | | { |
| | | foreach (GridColumn colmn in gv.Columns) |
| | | { |
| | | if (colmn.Name.ToString().Contains("gvMxDel")) |
| | | if (colmn.Name.ToString().Contains("gvMxDel") || colmn.Name.ToString().Contains("gvMxTui")) |
| | | { |
| | | colmn.Visible = !isEdt; |
| | | break; |
| | | // colmn.Visible = !isEdt; |
| | | // break; |
| | | colmn.OptionsColumn.AllowEdit = true; |
| | | } |
| | | else |
| | | colmn.OptionsColumn.AllowEdit = !isEdt; |
| | | } |
| | | gv.OptionsBehavior.Editable = !isEdt; |
| | | //gv.OptionsBehavior.Editable = !isEdt; |
| | | } |
| | | foreach (Control ctrl in controls) |
| | | { |
| | |
| | | txt.Enabled = !isEdt; |
| | | continue; |
| | | } |
| | | //自定组织 |
| | | if (ctrl is UcLookOrg) |
| | | { |
| | | var txt = ctrl as UcLookOrg; |
| | | txt.SetIdOrCode("-1"); |
| | | txt.Enabled = !isEdt; |
| | | continue; |
| | | } |
| | | if (ctrl is SimpleButton) |
| | | { |
| | | var txt = ctrl as SimpleButton; |
| | |
| | | { |
| | | foreach (GridColumn colmn in gv.Columns) |
| | | { |
| | | if (colmn.Name.ToString().Contains("gvMxDel")) |
| | | if (colmn.Name.ToString().Contains("gvMxDel") || colmn.Name.ToString().Contains("gvMxTui")) |
| | | { |
| | | colmn.Visible = !isEdt; |
| | | break; |
| | | // colmn.Visible = !isEdt; |
| | | // break; |
| | | colmn.OptionsColumn.AllowEdit = true; |
| | | } |
| | | else |
| | | colmn.OptionsColumn.AllowEdit = !isEdt; |
| | | } |
| | | gv.OptionsBehavior.Editable = !isEdt; |
| | | //gv.OptionsBehavior.Editable = !isEdt; |
| | | } |
| | | foreach (Control ctrl in controls) |
| | | { |
| | |
| | | txt.Enabled = false; |
| | | continue; |
| | | } |
| | | //自定组织 |
| | | if (ctrl is UcLookOrg) |
| | | { |
| | | var txt = ctrl as UcLookOrg; |
| | | if (txt.IsReadly == false) |
| | | txt.Enabled = !isEdt; |
| | | else |
| | | txt.Enabled = false; |
| | | continue; |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | return 0; |
| | | } |
| | | } |
| | | |
| | | public static int ToBit(string str) |
| | | { |
| | | if (str.ToUpper() == "true".ToUpper()) |
| | | return 1; |
| | | return 0; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 读取grid的当前行 |
| | | /// </summary> |
| | |
| | | return _sbSqlWhere.ToString(); |
| | | } |
| | | /// <summary> |
| | | /// 初始化gridview |
| | | /// |
| | | /// </summary> |
| | | /// <param name="gridView1"></param> |
| | | public static void SetGridSear(GridView gridView1) |
| | | /// <param name="gridView1">gridview</param> |
| | | /// <param name="btnChkIco">图标按钮</param> |
| | | /// <param name="fm">当前窗体</param> |
| | | /// <param name="fileName">字段</param> |
| | | /// <param name="icoName">图标路径</param> |
| | | public static void SetGridSear(GridView gridView1, PictureBox btnChkIco = null, Form fm = null, string fileName = "checkStatus", string icoName = "") |
| | | { |
| | | foreach (GridColumn column in gridView1.Columns) |
| | | { |
| | | column.OptionsFilter.AutoFilterCondition = AutoFilterCondition.Contains; |
| | | column.OptionsFilter.ImmediateUpdateAutoFilter = false; |
| | | column.OptionsColumn.AllowEdit = false; |
| | | // column.OptionsColumn.AllowEdit = false; |
| | | if (column.Tag == null || column.Tag.ToString().Length <= 0) |
| | | column.OptionsFilter.AllowAutoFilter = false; |
| | | } |
| | |
| | | e.Bounds.Top + 45, e.Bounds.Right - 5, e.Bounds.Height - 5); |
| | | e.Graphics.DrawString(str, f, Brushes.Gray, r); |
| | | }; |
| | | |
| | | if (btnChkIco != null) |
| | | { |
| | | gridView1.FocusedRowChanged += (s, e) => |
| | | { |
| | | UtilityHelper.SetCheckIco(s, btnChkIco, fm, fileName, icoName); |
| | | }; |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | | |
| | | public static bool IsNumeric(string str) |
| | | { |
| | |
| | | return regex.IsMatch(str); |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// yz_quantity_0,yz_字段_类型 |
| | | /// </summary> |
| | | /// <param name="sender"></param> |
| | | /// <param name="e"></param> |
| | | public static void SetValidatingEditor(object sender, BaseContainerValidateEditorEventArgs e) |
| | | { |
| | | //yz_quantity_0 |