예제 #1
0
        private void btnDelete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (MessageBox.Show("ลบรหัสสินค้า '" + this.current_stmas.Stkcod + "' ทำต่อหรือไม่?", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {
                ApiAccessibilities acc = new ApiAccessibilities
                {
                    API_KEY = this.main_form.config.ApiKey,
                    stmas   = this.current_stmas
                };

                APIResult delete = APIClient.DELETE(this.main_form.config.ApiUrl + "Stmas/DeleteStmas", acc);
                if (delete.Success)
                {
                    StmasVM stmas = JsonConvert.DeserializeObject <StmasVM>(delete.ReturnValue);
                    this.current_stmas = stmas;
                    this.FillForm(this.current_stmas);
                }
                else
                {
                    if (MessageBox.Show(delete.ErrorMessage, "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry)
                    {
                        this.btnDelete.PerformClick();
                    }
                }
            }
        }
예제 #2
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (this.gridViewIstab.GetRow(this.gridViewIstab.FocusedRowHandle) == null)
            {
                return;
            }

            IstabVM istab = this.istab.Where(i => i.Id == (int)this.gridViewIstab.GetRowCellValue(this.gridViewIstab.FocusedRowHandle, this.colId)).FirstOrDefault();

            if (istab == null)
            {
                return;
            }

            if (MessageBox.Show("ลบรหัส \"" + istab.TypCod + "\" ทำต่อหรือไม่?", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {
                this.splashScreenManager1.ShowWaitForm();

                ApiAccessibilities acc = new ApiAccessibilities
                {
                    API_KEY = this.main_form.config.ApiKey,
                    istab   = istab
                };
                APIResult delete = APIClient.DELETE(this.main_form.config.ApiUrl + "Istab/DeleteIstab", acc);
                if (delete.Success)
                {
                    this.istab = this.LoadIstabFromServer();
                    this.bs.ResetBindings(true);
                    this.bs.DataSource = this.istab;
                    this.splashScreenManager1.CloseWaitForm();
                }
                else
                {
                    this.splashScreenManager1.CloseWaitForm();
                    if (MessageBox.Show(delete.ErrorMessage.RemoveBeginAndEndQuote(), "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry)
                    {
                        this.btnDelete.PerformClick();
                    }
                }
            }
        }
예제 #3
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            int    user_id   = (int)this.gridView1.GetRowCellValue(this.gridView1.FocusedRowHandle, colId);
            string user_name = (string)this.gridView1.GetRowCellValue(this.gridView1.FocusedRowHandle, colUserName);

            InternalUsers user = this.users.Where(u => u.Id == user_id).FirstOrDefault();

            if (user == null)
            {
                return;
            }

            if (MessageBox.Show("ลบรหัสผู้ใช้ \"" + user_name + "\"", "Delete", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1) == DialogResult.OK)
            {
                try
                {
                    ApiAccessibilities acc = new ApiAccessibilities
                    {
                        API_KEY       = this.main_form.config.ApiKey,
                        internalUsers = user
                    };

                    APIResult result = APIClient.DELETE(this.main_form.config.ApiUrl + "users/delete", acc);
                    if (result.Success)
                    {
                        this.RefreshGridUsers();
                    }
                    else
                    {
                        MessageBox.Show(result.ErrorMessage.RemoveBeginAndEndQuote());
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
예제 #4
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (this.gridViewDlvProfile.GetRow(this.gridViewDlvProfile.FocusedRowHandle) == null)
            {
                return;
            }

            DlvProfileVM dlvprofile = this.dlvprofile.Where(d => d.Id == (int)this.gridViewDlvProfile.GetRowCellValue(this.gridViewDlvProfile.FocusedRowHandle, this.colProfileId)).FirstOrDefault();

            if (dlvprofile == null)
            {
                return;
            }

            if (MessageBox.Show("ลบรหัสกลุ่ม \"" + dlvprofile.TypCod + "\" ทำต่อหรือไม่?", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {
                ApiAccessibilities acc = new ApiAccessibilities
                {
                    API_KEY    = this.main_form.config.ApiKey,
                    dlvprofile = dlvprofile
                };
                APIResult delete = APIClient.DELETE(this.main_form.config.ApiUrl + "DlvProfile/DeleteDlvProfile", acc);
                if (delete.Success)
                {
                    this.dlvprofile = this.LoadDlvProfileFromServer();
                    this.bs.ResetBindings(true);
                    this.bs.DataSource = this.dlvprofile;
                }
                else
                {
                    if (MessageBox.Show(delete.ErrorMessage.RemoveBeginAndEndQuote(), "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry)
                    {
                        this.btnDelete.PerformClick();
                    }
                }
            }
        }
예제 #5
0
        public void ProcessRequest(HttpContext context)
        {
            string result = string.Empty;
            Dictionary <string, string> my_headers = new Dictionary <string, string>();

            // Substitute the REST API's domain in the request URI so we can forward the request.
            string my_path = context.Request.ServerVariables["REQUEST_URI"].Replace(ConfigurationManager.AppSettings["path_to_client"], "");
            string my_url  = "https://" + ConfigurationManager.AppSettings["rest_api_server"] + my_path;

            // To-do:
            // Implement your own code here to check that the accountNr in the URL /dealers/accountNr/....
            // corresponds to the current user/session info.
            // This is to prevent some dishonest user from accessing someone else's project list.
            // ...
            // If the account nr in the REST URL does not correspond to the session user, respond with a 401 "are you trying to hack me" code.
            // ...

            // Instantiate APIClient library.
            APIClient API = new APIClient();

            //Get content as string
            var bodyStream = new StreamReader(context.Request.InputStream);

            bodyStream.BaseStream.Seek(0, SeekOrigin.Begin);
            var json_data = bodyStream.ReadToEnd();

            switch (context.Request.HttpMethod)
            {
            case "OPTIONS":
                result = API.OPTIONS(my_url);
                break;

            case "GET":
                my_headers.Add("Accept", "application/json,application/vnd.geo+json");
                result = API.GET(my_url, "", my_headers);
                break;

            case "POST":
                my_headers.Add("Content-Type", "application/json");
                my_headers.Add("Accept", "application/json,application/vnd.geo+json");
                result = API.POST(my_url, json_data, my_headers);
                break;

            case "PUT":
                my_headers.Add("Content-Type", "application/json");
                my_headers.Add("Accept", "application/json,application/vnd.geo+json");
                result = API.PUT(my_url, json_data, my_headers);
                break;

            case "DELETE":
                result = API.DELETE(my_url);
                break;
            }

            // Set HTTP response code.
            context.Response.StatusCode = API.response_code;

            // For POST requests, forward HTTP "Location" header if sent by REST API to the client.
            // HTTP "Location" header can be used by the client to download a newly created resource after a POST request (add to collection).
            if (context.Request.HttpMethod == "POST" && API.response_headers.ContainsKey("Location"))
            {
                context.Response.AddHeader("Location", API.response_headers["Location"]);
            }

            // Forward HTTP "Allow" header to the client.
            // HTTP "Allow" header is used by the client to render form controls (save, delete, etc) to a resource.
            if (API.response_headers.ContainsKey("Allow"))
            {
                context.Response.AddHeader("Allow", API.response_headers["Allow"]);
            }

            // Output to client.
            // Check server response Content-Type header.
            if (context.Response.StatusCode != 204)
            {
                if (API.response_headers["Content-Type"] == "application/json" || API.response_headers["Content-Type"] == "application/vnd.geo+json")
                {
                    context.Response.AddHeader("Content-Type", API.response_headers["Content-Type"]);
                    context.Response.Charset = "";
                    context.Response.Write(result);
                }
                else
                {
                    context.Response.StatusCode = 500;
                    context.Response.Write("<h3>Well this isn\'t supposed to happen now, is it?</h3>");
                }
            }
        }